const path = {
styles : {
src: './path-to-styles-src',
dist: './path-to-styles-dist',
toString() { return this.src },
},
}
console.log('' + path.styles)
const pathHandler = {
get(target, prop) {
const val = target[prop];
if (typeof val === 'object' && val.hasOwnProperty('src')) {
val.toString = function() {
return this.src;
};
return new Proxy(val, pathHandler);
} else {
return target[prop];
}
}
}
const path = new Proxy({
styles: {
src: './path-to-styles-src',
dist: './path-to-styles-dist',
scss: {
src: './scss-src',
dist: './scss-dist',
}
},
images: {
src: './path-to-images-src',
dist: './path-to-images-dist'
},
}, pathHandler);
console.log('' + path.styles); // './path-to-styles-src'
console.log('' + path.styles.dist); // './path-to-styles-dist'
console.log('' + path.styles.scss); // './scss-src'
console.log('' + path.styles.scss.dist); // './scss-dist'