0.0.10 • Published 3 years ago

d12 v0.0.10

Weekly downloads
50
License
MIT
Repository
github
Last release
3 years ago

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:password@my.domain.com:5050/some/path/to/index.html?token=me#fragment'
console.log(parseURL(url))
// => {
//      absolute: 'https://user:password@my.domain.com: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.

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

4 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago