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

@beardedtim/api-data-mapper

v0.1.1

Published

A way to map API to needed schema

Downloads

12

Readme

#Component Mapper

blah

Utils

Common Errors

If you get TypeError: Cannot read property 'indexOf' of undefined it is probably because you don't have your config object set correctly. A correctly set config object will have as its root keys, keys that match the desired output object. Each key on the config object MUST have at least 2 keys: type and key. type tells the function how to handle the value and key tells the function where on the data object we want to get the value from.

configureFromTypes

This is a way to pass in custom types to the configuration function. This must be an array of objects with the schema { type: 'some type', method: function }

The method will be called with the following arguments:

method.call(null, config[k], data, config)
  • config[k] is the value at the current config key. k corresponds with the final key/root key from the config object.
  • data is the whole object we are configuring.
  • config is the whole configuration object in case the method needs to know something special about the configuration.

Whatever this method returns will be set on the final object at the key corresponding to k in the above.

configureObject

This has the default types of list, basic, nested, and flat. You can look in ./modules/utils.js to see what those methods are. This is a curried version of configureFromTypes.

ConfigureObject = { type, key, ...props}

ArrayConfigObject = { type = 'list', value, ...props }

NestedConfigObject = { type = 'nested', value, ...props }

MasterConfig = { [FINAL_KEY]: ConfigureObject | ArrayConfigObject }

configureObject: MasterConfig -> Object -> Object

ConfigureObject:

  • type key is the string to tell the function how to handle your request
  • Anything else besides key will be copied over flat

ArrayConfigObject:

  • type is 'list'
  • value is an array of ConfigureObjects

MasterConfig:

  • string keys that correspond to the target object's keys
  • Each key will be processed through the type

Default Types

The following are the default types that come with configureObject:

  • list: This config must be
{
  type: 'list',
  key: [KEY_ON_INCOMING_OBJECT],
  value: [
    {
      key: [KEY_ON_INCOMING_OBJECT],
      // ...passedProps
    }
  ]
}
  • list returns an array of { value, ...passedProps }
  • flat: This config must be:
{
  key: [KEY_ON_INCOMING_OBJECT],
  type: 'flat'
}
  • flat does not copy any props and just sets the value
  • nested: This config must be
{
  key: [KEY_ON_INCOMING_OBJECT],
  type: 'nested',
  value: {
    // Config Object
  }
}
  • nested allows for custom nested values
  • basic: This config must be:
{
  key: [KEY_ON_INCOMING_OBJECT],
  type: 'basic',
  // ...passedProps
}
  • basic returns values underneath the value key.

Rules

  • Every default type except for flat returns the mapped values under a value key in the newly created object.
  • The key of the configuration is the desired final key:
    • Example: { name: { ... } } as config would return { name: ... } object.
  • The key inside of the config, as in { key: 'abc' }, is the key we are wanting to look for in the incoming object