New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

rich-js

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rich-js

A JavaScript library for rich prototypes


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created

RichJS Build Status

A JavaScript library for rich prototypes

This is a simple library designed to give a belt of good utility functions throughout your well known data types

How to use

var Rich = require('rich-js');
Rich.Core.applyAll(); // To apply all prototypes
Rich.Array.applyRichPrototype(); // Applies only the Array prototype

npm install --save rich-js

Safety

This library try not to clash with any possible standard when naming methods. And in case it clashes, it will not override the method and will output a warn in the console.

Prefix

In case you want to prefix the new methods, you can do by:

Rich.Util.prefix = 'r';
Rich.Number.applyRichPrototype();

(1).rseconds(); //1000

Adding your own custom prototypes

Rich.Util.applyToPrototype(Number, 'square', function() {
    return this.valueOf() * this.valueOf();
});

(3).square();
// 9

Documentation

  1. Number
  2. Object
  3. Array

Examples

A few examples of what this library offers

//Number prototype
(3).minutes();
// 180000

(3).times(function(i) {
    console.log(i);
});
// 0
// 1
// 2

(3).isEven();
// false
(3).isOdd();
// true

// Object prototype
({
    prop: {
        name: 'Test'
    }
}).getProperty('prop.name');
// 'Test'

// Array prototype
[{a: 1}, {a: 1}, {a: 2}].groupBy('a');
/*
{
  1: [{a: 1}, {a: 1}],
  2: [{a: 2}]
}
*/

FAQs

Package last updated on 28 Mar 2016

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