Socket
Book a DemoInstallSign in
Socket

@lbennett/grape-jelly

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lbennett/grape-jelly

JavaScript serializer library inspired by ruby-grape/grape-entity

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

GrapeJelly

I was jelly of ruby-grape's grape-entity gem so here we have a JavaScript serializer framework inspired by grape-entity. It is not intended to be a complete implementation of grape-entity.

Install

npm install @lbennett/grape-jelly
# OR
yarn add @lbennett/grape-jelly

Usage

Define entities by extending the Entity class. You must implement a define method that defines the entity using Entity.prototype.expose.

import { Entity } from '@lbennett/grape-jelly';

class UserEntity extends Entity {
  define() {
    this.expose('username', { as: 'not_username' });
    this.expose('password', user => user.notPassword);
  }
}

You can use Entity.prototype.represent to serialize your object.

import UserEntity from './UserEntity';

const data = {
    username: 'foo',
    password: 'bar',
    notPassword: 'raboof',
    otherValue: 'not included',
};

const entity = new UserEntity();
const serializedData = entity.represent(data);

console.log(serializedData);

// { not_username: 'foo', password: 'raboof' }

FAQs

Package last updated on 22 Apr 2019

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