npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-object-helper

v0.0.6

Published

Readme

js-object-helper

A sample Object class that contains some useful methods.

npm

https://www.npmjs.com/package/js-object-helper

Test Cases Report

Image description Image description

Installation

$ npm install --save js-object-helper
OR
$ yarn add js-object-helper

Getting started

import helper from 'js-object-helper'
OR 
const helper = require('js-object-helper')

Get property value inside a object.

getProp(object: object | Array<any>, path: Array<string> | string, defaultValue: any): any

| param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | obj |object/Array | Required | To extract the property value inside it
| path | Array/string | Required | Value can be array like ['user', 'info', 'email'] or string (user.info.email) | defaultValue | any | undefined | if property does not exists then return the default value

Examples
const arr = [{ id: 1, name: 'Test' }, { id: 2, name: 'Test 2' }];
helper.getProp(arr, '[id=1].name') // output -> Test
helper.getProp(arr, '[id>1].name') // output -> Test 2
helper.getProp(arr, '[id>=1].name') // output -> Test
helper.getProp(arr, '[id<2].name') // output -> Test
helper.getProp(arr, '[id<=2].name') // output -> Test
helper.getProp(_arr, '[id<>2].name') // output -> Test
const arr = {
  name: 'User Name'
  info: [
          { id: 1, name: 'Test' }, 
          { id: 2, name: 'Test 2' }
        ]
 };
 helper.getProp(arr, 'info.0.id.name') // output -> Test
 helper.getProp(arr, 'info.0.id.email') // output -> undefined
 helper.getProp(arr, 'info.0.id.email', '[email protected]') // output -> [email protected]
 helper.getProp(arr, 'info.[id==2].name') // output -> Test 2

Set property values inside object.

setProp(object: object | Array<any>, path: Array<string> | string, defaultValue: any, value: any, replace?: boolean):void

| param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | obj |object/Array | Required | To set property value in given object
| path | Array/string | Required | Value can be array like ['user', 'info', 'email'] or string (user.info.email) | value | any | Required | Value, what do you want to set at given path | replace | boolean | false | If path existing value is object, so the replace = true will replace from new value otherwise value will merge in existing value.

Examples
const obj = { 
  id: 1, 
  name: 'V1', 
  children: [
              { id: 2, name: 'V11' }, 
              { id: 3, name: 'V12' }
            ]
  }
helper.setProp(obj, 'name', 'Hello')
//output ->
// {
//   id: 1,
//   name: 'Hello', // change is here
//   children: [
//         { id: 2, name: 'V11'
//         },
//         { id: 3, name: 'V12'
//         },
//     ],
// }

helper.setProp(obj, 'test', 'Hello Testing')
//output ->
// {
//   id: 1,
//   name: 'Hello',
//   test: 'Hello Testing', // change is here
//   children: [
//         { id: 2, name: 'V11'
//         },
//         { id: 3, name: 'V12'
//         },
//     ],
// }

helper.setProp(obj, '_test.0', 'Test to create array')
//output ->
// {
//   id: 1,
//   name: 'Hello',
//   _test: ['Test to create array'], // Change is here
//   test: 'Hello Testing',
//   children: [
//         { id: 2, name: 'V11'
//         },
//         { id: 3, name: 'V12'
//         },
//     ],
// }


helper.setProp(obj, 'children.0.name', 'Test Data')
//output ->
// {
//   id: 1,
//   name: 'Hello',
//   _test: ['Test to create array'],
//   test: 'Hello Testing',
//   children: [
//         { id: 2, name: 'Test Data' // Change is here
//         },
//         { id: 3, name: 'V12'
//         },
//     ],
// }

helper.setProp(obj, 'children.0', {id: 5}, true)
//output ->
// {
//   id: 1,
//   name: 'Hello',
//   _test: ['Test to create array'],
//   test: 'Hello Testing',
//   children: [
//         { id: 5}, // change is here
//         { id: 3, name: 'V12'},
//     ],
// }

