1.0.0 • Published 10 months ago

@haensl/object v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@haensl/object

Help for JavaScript objects.

NPM

npm version CircleCI

Install

NPM

npm i -S @haensl/object

Yarn

yarn add @haensl/object

Use

const { hasDefinedKeys } = require('@haensl/object');

const someProcessingFunction = async (input) =>
  const processed = await input.pipe(here)
    .map(there)
    .reduce(theData);

  if (hasDefinedKeys(processed)) {
    return processed;
  }

  // return null instead of empty objects
  return null;
}

Synopsis

removeUndefinedKeys: (obj) => obj

Returns a new object without undefined keys.

Example:

const { removeUndefinedKeys } = require('@haensl/object');

const input = {
  foo: undefined,
  bar: 'foo',
  foobar: undefined
};

const out = removeUndefinedKeys(input);

// out == { bar: 'foo' }

hasDefinedKeys: (obj) => boolean

Checks whether an object has defined keys.

Example:

const { hasDefinedKeys } = require('@haensl/object');

const empty = {
  foo: undefined
};

Object.keys(empty).length; // 1

hasDefinedKeys(empty); // false

hasDefinedKeys({ foo: 'bar' }); // true

Changelog

License