dycraft
v1.1.0
Published
[![npm version][npm-version-src]][npm-version-href] [![npm version][codecov-src]][codecov-href] [![Master Workflow][workflow-src]][workflow-href] [![Known Vulnerabilities][snyk-src]][snyk-href] [![Conventional Commits][conventional-src]][conventional-href
Downloads
579
Readme
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 --save
Usage
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);
//baz
Getters
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
Contributing
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.