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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@12luckydev/utils

v3.1.1

Published

Utils for working with arrays!

Downloads

616

Readme

@12luckydev/utils

npm (scoped)

Few helper funtions to work with arrays without mutation and more.

Install

# using npm
npm i @12luckydev/utils

# using yarn
yarn add @12luckydev/utils

Usage

All utilities are available as named exports and can be imported directly from the main package entry:

import { insertAt, remove, editAt, ArrayPipe } from '@12luckydev/utils';

Non mutable array operation functions

add

insertAt

const array = [0, 1, 2, 3, 4, 5, 6, 7, 8];
insertAt(array, 4, 10); // result: [0, 1, 2, 3, 10, 4, 5, 6, 7, 8]
insertAt(array, 4, [10, 11]); // result: [0, 1, 2, 3, 10, 11, 4, 5, 6, 7, 8]

merge

merge([1, 2, 3], [4, 5]); // result: [1,2,3,4,5]

push

push([1, 2, 3], 4, 5); // result: [1,2,3,4,5]

edit

edit

const input = [
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob' },
  { id: 3, name: 'Charlie' },
];

edit(
  input,
  (el) => el.id === 2,
  (el) => ({ ...el, name: 'Bobby' }),
);
/**
    result: [
        {id: 1, name: "Alice"},
        {id: 2, name: "Bobby"},
        {id: 3, name: "Charlie"}
]
**/

editAt

const input = [
  { id: 1, name: 'Kevin' },
  { id: 2, name: 'Karen' },
  { id: 3, name: 'Bob' },
];

editAt(input, 1, { id: 4, name: 'Ann' });
/**
    result: [
        {id: 1, name: "Kevin"},
        {id: 4, name: "Ann"},
        {id: 3, name: "Bob"}
]
**/

editAt(input, (el) => ({..el, name: 'Lucy'}), 1);
/**
    result: [
        {id: 1, name: "Kevin"},
        {id: 2, name: "Lucy"},
        {id: 3, name: "Bob"}
]
**/

editByProp

const input = [
  { id: 1, name: 'Kevin' },
  { id: 2, name: 'Karen' },
  { id: 3, name: 'Bob' },
];

editByProp(input, { id: 4, name: 'Ann' }, 'id', 2);
/**
    result: [
        {id: 1, name: "Kevin"},
        {id: 4, name: "Ann"},
        {id: 3, name: "Bob"}
]
**/

move

move

move(['a', 'b', 'c', 'd', 'e'], 3, 1); // result: ['a', 'd', 'b', 'c', 'e']

moveUp

moveUp(['a', 'b', 'c', 'd', 'e'], 2); // result: ['a', 'b', 'd', 'c', 'e']

moveDown

moveDown(['a', 'b', 'c', 'd', 'e'], 2); // result: ['a', 'c', 'b', 'd', 'e']

shift

const array = ['a', 'b', 'c', 'd', 'e'];

shift(array, 1); // result: ['e', 'a', 'b', 'c', 'd']

shift(array, -1); // result: ['b', 'c', 'd', 'e', 'a']

shift(array, 1, false); // result: ['a', 'b', 'c', 'd']

shift(array, -1, false); // result: ['b', 'c', 'd', 'e']

pop

pop

pop(['a', 'b', 'c'], (el) => el === 'b'); // result ["b", ["a", "c"]]
pop(['a', 'b', 'c'], (el) => el === 'd'); // result [undefined, ["a", "b", "c"]]

popAt

popAt(['a', 'b', 'c'], 1); // result ["b", ["a", "c"]]

popByProp

const input = [
  { id: 1, name: 'Kevin' },
  { id: 2, name: 'Karen' },
  { id: 3, name: 'Bob' },
];

popByProp(input, 'name', 'Karen');
/**
    result: [
      { id: 2, name: 'Karen' },
      [
        { id: 1, name: "Kevin" },
        { id: 3, name: "Bob" }
      ]
  ]
**/

random

shuffle

const array = ['a', 'b', 'c', 'd', 'e'];

shuffle(array); // result: ['e', 'b', 'a', 'c', 'd']

shuffle(array); // result: ['a', 'c', 'e', 'd', 'b']

deshuffle

const array = [3, 1, 2];

deshuffle(array, [2, 0, 1]); // result: [1, 2, 3]

reshuffle

const array = [1, 2, 3];

reshuffle(array); // result: [[3, 1, 2] , [2, 0, 1]]
reshuffle([3, 1, 2], [2, 0, 1]); // result: [[1, 2, 3] , [2, 0, 1]]

remove

remove

remove(['a', 'b', 'c'], 'b'); // result ["a", "c"]
remove(['a', 'b', 'c'], (el) => el === 'b'); // result ["a", "c"]

removeAt

removeAt(['a', 'b', 'c'], 1); // result ["a", "c"]

removeByProp

const input = [
  { id: 1, name: 'Kevin' },
  { id: 2, name: 'Karen' },
  { id: 3, name: 'Bob' },
];

removeByProp(input, 'name', 'Karen');
/**
    result: [
        {id: 1, name: "Kevin"},
        {id: 3, name: "Bob"}
]
**/

toggle

toggle

