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

d12

v0.0.10

Published

A Platonic Solid for Ideal Data

Downloads

13

Readme

Version License Coverage

D12

A Platonic Solid for Ideal Data
by Collective Acuity

Intro

d12 is a javascript package for data ingestion and validation. d12 extends the methods in lodash to tackle the evaluation of more complex data structures in order to reduce code verbosity and make input validation easier.

Installation

From NPM:

$ npm install d12

From GitHub:

$ git clone https://github.com/collectiveacuity/d12
$ cd d12
$ npm install

Usage

ingestObject : to ensure a plain object output

import { ingestObject } from 'd12'
console.log(ingestObject({me: 'you'}))
// { me: 'you' }
console.log(ingestObject(['me','you']))
// { }

ingestOptions : to merge an object of options into an object of defaults and preserve scope and typing

import { ingestOptions } from 'd12'
let options = {
  token: 'abc',
  dt: 1123456789.012,
  timeout: '4000',
  extra: 'key'
};
let defaults = {
  token: '',
  dt: 0.0,
  timeout: 9000,
  method: 'header',
  offline: false
};
console.log(ingestOptions(options, defaults))
// => { 
//      token: 'abc', 
//      dt: 1123456789.012,
//      timeout: 9000, 
//      method: 'header', 
//      offline: false 
//    }

parseDiff : to compare the difference between two objects and output only the fields with altered values

import { parseDiff } from 'd12'
let current = {
  token: 'abc',
  dt: 1123456789.012,
  timeout: '4000',
  extra: 'key'
};
let previous = {
  token: 'abc',
  dt: 0.0,
  timeout: 9000,
  method: 'header',
  offline: false
};
console.log(parseDiff(current, previous))
// => {
//      dt: 1123456789.012,
//      timeout: '4000',
//      extra: 'key',
//      method: null,
//      offline: null 
//    }

validateString : to test a string input against a set of valid criteria

import { validateString } from 'd12'
let criteria = {
  datatype: 'string',
  min_length: 8,
  max_length: 64,
  excluded_values: [ '12345678', 'password' ]
};
console.log(validateString('password', criteria))
// => { 
//      required: '',
//      prohibited: 'cannot be "12345678" or "password"'
//    }

parseURL : to test validity of url syntax and parse components

import { parseURL } from 'd12'

let url = 'https://user:[email protected]:5050/some/path/to/index.html?token=me#fragment'
console.log(parseURL(url))
// => {
//      absolute: 'https://user:[email protected]:5050',
//      scheme: 'https',
//      user: 'user',
//      password: 'password',
//      host: 'my.domain.com',
//      port: 5050,
//      path: '/some/path/to/index.html',
//      query: 'token=me',
//      fragment: 'fragment',
//      errors: {},
//      valid: true
//    }  
 
url = 'http://notavalidport.com:abc'
console.log(parseURL(url).errors)
// => {
//      port: 'abc'
//    }

Testing

$ npm test

Building

$ npm run build

Reporting

$ npm run coverage

Collaboration Notes

A collaborator should always FORK the repo from the main master and fetch changes from the upstream repo before making pull requests. Please add unittests and documentation for any additional code in a pull request.