pick-exist-fields

1.0.1 • Public • Published

pick-exist-fields

Pick exist fields from an object

npm npm

Utility function to select specified field's value is not null and undefined from an plain object

If the object is not plain object, then return the object directly.

Usage

npm install pick-exist-fields --save
import pickExistFields from "pick-exist-fields";

const originalObj = { 
  name: "npm", 
  age: 18, 
  career: "engineer", 
  address: null
};

// { age: 18 }
pickExistFields(originalObj, "age"); 

// { age: 18, career: 'engineer' }
pickExistFields(originalObj, ["age", "career"]); 

// { name: 'npm', age: 18, career: 'engineer' } 
pickExistFields(originalObj); 

API

pickExistFields(obj: object, fields: string | string[]) : object

return a shallow copy which is composed of the picked fields, if the field value is not null and undefined.

if fields is not specified, then pick all non-null/non-undefined fields.

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i pick-exist-fields

Weekly Downloads

9

Version

1.0.1

License

MIT

Unpacked Size

4.12 kB

Total Files

4

Last publish

Collaborators

  • peter_bj