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

reduce-to

v0.1.0

Published

convert and modify Arrays, Objects, Maps, Sets, Strings and iterators

Downloads

4

Readme

reduce-to

convert and modify Arrays, Objects, Maps, Sets and Strings. A powerful utility belt well under 1kb gzip, no dependencies

example

var x = require('reduce-to')

// CONVERSIONS
var source = ['a', 'b', 'c'],
    map = x(source, new Map), // Map of [0,'a'], [1, 'b'], [2, 'c']
    obj = x(map, {}), // {'0': 'a', '1': 'b', '2': 'c'}
    set = x(obj, new Set) // Set of 'a', 'b', 'c'
    txt = x(set, '') // 'abc'
    arr = x(txt, []) // same as source

// LAZY TRANSFORMS WITH TRANSDUCERS
var zAC = x(
  set, //start from any of the supported types
  x.filter(v=>v!=='b'), //filter transducer
  x.map(v=>v.toUpperCase(), //map transducer
  'z' //target with initial value
)) // 'zAC

Features

  • apply multiple transforms in a lazy and efficient way
  • convert to any javascript key-value data types
    • var myMap = x(JSON.parse(json), new Map)
    • var json = x(set, [])
    • var noDuplicates = x(x(arr, new Set), [])
    • var shallowClone = x(obj, {})
    • var plusOne = x(new Int8Array([1,2,3]), x.map(v=>v+1)) converted to an Array
  • works seamlesly in ES5

supported types

  • Input: Array, Strings, Object, Map, Set, Iterators
  • Output: Array, Strings, Object, Map, Set, WeakMap, WeakSet

key value conversions

  • Array: index, value
  • String: index, value
  • Object: key, value
  • Map: key.toString(), value
  • Set: index, value
  • Iterators: index, value

transducer and reducer functions

To keep things light and simple, only 3 reducer types are provided

  • .map((val, key, source) => newValue)
  • .filter((val, key, source) => Boolean)
  • .index((val, index, source) => Boolean)

index is similar to filter but with a counter index instead of the key (same as Array.filter). Most common other reducers can be emulated with these 3 base reducers:

  • take(N): use index((val, idx) => idx < N)
  • drop(N): use index((val, idx) => idx >= N)
  • ...reject, dropWhile, ...

License

MIT © Hugo Villeneuve