0.6.6 • Published 2 years ago

object-crumble v0.6.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Object-crumble

npm Build
status npm bundle size Codacy
Badge

npm type definitions node-current NPM

Creative ways to cook your objects

The main motivation is to boost the writing of unit tests by simplifying the process of creating new data content. This is achieved by mutating programmatically existing data:

  • Written in Typescript.

  • Uses JSON-like object as an input.

  • Can be used with any testing framework (Jest, ...)

  • A simpler and experimental alternative to property testing. No need for a schema. You should still consider, property based testing framework likefast-check that can help find bugs in unexplored code paths.

Usage

Convert any object to an abstract representation of the object structure

abstractObject({name: "Jane", homepage: "http://mywebsite.com" })

will return:

[
  {
    path: "name",
    kind: "string",
  },
  {
    path: "homepage",
    kind: "url",
  },
];

Mutates an object applying a mutation.

const mutation = {
  path: "name",
  kind: "string",
  mutationName: "string => empty",
};

mutateObject(mutatorRules)(mutation)({
  name: "Picasso",
  firstName: "Pablo",
});

will return empty field for name:

{
name: '',
firstName: 'Pablo'
}

A more exhaustive documentation of the api is available

Documentation and links

Installation

This package is ESM only.

yarn add object-crumble