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

@devesharp/helpers-js

v0.2.0

Published

<p align="center"> <img src="https://user-images.githubusercontent.com/14295479/72281868-2e2d6d00-361a-11ea-913c-0ea04740a545.png"/> </p> <p align="center"> <a href="https://www.npmjs.com/package/@devesharp/helpers-js" target="_blank"><img src="https://

Downloads

10

Readme

Description

HelpersJS is a javascript library based on Laravel helpers. It is just based, contains too many functions and also the lack of some.

Installation

$ npm i @devesharp/helpers-js
$ yarn add @devesharp/helpers-js

Usage

import { Str, Arr } from '@devesharp/helpers-js';

Str.contains('This is my name', 'my name');

// true

Arr.warp(1);

// [1]

Arr

Arr.chunk()

The Arr.chunk() method creates an array chunk:

import { Arr } from '@devesharp/helpers-js';

Arr.chunk([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2);

// [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]

Arr.range()

The Arr.range() method creates an array containing a range of elements.:

import { Arr } from '@devesharp/helpers-js';

Arr.range(1, 5);

// [1,2,3,4,5]

Arr.range(1, 1);

// [1]

Arr.compareArray()

The Arr.compareArray() method compare two arrays:

import { Arr } from '@devesharp/helpers-js';

Arr.range([0, 1], [0, 1]);

// true

Arr.range([], [1]);

// false

Arr.wrap()

The Arr.wrap() method wraps the given value in an array. If the given value is already an array it will not be changed:

import { Arr } from '@devesharp/helpers-js';

Arr.wrap('any');

// ['any']

Arr.wrap(0);

// [0]

Arr.wrap([true]);

// [true]

Arr.collapse()

The Arr.collapse() method collapses an array of arrays into a single array:

import { Arr } from '@devesharp/helpers-js';

Arr.wrap([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
]);

// [1, 2, 3, 4, 5, 6, 7, 8, 9]

Obj

Obj.add()

The Obj.add() method adds a given key / value pair to an array if the given key doesn't already exist in the array or is set to null:

import { Obj } from '@devesharp/helpers-js';

Obj.add({ name: 'Desk' }, 'price', 100);

// {name: 'Desk', price: 100}

Obj.except()

The Obj.except() method removes the given key / value pairs from an array:

import { Obj } from '@devesharp/helpers-js';

Obj.except({name: 'Desk', price: 200}, ['price']);

// {name: 'Desk'}

Obj.except({'value': [1,2,3,4]}, ['value.2', 'value.0']);

// {'value': [2,4]}

Obj.except({'products':[{'desk': {'price': 100}},{'desk': {'price': 100}'desk2': {'price': 200}}]},
    'products.desk');

    // {'products':[{},{'desk2': {'price': 200}}]}

Obj.pluck()

The Obj.pluck() method retrieves all of the values for a given key from an array:

import { Obj } from '@devesharp/helpers-js';

Obj.pluck([{ id: 1 }, { id: 2 }, { id: 3 }], 'id');

// [1,2,3]

Obj.pluck([{ developer: { id: 1, name: 'Taylor' } }, { developer: { id: 2, name: 'Abigail' } }], 'developer.name'); // ['Taylor', 'Abigail']

Obj.divide()

The Obj.divide() method returns two arrays, one containing the keys, and the other containing the values of the given array:

import { Obj } from '@devesharp/helpers-js';

Obj.divide({ key: 'value' });

// [['key'], ['value']]

Obj.divide({ key: 'value', key2: 'value2' });

// [['key', 'key2'], ['value', 'value2']]

Obj.get()

The Obj.get() method retrieves a value from a deeply nested array using "dot" notation:

import { Obj } from '@devesharp/helpers-js';

Obj.get({ products: { desk: { price: 100 } } }, 'products.desk.price');

// 100

Obj.get({ products: { desk: { price: 100 } } }, 'products.desk.price');

// 100

The Obj.get() method also accepts a default value, which will be returned if the specific key is not found:

import { Obj } from '@devesharp/helpers-js';

Obj.get({}, 'products.desk.price', 200);

// 200

Obj.has()

The Obj.has() method checks whether a given item or items exists in an array using "dot" notation:

import { Obj } from '@devesharp/helpers-js';

Obj.get({ products: { desk: { price: 100 } } }, 'products.desk.price');

// true

Obj.get({ products: { desk: { price: 100 } } }, 'products.desk.price2');

// false

Obj.only()

The Obj.only() method returns only the specified key / value pairs from the given array:

import { Obj } from '@devesharp/helpers-js';

Obj.only({ name: 'Desk', price: 200 }, ['price']);

// {price: 200}

Obj.set()

The Obj.set() method sets a value within a deeply nested array using "dot" notation:

import { Obj } from '@devesharp/helpers-js';

Obj.set({ products: { desk: { price: 100 } } }, 'products.desk.price', 200);

// {'products':{'desk': {'price': 200}}}

Obj.dot()

The Obj.dot() method flattens a multi-dimensional array into a single level array that uses "dot" notation to indicate depth:

import { Obj } from '@devesharp/helpers-js';

Obj.dot({ products: { desk: { price: 100, price2: 200 } } });

// ['products.desk.price': 100, 'products.desk.price2': 200]

Str

Str.after()

The Str.after() method returns everything after the given value in a string:

import { Str } from '@devesharp/helpers-js';

Str.after('This is my name', 'This is my ');

// 'name'

Str.before()

The Str.before() method returns everything before the given value in a string:

import { Str } from '@devesharp/helpers-js';

Str.before('This is my name', 'my name');

// 'This is '

Str.camel()

The Str.camel() method converts the given string to camelCase:

import { Str } from '@devesharp/helpers-js';

Str.before('This is my name', 'my name');

// 'This is '