toggle(['a', 'b', 'c'], 'b'); // result ["a", "c"]

toggle(['a', 'c'], 'b'); // result ['a', 'b', 'c']

toggleByProp

const input = [
  { id: 1, name: 'Kevin' },
  { id: 2, name: 'Karen' },
  { id: 3, name: 'Bob' },
];

toggleByProp(input, 'name', { id: 2, name: 'Karen' });
/**
    result: [
        {id: 1, name: "Kevin"},
        {id: 3, name: "Bob"}
]
**/

toggleByProp(input, 'name', { id: 4, name: 'Iwan' });
/**
    result: [
       { id: 1, name: 'Kevin' },
       { id: 2, name: 'Karen' },
       { id: 3, name: 'Bob' },
       { id: 4, name: 'Iwan' }
]
**/

Other array operation functions

common

compare

const array = [0, 1, 2, 3, 4, 5];
compare(array, [0, 1, 2, 3, 4, 5]); // result: true

const objArray = [
  { id: 1, value: 'value 1' },
  { id: 2, value: 'value 2' },
  { id: 3, value: 'value 3' },
];

compare(
  objArray,
  [
    { id: 2, value: 'value 2' },
    { id: 3, value: 'value 3' },
    { id: 4, value: 'value 4' },
  ],
  (elA, elB) => elA.id === elB.id,
); // result: true

nMap

nMap(3, (i) => `${i} value`); //result: ["0 value", "1 value", "2 value"]

dimension

to2D

to2D([1, 2, 3, 4]); //result: [[1, 2], [3, 4]]

separate

separate

separate([1, 2, 3, 4, 5, 6], (el) => el < 4); //result: [[1, 2, 3], [4, 5, 6]]

multiSeparate

multiSeparate([1, 2, 3, 4, 5, 6, 7, 8, 9], (el) => el % 3);

/**
 * Map:
 * 0 => [3, 6, 9]
 * 1 => [1, 4, 7]
 * 2 => [2, 5, 8]
 */

mappify

const inputArray = [
  { id: 1, value: 'a' },
  { id: 2, value: 'b' },
  { id: 3, value: 'c' },
];

mappify(inputArray, 'id');

/**
 * Map:
 * 1 => { id: 1, value: 'a' }
 * 2 => { id: 2, value: 'b' }
 * 3 => { id: 3, value: 'c' }
 */

diff

const inputArray1 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const result1 = diff(inputArray1, [2, 3, 4, 10], (a, b) => a === b);

/**
  result1: [
  // [added, removed] 
    [ [ 10 ], [ 1, 5, 6, 7, 8, 9 ] ],
  // [the same from new array, from input array]
    [ [ 2, 3, 4 ], [ 2, 3, 4 ] ],
  // [edited from new array, from input array] - no given editCheck func - so empty
    [ [], [] ]
  ]
 */

const inputArray = [
  { id: 1, v: '1' },
  { id: 2, v: '2' },
  { id: 3, v: '3' },
  { id: 4, v: '4' },
  { id: 5, v: '5' },
];

const result2 = diff(
  inputArray,
  [
    { id: 2, v: '2' },
    { id: 3, v: '3.1' },
    { id: 4, v: '4' },
    { id: 6, v: '6' },
  ],
  (a, b) => a.id === b.id,
  (a, b) => a.v === b.v,
);

/**
  result2: [
  // [added, removed] 
   [ { id: 6, v: '6' } ], [ { id: 1, v: '1' }, { id: 5, v: '5' } ] ],
  // [the same from new array, from input array]
   [ [ { id: 2, v: '2' }, { id: 4, v: '4' } ], [ { id: 2, v: '2' }, { id: 4, v: '4' } ]],
  // [edited from new array, from input array]
   [ [ { id: 3, v: '3.1' } ], [ { id: 3, v: '3' } ] ]
 */

range

isInRange

const array = [0, 1, 2, 3, 4, 5, 6, 7];
isInRange(array, 5); // result: true
isInRange(array, 10); // result: false

areInRange

const array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

areInRange(array, [0, 4, 7]); // result: true
areInRange(array, [-1, 0, 4, 10]); // result: false
areInRange(array, [-1, 0, 4, 10], false); // result: true
areInRange(array, [-1, 10], false); // result: true

Other helpers funtions

resolve

resolveValue

resolveValue(10, 11); // result: 10
resolveValue((el) => el + 2, 11); // result: 13

resolveArray

resolveArray(10); // result: [10]
resolveArray([10]); // result: [10]

ArrayPipe

Available utils operations:

  • add: insertAt merge push
  • edit: edit editAt editByProp
  • move: move moveDown moveUp shift
  • random: shuffle
  • remove: remove removeAt removeByProp
  • toggle: toggle toggleByProp
new ArrayPipe([1, 2, 3]).push(4, 5).insertAt(0, 0).result(); // result: [0, 1, 2, 3, 4, 5]

StringBuilder

new StringBuilder().appendLine('aaa').appendLine('bbb').toString(); // result: 'aaa\nbbb\n'
new StringBuilder('aaa', 'bbb').append('ccc', 'ddd').toString(); // result: 'aaabbbcccddd'

Changelog

All changes are here

License

MIT © 12LuckyDev