New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@jf/object

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jf/object

Class providing dot path syntax for properties, JSON serialization, singletons and more.

latest
Source
npmnpm
Version
4.0.0
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

@jf/object stable

Class providing dot path syntax for properties, JSON serialization, singletons and more.

Usage

npm install @jf/object

Objects as parameters

You can pass several objects and will be merged recursively.

const obj = new jfObject(
    {
        a : {
            b : 0
            c : 2
        }
    },
    {
        a : {
            b : 1,
        }
    },
    {
        a : {
            c : 3
        }
    }
);
console.log(obj.toJSON()); // { a : { b : 1, c : 3 } }

Dot notation

You can use dot notation in order to assign/retrieve/test nested objects.

const obj = new jfObject();
obj.set('d.e.f', 5);
console.log(obj.toJSON()); // { d : { e : { f : 5 } } }
console.log(obj.get('d.e')); // { f : 5 }
console.log(obj.has('d.e.f')); // true

Merging objects

Objects can be merged in 2 ways:

  • Recursively: Use obj.merge(...).
  • Overwrite existing keys: Use Object.assign(obj, ...)
const obj = new jfObject(
    {
        a : {
            b : 0
        }
    }
);
// Recursive merge
obj.merge(
    {
        a : {
            c : 1
        }
    }
);
console.log(obj.toJSON()); // { a : { b : 0, c : 1 } }
// Overwrite merge
Object.assign(
    obj,
    {
        a : {
            c : 2
        }
    }
);
console.log(obj.toJSON()); // { a : { c : 2 } }

Iterating over properties

You can use new ES6 loop for..of:

const obj = new jfObject(
    {
        a : 1,
        c : 2,
        f : 3,
        h : 4
    }
);
for (const prop of obj)
{
    console.log('%s = %s', prop, obj[prop]);    
}
// a = 1
// c = 2
// f = 3
// h = 4

Keys & values

If you need to split object into keys and values, you can use split or toArray methods.

const obj = new jfObject(
    {
        a : 1,
        c : 2,
        f : 3,
        h : 4
    }
);
console.log(obj.split()); // { keys: [ 'a', 'c', 'f', 'h' ], values: [ 1, 2, 3, 4 ] }
console.log(obj.toArray());  // [ [ 'a', 1 ], [ 'c', 2 ], [ 'f', 3 ], [ 'h', 4 ] ]

Singleton

If you need to share the same instance between differents external modules, you can use static method i() in order to retrieve the same instance anywhere in the app.

class User extends jfObject
{
    // User class methods and properties
}
// Initialize the User instance on ajax response using external library:
function onAjaxResponse(data)
{
    //...
    User.i().setProperties(data);
    //...
}
// In UI, using external framework
<user-info data="{{User.i()}}" />

Keywords

class

FAQs

Package last updated on 24 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts