dycraft
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

dycraft 🌈

npm version npm version Master Workflow Known Vulnerabilities Conventional Commits

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.

Readme

Keywords

none

Package Sidebar

Install

npm i dycraft

Weekly Downloads

57

Version

1.1.0

License

MIT

Unpacked Size

37.9 kB

Total Files

14

Last publish

Collaborators

  • tada5hi