1.1.0 • Published 2 years ago
dycraft v1.1.0
dycraft 🌈
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
Installation
npm install dycraft --saveUsage
Defaults
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);
//bazGetters
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);
// bazContributing
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.
License
Made with 💚
Published under MIT License.