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

@asd14/m

v8.1.0

Published

Point free style, functional Javascript library with focus on object arrays

Downloads

156

Readme

CircleCI npm version Coverage Status

m

Point free style, functional library for Javascript with focus on object arrays.


Install

npm install @asd14/m

Use

import { pipe, trim, split, dropLast, push, join } from "@asd14/m"

const removeTrailingSlash = source =>
  source[source.length - 1] === sep ? source.slice(0, -1) : source

const renameFile = newName =>
  pipe(
    removeTrailingSlash,
    split(sep),
    dropLast,
    push(trim(sep, newName)),
    join(sep)
  )

"With" pattern

Some functions have a *With variant. find has findWith, filter has filterWith etc. They allow for less boilerplate and more intuitive way of handling object arrays.

import { find, findWith, filterWith, not, is } from "@asd14/m"

const todos = [
  { id: 1, name: "lorem", tagId: 2 },
  { id: 2, name: "ipsum", tagId: null },
  { id: 3, name: "dolor", tagId: null },
]
/* Predicate fn */
find(item => item.id === 1, todos)
// => {id: 1, name: "lorem", tagId: 2}

/* Matching object */
findWith(
  {
    id: 1,
  },
  todos
)
// => {id: 1, name: "lorem", tagId: 2}

/* Matching object & predicate fn */
filterWith(
  {
    tagId: is, // same as `tagId: source => is(source)`
  },
  todos
)
// => [{id: 1, name: "lorem", tagId: 2}]

/* Syntactic sugar */
filterWith(
  {
    "!tagId": is, // same as `tagId: not(is)`
  },
  todos
)
// => [
//  {id: 2, name: "ipsum", tagId: null},
//  {id: 3, name: "dolor", tagId: null}
// ]

|> pipe

There is no structure difference between pipe and compose, both will use the same building blocks to get from A to B.

A series of transformations over an initial input can be written as x -> f -> g -> result, piping, or as result = g(f(x)), composing. The difference is only syntactic. Input is the same, transformations and order of application are the same, the result will be the same.

Given that:

it makes sense to choose the syntax more aligned with our intuition and context. The transformations are applied in a certain order with time as a medium - input -> t0 -> t1 -> tn -> output.

const { sep } = require("path")
const { pipe, compose, join, push, dropLast, split } = require("@asd14/m")

// Compose: g(f(x))
const renameFile = newName => filePath =>
  compose(join(sep), push(newName), dropLast, split(sep))(filePath)

// Pipe: x -> f -> g
const renameFile = newName => filePath =>
  pipe(split(sep), dropLast, push(newName), join(sep))(filePath)

// More expressive with pipeline operator
const renameFile = newName => filePath =>
  filePath |> split(sep) |> dropLast |> push(newName) |> join(sep)

Develop

git clone [email protected]:asd14-xyz/m.git && \
  cd m && \
  npm run setup

# run tests (any `*.test.js`) once
npm test

# watch `src` folder for changes and run test automatically
npm run tdd

Contributors

Thank you for contributing your time and knowledge:

Changelog

See the releases section for details.