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

pacit

v0.1.4

Published

make JavaScript chainable and more readable.

Downloads

6

Readme

pacit CircleCI

make JavaScript chainable and more readable.

How to use

Install

npm install --save pacit
# or
yarn add pacit

API

There are only 4 methods you should notice.

  • pacit pack a value
import pacit from 'pacit'

pacit(123) // pack a number
pacit('test') // pack a string
pacit({ foo: 'bar' }) // pack an object
pacit([123]) // pack an array
  • map map the value to another. It accepts a pure function.
const addOne = (n: number) => n + 1
const result = pacit(123)
  .map(addOne)
  .valueOf()

console.log(result) // 124
  • and execute some side effect here. It returns the original value whatever the return value of the function you pass in is.

You can get rid of any and at any time.

const result = pacit(123)
  .map(addOne)
  .and(console.log) // 124
  .map(addOne)
  .and(console.log) // 125
  .and(addOne) // nothing happends here
  .valueOf()

console.log(result) // 125
  • valueOf unpack and get the value in it
pacit(123)
  .map(addOne)
  .valueOf() // return 124

Why This

For last few years, I was constantly trying to make JavaScript more functional. I used underscore, lodash and ramda and all of them are nice.

However, recently I found JavaScript might be not so functional, despite of somewhat features of functional programming supported.

Suppose we need to reverse digits of a given integer. We probably do like this if using basic JavaScript.

Basic JavaScript

function solution(num) {
  const str = String(num)
  const arr = str.split('')
  const reversedArr = arr.reverse()
  const reversedStr = arr.join('')

  return parseInt(reversedStr)
}

Annoying! We have to make up 4 names for these variables. Or we can merge some actions

function solution(num) {
  const str = String(num)
  const reversed = str
    .split('')
    .reverse()
    .join('')

  return parseInt(reversed)
}

More clearer huh! But we still have to make up two names at least. Let try with Ramda

Ramda

const solution = R.pipe(String, R.reverse, parseInt))

Pretty good! I used to love this way. Because of the limitation of TypeScript, the pipe methods cannot accept too many arguments.

Pacit

As I use React, I tend to focus on data only.

const solution = (num: number) =>
  pacit(num)
    .map(String)
    .add(console.log) // You can use `add` anywhere you like. Since it will not affect the value, it's easy to be removed.
    .map(R.reverse)
    .add(alert)
    .map(parseInt)
    .valueOf()