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

@yodata/transform

v1.6.10

Published

declarative, JSON transformation library

Downloads

64

Readme

@yodata/transform

declarative, composable JSON transformation utility.

Installation

> npm install --save @yodata/transform

Usage

const {Context, pluginDefaultValues} = require('@yodata/transform')

const input = {
    Name: 'Bruce Wayne',
    Address: '1007 Mountain Drive',
    City: 'Gotham City',
    State: 'NJ',
    Zip: '00001',
    Phone: '1-800-4-BATMAN'
}

const toPerson = new Context({
    Name: 'name',
    Address: 'streetAddress',
    City: 'addressLocality',
    State: 'addressRegion',
    Zip: 'postalCode',
    Phone: 'telephone'
})

toPerson.map(input)
// result
{
  name: 'Bruce Wayne',
  streetAddress: '1007 Mountain Drive',
  addressRegion: 'NJ',
  addressLocality: 'Gotham City',
  postalCode: '00001',
  telephone: '1-800-4-BATMAN'
}

Features

Table of Contents

fromString

Attempt to parse a string as yaml or json

Parameters

  • value string the value to parse
  • options object? optionsal js-yaml parserOptions (optional, default {json:true})

compileContext

Fetch a conext by path or url and return an async context.map helper function

Parameters

Returns Promise<function>

map

Parameters

  • object

pathArray

Converts a path expression a.b.c to a path array [a,b,c]

Parameters

Returns Array<string> pathArray

Context

Creates a new Context

Parameters

  • contextDefinition object? a valid ContextDefinition object (optional, default {})
  • options object? configuration options (optional, default {})

parseContext

Parse & normalize a context definition JSON string

Parameters
  • contextDefinition object a valid ContextDefinition

Returns object normalized ContextDefinition document

extend

Creates a new context from the current + the provided context definition document.

Parameters
  • cdef object a valid context definition object
  • options object? optional configuration and plugin options

Returns Context a new Context

toJSON

Returns JSON representation of the Context Definition

Returns string JSON ContextDefinition

toJS

Returns a plain javascript object representation of the current context

Returns object JavaScript object representation of the current context

setOption

Sets or creates a context.options.key value

Parameters
  • key string option.name
  • value any option.value

Returns Context Context

getOption

Get an option value

Parameters
  • key string option.name
  • defaultValue any? optional defaultValue

Returns any option.value | defaultValue

has

Checks the current context for key

Parameters

Returns boolean true if the current context contains key

get

Returns the value of key from the current context

Parameters
  • key (string | Array<string>) the property to find
  • defaultValue any? optional defaultValue

Returns any key.value | defaultValue

isRemoved

True if the provided key will be removed on transform

Parameters

Returns boolean true if the property found in the current context

isRedacted

True if the provided key will be redacted on transform

Parameters

Returns boolean true if property.redact = true

allowsAdditionalProperties

True if the context allows out-of-context values

isAllowed

Parameters

Returns boolean

mapKey

Returns the context name of key

Parameters

Returns string

mapKeys

Returns a new copy of object with the keys renamed by the active context (this)

Parameters

Returns object

mapValue

Executes the current context for the key/value pair and returns the resulting value

Parameters
  • value any the value
  • key (string | Array<string>) the key
  • object any? (optional, default {})
  • context any?

map

Process object with the current context non-destructive - always returns a new object

Parameters

Returns object the resulting state of object

transformEntry

Adds value to target.key. if target.key does not exist it will be created. if target.key is a scalar, it will be converted to an array and the new value will be pushed if target.key is an array, the new value is pushed to target.key if target.key is an object and value is an object, target.key will be recursively processed in the same manor

Parameters
  • target object the object being transformed
  • value any the value to add to target.key
  • key string the key
  • object any the original (source) object

Returns object the next state of target

use

Adds a plugin to the context

Parameters

Returns Context the new context with plugin installed

dispatch

Emits event to plug-in handlers

Parameters

Returns Context the current context

fromYaml

Create a new context from a YAML string

Parameters

Returns any

mapEntry

Processes the key/value pair with the current context and returns the resulting key/value pair or void if the key is not allowed

Parameters
  • entry any

Returns any [{string},{*}]

isExpression

Check for jsonata expression syntax

Parameters

  • value any

Returns any true if the value is a jsonata expression

Events

Context events used by plugins

getContext

Fetch context from path or object

Parameters

Returns Promise

loadContext

Parameters

Returns any @instance Context

loadData

Load data from a path to a yaml, json, js, or href or, if not a path, try to parse the string as yaml/json

Parameters

Returns Promise<object>

fromFile

Loads a javascript object from a filepath

Parameters

  • target string source pathname or href

Returns object parsed json or yaml object

isURL

Checks if value is a string starting with http

Parameters

  • value string the string to test

Returns boolean true if string starts with 'http'

License

MIT © Dave Duran