Socket
Book a DemoInstallSign in
Socket

@walltowall/auxline

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@walltowall/auxline

Generate auxillary data using a series of contextually aware functions.

0.1.2
latest
npmnpm
Version published
Maintainers
3
Created
Source

auxline

Generate auxillary data using a series of contextually aware functions.

npm version

npm i auxline

Usage

import auxline from 'auxline'

// Data used to generate auxillary data.
const list = [
  { id: 1, type: 'HeroBlock', text: 'Text for a Hero component' },
  { id: 2, type: 'CallToActionBlock', text: 'Hey', buttonText: 'Call Me' },
  { id: 3, type: 'FooterBlock', year: 2074 },
]

// List of functions to generate auxillary data derived from the provided data.
const fns = {
  // Get a list of types for each item in data.
  types: data => data.map(x => x.type),

  // Get a list of keys for each item in data.
  keys: data => data.map(x => x.id),

  // Get a list of containers for each item in data.
  containers: (data, { types }) =>
    data.map((x, i) => (types[i] === 'FooterBlock' ? 'footer' : 'body')),

  // Group data items by container with keys.
  tree: (data, { keys, containers }) =>
    data.reduce((acc, x, i) => {
      const key = keys[i]
      const container = containers[i]

      acc[container] = (acc[container] || []).concat({ ...x, key })

      return acc
    }, {}),
}

const { types, keys, containers, tree } = auxline(fns, list)

API

auxline(fns, data)
  • fns: Object of functions. Each key represents a group of auxillary data. Auxillary data will be available to subsequent functions using the function's key.
  • data: Any data to be used to generate auxillary data.

Each function in fns is provided two pieces of data:

  • data: The original data provided to auxline.
  • context: An object of auxillary data. Each function receives the aggregate auxillary data keyed by function name.

Functions are called serially in the order of property definition.

Keywords

data

FAQs

Package last updated on 27 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.