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.

latest
Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Referencejs Build Status

Referencejs manages references to values in plain JS or Immutable objects (called stores). You can use this to:

  • Easily manage complex denormalized, without needing an explicited schema
  • referencing data that doesn't exist yet (e.g. async data)
  • normalize and denormalize immutable data
  • Lazily denormalize stored data

Getting Started

Update a Plain store

import { createReference, resolveReference, dereference } from 'referencejs';
const jon = {
  id: 'user_1',
  name: 'John Doe',
  email: 'jon@doe.com'
};
const jonRefrence = createReference('auth', 'users', jon.id);

let store = {};
store = resolveReference(store, jonReference, jon);

dereference(store, jonRefrence) === jon;

Or use Immutable if that's your jam

import { Map, is } from 'immutable';
import { createReference, resolveReference, dereference } from 'referencejs/immutable';
const jon = Map({
  id: 'user_1',
  name: 'John Doe',
  email: 'jon@doe.com'
});
const jonRefrence = createReference('auth', 'users', jon.id);

let store = Map();
store = resolveReference(store, jonReference, jon);

is(dereference(store, jonRefrence), jon);

More Advanced: smartDereference

Dereferencing one reference at a time can be painful. smartDereference scans an object or array and dereferences every reference it finds

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);

Like what you see?

Keywords

reference

FAQs

Package last updated on 13 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