npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nonstandard

v1.1.1

Published

Non standard JavaScript features

Downloads

66

Readme

Readme

NPM

Build Status Dependencies npm version Code Climate Test Coverage bitHound Overalll Score

Some non standard JavaScript features.

from Node.js > 0.12.0

Usage

require('nonstandard'); // Install all features

// install specified function
require('nonstandard/src/array/contains').Install();
[1, 2, 3].contains(2); // true

// Install some module
require('nonstandard/src/array').Install();
require('nonstandard/src/console').Install();
require('nonstandard/src/number').Install();
require('nonstandard/src/object').Install();
require('nonstandard/src/string').Install();

Contents

console.pipe

Log value to console and pass value First value was passed next.

console.pipe(returnValue: any, logValue1: any, logValue2: any, logValueN: any) : any;

Install:

require('nonstandard/src/console').Install();
// write `123` to console with `console.log`
var a = console.pipe(123);

// write:
// hello world
// hello
//
console.log(console.pipe('hello', 'world'));

console.[log, info, warn, error].pipe

console.log.pipe(value: any, ...values: any[]) : any;
console.info.pipe(value: any, ...values: any[]) : any;
console.warn.pipe(value: any, ...values: any[]) : any;
console.error.pipe(value: any, ...values: any[]) : any;

Install:

require('nonstandard/src/console').Install();
executeFunction(console.log.pipe({ some: 'data' }, "that string has been logged only")); // value was shown in console, and passed to function `executeFunction`

function actionLogin(user) {
  return login(user.credentials)
  .then(function(resp) {
    return console.info.pipe(resp.data);
  })
  .catch(function(error) {
    throw console.error.pipe(error); // in promise throwns was catched by next then/catch pair
  });
}

Array.empty

Check if array has not elements

Array.empty(target: array) : boolean;

Install:

require('nonstandard/src/array/empty').Install();
Array.empty([]) // true
Array.empty([1, 2, 3]) // false

Array.present

Check if array has some elements

Array.present(target: array) : boolean;

Install:

require('nonstandard/src/array/present').Install();
Array.present([]) // false
Array.present([1, 2, 3]) // true

Array.prototype.first

First element in array

[].first

Install:

require('nonstandard/src/array/properties').Install();
var arr = [5, 9, 14];

arr.first // 5

arr.first = 2;

arr // [2, 9, 14]

Array.prototype.second

Second element in array

[].second

Install:

require('nonstandard/src/array/properties').Install();
var arr = [1, 8, 10];

arr.second // 8

[].second // undefined

[].second = 2 // equals:  [][1] = 2

Array.prototype.last

Latest element in array

[].last

Install:

require('nonstandard/src/array/properties').Install();
var arr = [12, 34, 56, 78, 90];

arr.last // 90

arr.last == arr[arr.length - 1] // true

[].last = 1; // nothing changed

Array.prototype.clean

Clear array

[].clean()

Install:

require('nonstandard/src/array/clean').Install();
var arr = [1, 2, 3, 45, 67];

arr.clean();

arr // now `[]`

If as argument function passed, .clean call it on every value and clean if callback return not false, 0, null or undefined

var arr = [1, 2, 3, 4, 5, 6];
arr.clean(function(e){
  return e % 2;
});
arr; // [2, 4, 6]

Array.prototype.contains

Check elements exists in array

[].contains(any[]) : boolean

Install:

require('nonstandard/src/array/contains').Install();
var arr = ["a", "b", "c"];

arr.contains(['a', 'b']); // true

arr.contains('c'); // true

arr.contains('d'); // false

Array.prototype.clone

Full clone array.

[].clone() : any[]

Install:

require('nonstandard/src/array/clone').Install();
var arr = [1, 5].clone();

// its simple
arr // [1, 5]

Object.clone

Deep clone object

Object.clone(target: object) : object;

Install:

require('nonstandard/src/object/clone').Install();
var oob = { name: "Foo", test: "bar", cool: { yeah: true } };

var wob = Object.clone(oob);
// Object `wob` is full copy of `oob` without links in memory

Object.empty

Check if object has not keys

Object.empty(target: object) : boolean;

Install:

require('nonstandard/src/object/empty').Install();
Object.empty({}) // true
Object.empty({ a: 2 }) // false
Object.empty(window) // false

Object.present

Check if object has keys

Object.present(target: object) : boolean;

Install:

require('nonstandard/src/object/present').Install();
Object.present({}) // false
Object.present({ a: 2 }) // true
Object.present(window) // true

Number.range

Create array of numbers

Number.range(min: number, max: number, step: number = 1) : number[];

Install:

require('nonstandard/src/number/present').Install();
console.log(Number.range(1, 10))
/*
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
*/

console.log(Number.range(2, 8, 2))
/*
  [2, 4, 6, 8]
*/

Number.prototype.times

Run callback n times

(5).times(function(index: number) { return index + 1; }) : any[]

Install:

require('nonstandard/src/number/times').Install();
var result = (5).times(function(index) { return ++index * 2; });
result // [ 2, 4, 6, 8, 10 ]

String.random

Generate random string with custom length

String.random(length: string = 10) : string;

Install:

require('nonstandard/src/string/random').Install();
String.random() // "778fx0hmc0"
String.random(5) // "u5ojh"
String.random(64) // "ww5z8kar8m6l4ichouw221n307xiec1wt6584qf4bib2rbsa4b379hoblsd42h3e"