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

@streamster/coyote

v0.0.1-alpha.2

Published

A wiley, shapeshifting data transformation utility.

Downloads

6

Readme

@streamster/coyote

:warning: @streamster/coyote is still very much a work in progress. Features and implementations are likely to change.

A wiley, shapeshifting data transformation utility.

The aim of coyote is to make the process of programmatically transforming an input data set to match a desired output structure much simpler. The need for this package arose when I started working with the USGS Water Services.

Getting Started

To install the package

# yarn
yarn add @streamster/coyote

# npm
npm install @streamster/coyote

Usage

Coyote currently only exports the transform function, but I am guessing this will change down the road. Usage is relatively straightforward. You just need to provide a data and schema argument like in the example below. Pass the data that you would like to transform to the data argument. This can be an object or array. The schema argument expects an object with the desired property names and mappings for each object that is output by transform.

Using the schema in the example below, you can see that we want the transform function return an array of objects with the fields date, siteId, siteName, parameter...you get the idea. The value for each of these keys in the schema object represents where coyote needs to grab the associated value from in the source dataset. The string value follows the JavaScript Object Dot Notation with one very important exception. If the property you are accessing is an array and you need to iterate over it, you will need to place an * after the property name that will be iterated over. For example results.*.location will traverse the source data up until it hits the results property at which point it will loop through it and grab the value for the location property from each array item. This is difficult to explain but easier to show.

import { transform } from '@streamster/coyote';

// some mock source data to transform
const sourceData = {
  meta: {
    datasetName: 'Some Imaginaray Dataset',
    organization: 'Streamster',
    resultCount: 2
  },
  results: [
    { id: 1, date: '2021-02-10T14:24:29.909Z', location: 'LL-1', resultValue: 12 },
    { id: 2, date: '2021-02-12T14:24:29.909Z', location: 'LL-1', resultValue: 14 }
  ]
};

// define our desired output format and map our fields
// to fields in the source data
const transformSchema = {
  id: 'results.*.id',
  date: 'results.*.date',
  siteName: 'results.*.location',
  value: 'results.*.resultValue',
  organization: 'meta.organization'
};

const data = transform({
  data: sourceData,
  schema: transformSchema,
});

// data will yield
//  [
//    { 
//      id: 1, 
//      date: '2021-02-10T14:24:29.909Z', 
//      siteName: 'LL-1', 
//      value: 12, 
//      organization: 'streamster'
//    },
//    { 
//      id: 1, 
//      date: '2021-02-12T14:24:29.909Z', 
//      siteName: 'LL-1', 
//      value: 14, 
//      organization: 'streamster'
//    }
//  ]