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

@fec/ape

v2.1.0

Published

Array processing engine

Downloads

3

Readme

Ape

Ape is an array processing engine. It takes an array of records and gives you a convenient interface to operate on it. Operations are processed in batch.

Made by 👨‍💻 Florian Eckerstorfer in 🎡 Vienna, Europe.

Table of Contents

  1. Installation
  2. Usage
  3. API documentation
  4. Code of conduct
  5. Contributing
  6. Change log
  7. License

Installation

You can install ape with NPM or Yarn:

npm install --save @fec/ape
yarn add @fec/ape

Usage

ape does only have a single export, the titular ape function. It takes an array of records and returns an object with various functions to process the array.

import { ape } from 'ape';

const data = ape([{ a: 'val 1' }, { a: 'val 2' }])
  .map((record) => ({ a: record.a.toUpperCase() }))
  .renameKey('a', 'b').data;
// → [{ b: 'VAL 1' }, { b: 'VAL 2' }]

API documentation

In the following API documentation we will be using the following types:

  • ApeRecordKey: alias for string | number, used as key in ApeRecord
  • Value: value used in ApeRecord
  • ApeRecord: object with key-value pairs
  • ApeData: array of ApeRecord

Map

map((record: ApeRecord, index: number, data: ApeData) => ApeRecord) => ape

Takes a map function that is applied for each record in the array.

Example

import { ape } from 'ape';

const data = [{ a: 'val 1' }, { a: 'val 2' }];
const newData = ape(data).map((record) => ({ a: record.a.toUpperCase() })).data;
// → [{ a: 'VAL 1' }, { a: 'VAL 2' }]

Map value

mapValue(key: ApeRecordKey, (value: Value, key: ApeRecordKey, index: number, data: ApeData) => Value) => ape

Takes a mapValue function that is applied to the value with the given key for each record in the array.

Example

import { ape } from 'ape';

const data = [{ a: 'val 1' }, { a: 'val 2' }];
const newData = ape(data).mapValue('a', (a) => a.toUpperCase())).data;
// → [{ a: 'VAL 1' }, { a: 'VAL 2' }]

Add value

addValue(newKey: ApeRecordKey, (record: ApeRecord, key: ApeRecordKey, index: number, data: ApeData) => Value) => ape

Takes a addValue function that is used to add a new value to each record with the given key.

import { ape } from 'ape';

const data = [{ a: 'val 1' }, { a: 'val 2' }];
const newData = ape(data).addValue('b', (r) => Object.keys(r)).data;
// → [{ a: 'val 1', b: ['a'] }, { a: 'val 2', b: ['a'] }]

Rename key

renameKey(key: ApeRecordKey, newKey: ApeRecordKey) => ape

Renames the given key to newKey in each record in the array.

Example

import { ape } from 'ape';

const data = [{ a: 'val 1' }, { a: 'val 2' }];
const newData = ape(data).renameKey('a', 'b').data;
// → [{ b: 'val 1' }, { b: 'val 2' }]

Create index

createIndex(keys: ApeRecordKey | ApeRecordKey[]) => ape

Creates an index for the given key or keys, by creating a hash-map of all possible values. This is a pre-requisite for using the findByIndex() function.

Example

See findByIndex().

Merge by index

mergeByIndex(keys: ApeRecordKey | ApeRecordKey[], mergeData: ApeData) => ape

Merges the array with the given data by the given key or keys. For the given mergeData an index is created before the merge is performed.

Example

import { ape } from 'ape';

const data = [
  { id: 1, a: 'val 1' },
  { id: 2, a: 'val 2' },
];
const otherData = [
  { id: 1, b: 'foo 1' },
  { id: 2, b: 'foo 2' },
];
const newData = ape(data).createIndex('id').mergeByIndex('id', otherData).data;
// → [{ id: 1, a: 'val 1', b: 'foo 1' }, { id: 2, a: 'val 2', b: 'foo 2' }]

Find by index

findByIndex(query: Partial<ApeRecord>) => ApeRecord | undefined

Returns the single record from the array of records that matches the given query or undefined if no record matches the query. Throws an error if no index exists for the keys present in the query.

Example

import { ape } from 'ape';

const data = [
  { id: 1, a: 'val 1' },
  { id: 2, a: 'val 2' },
];
const result = ape(data).createIndex('id').findByIndex({ id: 1 });
// → { a: 'val 1' }

Code of conduct

See CODE_OF_CONDUCT

Contributing

To contribute to @fec/ape, follow these steps:

  1. Fork this repository.
  2. Create a branch: git checkout -b <branch_name>.
  3. Install dependencies: npm install
  4. Make your changes (please also update the tests and documentation)
  5. Don't forgot to run the tests: npm test
  6. Commit your changes: git commit -m '<commit_message>'
  7. Push to the original branch: git push origin <project_name>/<location>
  8. Create the pull request.

Alternatively see the GitHub documentation on creating a pull request.

Change log

See CHANGE_LOG

License

See LICENSE