• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reshape JavaScript objects to match a schema

Reshaper

Build Status Coverage Status

Reshaper is a JavaScript library which can automatically restructure JavaScript objects to match a provided schema. It also provides users with some manual control, by way of a 'hint' system.

To see some interactive examples, check out this Kajero notebook.

Installation

npm install reshaper

Usage

reshaper(data, schema, [hint])

  • data: The JavaScript data structure to be reshaped.
  • schema: The structure we want our reshaped data to match.
  • hint: (Optional) The name of an object key, given as a 'hint'. Keys matching this hint will be preferred. An array of keys can also be provided if desired.

Examples

var reshaper = require('reshaper');

var peopleData = [
    {
        name: 'Joel',
        info: {
            age: 22,
            height: 1.9,
            middleName: 'Robert',
            lastName: 'Auterson'
        }
    },
    {
        name: 'Jake',
        info: {
            age: 24,
            height: 1.85,
            middleName: 'Wild',
            lastName: 'Hall'
        }
    }
];

var schema = ['String'];

reshaper(peopleData, schema);
// => ['Joel', 'Jake']

// We can give a 'hint', to say lastName is what we want.
reshaper(peopleData, schema, 'lastName');
// => ['Auterson', 'Hall']

// Object keys get used as hints
var schema = {
    age: ['Number'],
    height: ['Number']
};

reshaper(peopleData, schema);
/* =>
{
    age: [22, 24],
    height: [1.9, 1.85]
}
*/

More Repositories

1

kajero

Interactive JavaScript notebooks with clever graphing
JavaScript
1,865
star
2

termloop

Terminal-based game engine for Go, built on top of Termbox
Go
1,424
star
3

jutsu

One-line graphs, with support for Smolder built-in
JavaScript
54
star
4

smolder

A library wrapper that attempts to reshape data going into your functions.
JavaScript
27
star
5

khaled-tinder

DJ Khaled Tinder bot
Python
12
star
6

dayligo

Golang library for working with Daylio backups
Go
9
star
7

khaled-bot

A very, very silly Reddit bot.
Python
8
star
8

go-garbled

Evaluator for Yao's Garbled Circuits, with example circuits
Go
6
star
9

risky

Chrome extension for helping out with those 'risky clicks'.
JavaScript
5
star
10

python-gameboy

A simple Game Boy emulator in Python.
Python
5
star
11

LTMSCPL

The repository for the Link To My SoundCloud Public License.
4
star
12

git-branch-i

The missing git branch --interactive
Go
4
star
13

resume

My CV, TeX and PDF versions.
TeX
3
star
14

k8s-context-i

Interactive terminal-based k8s context switcher
Go
2
star
15

golecture1

Code samples and slides for first Go lecture
1
star
16

BearwavesWebsite

The website for Bearwaves game studio.
CSS
1
star
17

golecture2

Slides and code samples for Go lecture 2, on 25/2/15 at Imperial.
Go
1
star
18

pai-sho

An effort to implement the Pai Sho game from "Avatar: The Last Airbender" using LibGDX.
Java
1
star
19

terraform-workspace-i

Interactive Terraform workspace switcher
Go
1
star
20

arm-project

ARM project, containing an emulator, assembler and Raspberry Pi extensions.
C
1
star
21

Uplift

Bearwaves' first game, a multi-platform, sci-fi action RPG.
Java
1
star
22

ggapp

CLI tool and Go library for GGapp.io
Go
1
star