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

data-lazers

v0.1.0

Published

Easier data translations in JavaScript

Downloads

5

Readme

DataLazers

Make converting unknown data into a standard format a bit easier. This library allows you to write data transformations as data structures and declarative functions.

It's a small library (2.9kB with dependencies) and easy to extend with your own operators.

Warning

This is a new project so treat it as pre-alpha and subject to change.

Hopefully it can get more stable over the next few weeks/months.

Installation

npm i data-lazers

Usage

L is the base object for the library.

There is one main function translate and six smaller functions prefixed by an underscore:

  • _default
  • _equals
  • _format
  • _or
  • _pipe
  • _when

Show me the code

More examples are coming but here are some samples:

L.translate({foo: 'hello'}, {hello: 'world'});
// => {foo: 'world'}

L.translate({foo: 'hello'}, {
    hello: 'world',
    other: 'things' // filtered out, key didn't match
});
// => {foo: 'world'}

// hold onto 'yer butts
L.translate({
    large: 'example', // 'object'
    // match of/other or default to lots
    with: L._default('lots', 'of', 'little'), // 'lots'
    // when 'and' exists, return {'other': 0}
    things: L._when('and', {'other': 0}), // { other: 0 }
    // pipe functions, match nested lookup, even number?, multiply by 100
    fun: L._pipe('stuff', 'over', 'here', n => n + 1, n => n * 100), // 600
    // tagged template for pulling out key values and indexes
    look: L._format`it's a ${'cool'} string`, // it's a template string
    // 
    and: L._or('some', 'other', 'strings'), // other
    // didn't match
    pretty: 'neat eh?' //null
}, {
    example: 'object',
    stuff: {over: {here: 5}},
    cool: 'template',
    and: 100,
    other: 'other'
});
/*
=> {
    large: "object",
    with: "lots",
    things: { other: 0 },
    fun: 600,
    look: "it's a template string",
    and: "other"
}
*/

There are moderately good JSDocs and tests to look through for now.

TODO

  • [ ] js-verify for extra testing, all core functions
  • [ ] add a GH pages site with machine-generated docs
  • [ ] open source real-world apps using lib
  • [ ] clean up core/index.js
  • [ ] show extra domain-specific functions extending the core lib
  • [ ] set up builds for different styles, IFFE/ES6/CJS/UMD
  • [ ] write a better README
  • [ ] add memes :D