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

ts-manip

v1.1.1

Published

Manipulate arrays and objects efficiently

Downloads

15

Readme

ts-manip

Install

In terminal, run:

npm i ts-manip

Usage

Import

import * as manip from 'ts-manip';

Methods can also be imported separatly:

import { flattenDeep } from 'ts-manip/flattenDeep';
OR
import { flattenDeep } from 'ts-manip';

Available functions

  • additiveMergeDeep: Performe a deep additive merge on values of an object, on a (key, value) basis
  • filter: Filter elements of an array
  • filteredMap: Map an array to another, thanks to a tranform function, filtering the elements to keep thanks to a predicate function
  • findFirst: Find the first matching element in an array
  • findLast: Find the last matching element in an array
  • flattenDeep: Flatten deeply an array (or up to a given depth), and can transform elements thanks to an optional tranform function
  • forEach: Iterates over elements of an array and invoke a function for each element
  • forEachAsync: Iterates over elements of an array and invoke an asynchronous function for each element
  • groupBy: Group elements of an array, thanks to an iteratee
  • map: Map an array to another, thanks to a tranform function
  • numericDiff: Return the differences of numeric values between 2 objects of the same type
  • reduce: Reduce an array to a new single value, thanks to a tranform function.
  • splitIntoMultiple: Split an array into an array of arrays of length <= to a given max length

Examples

const mapped = manip.map([1, 2, 3], (element) => { return element + 5; });
// mapped = [6, 7, 8];

const filtered = manip.filter(
	[{ id: 'aaa', type: 'a' }, { id: 'bbb', type: 'b' }, { id: 'ccc', type: 'a' }],
	(element) => { return element.type === 'a'; }
);
// filtered = [{ id: 'aaa', type: 'a' }, { id: 'ccc', type: 'a' }];

const difference = manip.numericDiff({ A: 10, B: -20 }, { A: 5, B: 30 });
// difference = { A: -5, B: 50 };

const result = manip.additiveMergeDeep(
	{ A: 5, B: 'part1', C: true, D: [1, 3], E: { val: 10 }, F: 25 },
	{ A: 10, B: '-part2', C: false, D: [5, 6], E: { val: 2, score: 1 } }
);
// result = { A: 15, B: 'part1-part2', C: false, D: [1, 3, 5, 6], E: { val: 12, score: 1 }, F: 25 };

Contribute

Please feel free to suggest features or bug fix through Git issues. Pull Requests for that are also more than welcome.