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

identitate

v1.0.1

Published

Custom identity functions for composability

Downloads

31,057

Readme

identitate

A tiny custom identity function creator for composable softwares.

Table of contents

Usage

import {createIdentity, identity, identitySecond, identityLast, identitySecondLast} from 'identitate';

// use built-in methods
console.log(identity('first', 'second', 'third', 'fourth', 'fifth')); // 'first'
console.log(identitySecond('first', 'second', 'third', 'fourth', 'fifth')); // 'second'
console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fifth'
console.log(identitySecondLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fourth'

// or create your own
const identityThird = createIdentity(2);
const identityThirdLast = createIdentity(-3);
const identityFirstNested = createIdentity(0, 'deeply[0].nested');

console.log(identityThird('first', 'second', 'third', 'fourth', 'fifth')); // 'third'
console.log(identityThirdLast('first', 'second', 'third', 'fourth', 'fifth')); // 'third'
console.log(identityFirstNested({deeply: [{nested: 'value'}]}, 'second', 'third', 'fourth', 'fifth')); // 'value'

Pre-built methods

identity

returns first argument passed to it

The classic identity function:

console.log(identity('first', 'second', 'third', 'fourth', 'fifth')); // 'first'

identitySecond

returns second argument passed to it

console.log(identitySecond('first', 'second', 'third', 'fourth', 'fifth')); // 'second'

Example usage when creating meta properties with the popular redux-actions package:

import {identity, identitySecond} from 'identitate';
import {createAction} from 'redux-actions';

export const doThing = createAction('DO_THING', identity, identitySecond);

console.log(doThing('payload', 'meta')); // {meta: 'meta', payload: 'payload', type: 'DO_THING'}

identityLast

returns last argument passed to it, regardless of total number of arguments

console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fifth'
console.log(identityLast('first', 'second', 'third')); // 'third'

identitySecondLast

returns second-to-last argument passed to it, regardless of total number of arguments

console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fourth'
console.log(identityLast('first', 'second', 'third')); // 'second'

Custom methods

createIdentity

creates a new identity method based on the parameters passed

createIdentity(position: number[, path: (Array<number|string>|number|string)]): any

// use a positive number to get the index of the arguments (zero-indexed)
const identityFourth = createIdentity(3);

console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fourth'

// use a negative number to get the index of the arguments relative to the last
const identityThirdLast = createidentity(-3);

console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'third'

// include a path to get the deeply-nested value of that argument
const identityNested = createIdentity(0, 'deeply.nested');

console.log(identityNested({deeply: {nested: 'value'}})); // 'value'

The path parameter uses pathington under the hood for path parsing, so check there for valid values.

Browser support

  • Chrome (all versions)
  • Firefox (all versions)
  • Edge (all versions)
  • Opera 15+
  • IE 9+
  • Safari 6+
  • iOS 8+
  • Android 4+

Development

Standard stuff, clone the repo and npm install dependencies. The npm scripts available:

  • build => run webpack to build development dist file with NODE_ENV=development
  • build:minified => run webpack to build production dist file with NODE_ENV=production
  • dev => run webpack dev server to run example app / playground
  • dist => runs build and build-minified
  • lint => run ESLint against all files in the src folder
  • prepublish => runs compile-for-publish
  • prepublish:compile => run lint, test:coverage, transpile:es, transpile:lib, dist
  • test => run AVA test functions with NODE_ENV=test
  • test:coverage => run test but with nyc for coverage checker
  • test:watch => run test, but with persistent watcher
  • transpile:lib => run babel against all files in src to create files in lib
  • transpile:es => run babel against all files in src to create files in es, preserving ES2015 modules (for pkg.module)