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

liget

v1.0.5

Published

Utility projet providing shortcut functions for HOFs

Downloads

50

Readme

Liget

The goal is to provide util methods to use as shortcuts with functionnal processes such as Higher-Order functions.

Usage

Install

yarn add liget

Or

npm install --save liget

Import

Import all features at lib level :

import liget from 'liget';

Features

et()

This function is a shortcut for props & methods on a list of objects. Example:

users.map((user) => user.name);
// vs
users.map(et('name'));

Import

import et from 'liget/et';
// OR
import { et } from 'liget';

Behaviour

Given an array of objects such as

const users = [
  {
    firstName: 'Ada',
    lastName: 'Lovelace',
    name() {
      return `${this.firstName} ${this.lastName}`
    },
    greet(name: string) {
      console.log(`Hello ${name}, I'm ${this.name()}`);
    },
    introduce(first: string, second: string) {
      console.log(`Hello ${first}, I'm ${this.name()} and this is ${second}`);
    },
  },
  // ...
];

Property access

The et() function takes the name of the property as argument and returns its value.

const firstNames = users.map(et('firstName'));

console.log(firstNames);
// ['Ada']

Method invocation

When the targeted method takes no parameter, the et() function takes the name of the method as its single argument.

const names = users.map(et('name'));

console.log(names);
// ['Ada Lovelace']

When the targeted method takes a single parameter, the et() function takes the name of the method as its first argument and the parameter value as its second argument, either directly or wrapped in an array*.

users.forEach(et('greet', 'Margaret Hamilton'));
// "Hello Margaret Hamilton, I'm Ada Lovelace"

users.forEach(et('greet', ['Grace Hopper']));
// "Hello Grace Hopper, I'm Ada Lovelace"

* caveat: when the method parameter is an array, it should always be wrapped in another array since it would be impossible to distinguish the desired value from a wrapped value (i.e. ['foo'] could be the argument value or a wrapped 'foo' argument)

When the targeted method takes at least two parameters, the et() function takes the name of the method as its first argument and an array of parmater values as its second argument.

users.forEach(et('introduce', ['Margaret Hamilton', 'Grace Hopper']));
// "Hello Margaret Hamilton, I'm Ada Lovelace and this is Grace Hopper"

neo()

This function is a shortcut for class instantiation from a list of values. Example:

documents.map((doc) => new User(doc));
// vs
documents.map(neo(User));

Import

import neo from 'liget/neo';
// OR
import { neo } from 'liget';

Behaviour

This function is meant to be used with single param constructor functions only, whatever type that param may be.

Example:

function User({ name, login }) {
  this.name = name;
  this.login = login;
}

const data = [
  { name: 'Ada Lovelace', login: 'a.lovelace' },
  { name: 'Margaret Hamilton', login: 'm.hamilton' },
];

data.map(neo(User));

nea()

This function is a shortcut for class instantiation from a list of entries or arguments array. Example:

entries.map((entry) => new User(entry[0], entry[1]));
// vs
entries.map(nea(User));

Import

import nea from 'liget/nea';
// OR
import { nea } from 'liget';

Behaviour

This function is meant to be used with constructor functions acception 1..n params, whatever type those params may be.

Example:

function User(name, login) {
  this.name = name;
  this.login = login;
}

const data = [
  ['Ada Lovelace', 'a.lovelace'],
  ['Margaret Hamilton', 'm.hamilton'],
];

data.map(nea(User));