0.1.2 • Published 7 years ago
dontstop v0.1.2
Don't Stop
A funny tool to call on an object via a semantic chain of unlimited depth.
Example
const dontStop = require("dontStop").default;
const I = dontStop("I");
I.am.student = true;
I.am.developer = true;
I.want.to.be.a.scientist = () => { //
// plan to be a scientist
};
I.want.money = () => {
// how to get money
};
I.want.health = () => {
// how to get health
};
I.have.hair = true;
I.have.job = true;
I.have.lunch = () => {
// how do I have lunch
};
I.have.lunch.at.where = "company dining room";
I.have.lunch.at.when = "12:00";
I.have.assets = {
computer: 1,
laptop: 1,
cup: 4,
bag: 1,
// ...
}
// check the 'name' property
console.log(I.have.name); // => 'I.have' (because it's auto-generated object)
console.log(I.have.hair.name); // => undefined (because it's a user-defined value)
console.log(I.have.lunch.name) // => 'I.have.lunch' (bacause it's assigned function)
console.log(I.have.assets.name) // => undefined (because it's a user-defined value)API
dontStop(name: string): DontStopProxydontStop<T extends Function>(target: T, name?: string): T & DontStopProxydontStop<T = object>(target: T, name: string): T & DontStopProxyThis function returns an object (or a function whentargetis a function) that implements the interfaceDontStopProxy, which allows you, for semantic purpose, chaining properties with unlimited depth, even they hasn't been defined.nameSets the top level name of the chain, used for prefixing property names. When passingtargeta named function or an object withnameproperty, this argument is not necessary.
DontStopProxy.nameThis read-only property returns the name of the current reference property (only if the property is set function, or is auto-generated).DontStopProxy.valueOf()This method returns the primitive value of the current reference property (since you will always get a new proxy if the property has never assigned a value).DontStopProxy.someProp = someFunctionIf you assign a function to a property, which is not original set intarget, the function will be automatically wrapped bydontStopasDontStopProxy, so that it both can be invoked and be chained.