This is a versatile package for dynamically shaping objects. It seamlessly integrates default values and getters, providing a flexible way to tailor objects based on specific requirements.
Table of Contents
npm install dycraft --save
import { dycraft } from 'dycraft';
type Options = {
foo: string,
bar: string
};
type OptionsInput = Partial<Options>;
const data : OptionsInput = {
foo: 'bar'
};
const record = dycraft({
data,
defaults: {
foo: 'baz',
bar: 'boz'
}
});
console.log(record.foo);
// bar
console.log(record.bar);
// boz
delete record.foo;
console.log(record.foo);
//baz
import { dycraft } from 'dycraft';
type Options = {
foo: string,
bar: string
};
type OptionsInput = Partial<Options>;
const record = dycraft({
data: {
foo: 'bar',
} as OptionsInput,
getters: {
bar: defineGetter((context) : string => {
if (context.has('foo')) {
return context.get('foo');
}
return 'baz';
}),
},
});
console.log(record.foo);
// bar
console.log(record.bar);
// bar
delete record.foo;
console.log(record.foo);
// undefined
console.log(record.bar);
// baz
Before starting to work on a pull request, it is important to review the guidelines for contributing and the code of conduct. These guidelines will help to ensure that contributions are made effectively and are accepted.
Made with 💚
Published under MIT License.