Giter Club home page Giter Club logo

jsshorts's Introduction

jsshorts

About

This is a Node.js module available through the npm registry.

This module provides a couple of shortcuts for commonly used javascript constructs

Installation

$ npm install jsshorts

Features

Run the examples below with runkit: https://npm.runkit.com/jsshorts

forEach

Iterates over properties of an object.

const forEach = require('jsshorts').forEach;

const obj = { a: '23', b: 'bla' };
forEach(obj, (k,v) => {
   console.log(`${k} : ${v}`);
}); 

containsProperty

Checks if an object contains a property

const containsProperty = require('jsshorts').containsProperty;

const obj = { a: '23', b: 'bla' };
console.log(`${containsProperty(obj, 'a')}`);
console.log(`${containsProperty(obj, 'c')}`);

deepCopy

Deeps copy an object. It uses JSON serialization under the hood: JSON.parse(JSON.stringify(a));

usage 1: to = deepCopy(from) creates new deep copied object

const deepCopy = require('jsshorts').deepCopy;
const from = { a: 'v1', b: 'v2', c: { x: '123', y: '345' } };

const to = deepCopy(from);
from.a = 'x'; // modify object, that does not influence 'to' 
console.log(`${JSON.stringify(from)}`);
console.log(`${JSON.stringify(to)}`);

usage 2: deepCopy(from, to) deeply copies properties of 'from' object into 'to' object

const deepCopy = require('jsshorts').deepCopy;

const from = { a: 'aaa' };
const to = { b: 'bbb' };
deepCopy(from, to);
console.log(`${JSON.stringify(to)}`); // to contains a and b

removePropertiesNotInFilter

Removes properties from 'from' object when property not in 'filter' object

const obj = {
  a: 'v1', b: 'v2', c: 'v3', d: 'v4',
};
const filter = { b: 'cc', c: 'dd' };
removePropertiesNotInFilter(obj, filter);
console.log(`${JSON.stringify(obj)}`); // a and d are removed

jsshorts's People

Contributors

wieshubbers avatar wwizz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.