National Puppy Menace

    densen

    2.0.0 • Public • Published

    densen

    Reduce the size of your serialized data with densen by turning objects literal into arrays of values.

    Examples

    With Object

    const densen = require('densen');
    
    const unflattened = {
    	qualities: ['perseverant', 'open-minded', 'funny'],
    	name: 'Alexander',
    	hobbies: [
    		{
    			activity_name: 'soccer',
    			hours_per_week: 4,
    		},
    		{
    			activity_name: 'piano',
    			hours_per_week: 3,
    		},
    		{
    			activity_name: 'painting',
    			hours_per_week: 2,
    		},
    	],
    	age: 32,
    	profession: {
    		title: 'engineer',
    		salary: 70000,
    	},
    };
    
    const flattened = [
    	'Alexander',
    	32,
    	['engineer', 70000],
    	[
    		['soccer', 4],
    		['piano', 3],
    		['painting', 2],
    	],
    	['perseverant', 'open-minded', 'funny'],
    ];
    
    const shape = {
    	name: '',
    	age: 0,
    	profession: {
    		title: '',
    		salary: 0,
    	},
    	hobbies: [
    		{
    			activity_name: '',
    			hours_per_week: 0,
    		},
    	],
    	qualities: [''],
    };
    
    const compressor = densen(shape);
    
    compressor.unflatten(flattened); // returns unflattened
    compressor.flatten(unflattened); // returns flattened

    With Array

    const densen = require('densen');
    
    const unflattened = [
    	{
    		age: 44,
    		name: 'Alice',
    	},
    	{
    		name: 'Bob',
    		age: 32,
    	},
    ];
    
    const flattened = [
    	['Alice', 44],
    	['Bob', 32],
    ];
    
    const shape = [
    	{
    		name: '',
    		age: 0,
    	},
    ];
    
    const compressor = densen(shape);
    
    compressor.unflatten(flattened); // returns unflattened
    compressor.flatten(unflattened); // returns flattened

    Functions

    unflatten = values => keys / values

    flatten = keys / values => values

    Details

    0 dependencies ECMAScript 2015

    License

    MIT License

    Copyright (c) 2021 CreatifCreateur

    Install

    npm i densen

    DownloadsWeekly Downloads

    1

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    10 kB

    Total Files

    7

    Last publish

    Collaborators

    • creatif-createur