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

referencejs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

referencejs

Easily create, update, and manipulate references to values in a JSON document.

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Referencejs Build Status

Reference JS lets you create references to any location in a JSON tree. This is useful for

  • For normalizing and denormalizing data without needing an explicit schema
  • For referencing data that doesn't yet exist in the store (e.g. async data)
  • For normalizing and denormalizing immutable data

A Basic Example

import {
  createReference,
  resolveReference,
  dereference,
} from 'referencejs';

const user = {
  id: 'abc',
  name: 'John Doe'
};
const reference = createReference(['users', user.id]);

let store = {};
store = resolveReference(store, reference, user);

dereference(store, reference) === user;

dereferencing using smartDereference

Dereferencing one reference at a time isn't that useful. smartDereference dereferences every reference in an object. This is useful if you have data structures that differ significantly from your store

import {
  createReference,
  smartDereference,
} from 'referencejs';

const store = {
  users: {
    user1: {
      name: 'John Doe'
    },
    user2: {
      name: 'Jane Doe'
    },
    user3: {
      name: 'Billy Doe'
    },

    user4: {
      name: 'Lucy Doe'
    }
  }
};

const john = createReference(['users', 'user1']);
const jane = createReference(['users', 'user2']);
const billy = createReference(['users', 'user3']);
const lucy = createReference(['users', 'user4']);

const familyTreeReferences = {
  father: john,
  mother: jane,
  children: [billy, lucy]
};

// familyTree will contain the user objects instead of the references  
const familyTree = smartDereference(store, familyTree);

What's a Reference?

A reference is an object that contains everything needed to find a value in a JSON object (called the store). The signature looks like:

{
  path : Array<number|string>
}

Keywords

reference

FAQs

Package last updated on 09 Apr 2017

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