helper.setProp(obj, 'children.1', {id: 6}, false)
//output ->
// {
//   id: 1,
//   name: 'Hello',
//   _test: ['Test to create array'],
//   test: 'Hello Testing',
//   children: [
//         { id: 5},
//         { id: 6, name: 'V12'}, // change is here
//     ],
// }

Delete property from a object.

deleteProp(object: object | Array<any>, path: Array<string> | string):void

| param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | obj |object/Array | Required | To delete property from given object
| path | Array/string | Required | Value can be array like ['user', 'info', 'email'] or string (user.info.email)

Examples
  
const obj = { 
 id: 1, 
 name: 'V1', 
 children: [
             { id: 2, name: 'V11' }, 
             { id: 3, name: 'V12' }
           ]
 }
helper.deleteProp(obj, 'children.*.name');
//output ->
// {
//   id: 1,
//   name: 'Hello',
//   children: [
//         { id: 2}, // change is here
//         { id: 3} // change is here
//     ],
// }
helper.deleteProp(obj, 'name');
//output ->
// {
//   id: 1,
//   children: [
//         { id: 2},
//         { id: 3} 
//     ],
// }

helper.deleteProp(obj, 'children');
//output ->
// {
//   id: 1
// }


helper.deleteProp(obj, 'test_not_object');
//output ->
// {
//   id: 1
// }

push value inside a array.

pushProp(object: object | Array<any>, path: Array<string> | string, value: any, primaryKey?: string, updateIfExists?: boolean, looseComparison?: boolean):void

| param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | obj | object/Array | Required | To delete property from given object
| path | Array/string | Required | Value can be array like ['user', 'info', 'email'] or string (user.info.email) | value | Array/object/any| Required | value to push on given path in given object | primaryKey | string | null | List Unique key name | updateIfExists | boolean. | false | If property already has any match data with given primary key, then true to update and false = skip the particular record |looseComparison | boolean | true | To compare the primaryKey value in strict mode or not. if true then operator will be == otherwise ===

Prepend value inside a array.

unshiftProp((object: object | Array<any>, path: Array<string> | string, value: any, primaryKey?: string, updateIfExists?: boolean, looseComparison?: boolean):void

| param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | obj | object/Array | Required | To delete property from given object
| path | Array/string | Required | Value can be array like ['user', 'info', 'email'] or string (user.info.email) | value | Array/object/any| Required | value to push on given path in given object | primaryKey | string | null | List Unique key name | updateIfExists | boolean. | false | If property already has any match data with given primary key, then true to update and false = skip the particular record |looseComparison | boolean | true | To compare the primaryKey value in strict mode or not. if true then operator will be == otherwise ===

Is given value array?

isArray(value: any): boolean | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | any | Required | To check this variable is array or not, It does not metter what value is given in param

Is given value object?

isObject(value: any): boolean | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | any | Required | To check this variable is object or not, It does not metter what value is given in param

Is given value empty Object?

isEmptyObject(value: any): boolean | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | any | Required | To check this variable is a empty object or not, It does not metter what value is given in param

Is given string integer?

isInteger(value: string): boolean | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | string | Required | To check this variable is integer or not

Is given string isFloat?

isFloat(value: string): boolean | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | string | Required | To check this variable is float or not

To convert the url's query string data into object.

queryStringToObject(url: string): object; | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | string | Required | Full url

To convert the object into queryString.

objectToQueryString(value: object): string; | param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | object | Required | any object

To convert the object into FormData.

objectToFormData(value: object, formData?: FormData | null, namespace?: string): FormData;

| param | type |default | description
|----------------|-------------------------|---------------|------------------------------------------------ | value | object | Required | object to conver into form data | formData | FormData | - | If want to merge your formdata veriable then pass it here, otherwise leave it. | namespace | string | - | To and the prefix before every key.