meows
Version:
A kittybin of tools.
33 lines (32 loc) • 1.53 kB
JavaScript
;
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Objects
Object.defineProperty(exports, "__esModule", { value: true });
exports.ONULL = Object.create(null);
exports.flipProp = (prop, obj) => (Object.assign({}, obj, { [prop]: !obj[prop] }));
exports.merge = (...objs) => Object.assign(Object.create(null), ...objs);
function path(obj, ...props) {
const val = obj[props[0]];
if (props.length === 1 || !val)
return val;
const rest = props.slice(1);
return path.apply(null, [val, ...rest]);
}
exports.path = path;
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Classes
class ObjectState {
constructor() {
this.state = Object.create(null);
}
_merge(...o) { return this.state = Object.assign(Object.create(null), ...o); }
_set(req) {
switch (typeof req) {
case 'function': return this.state = this._merge(req(this.state));
case 'object': return this.state = this._merge(this.state, req);
default: throw new Error('ObjectState instance :: _set() => internal error.');
}
}
get() { return this.state; }
}
exports.ObjectState = ObjectState;