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

fnional

v0.0.5

Published

Functional Programming inpired helper-functions

Downloads

14

Readme

FNional

Functional helper functions

Why me?

Across projects, I noticed I ended up (re-)writing the same set of functions nearly every time. This repo is supposed to be those functions and their flow-typings in one place, so I don't have to copy-paste them over or reinvent them every time.

None of the functions do ground-breaking stuff. I like them 'cause they make my code look a bit prettier and easy to write.

Why me though?

I was never really too happy with the signatures, naming, typing, size or any other property of other available library. Either they offer too much bloat or just aren't what I need. These functions are supposed to be exactly the way I want them.

Also, it's a fun thing to work on every now and then, I suppose.

API

getIn

Returns a property from an object.

getIn: (object: Object, key) => any

Example

const person = {name: 'Stijn Tytgat', nickname: 'stinodes', age: 23}
const age: number = getIn(person, 'age')

getDeep

Returns a deep property from an object (or undefined when not found).

getDeep: (object: Object, keys: Array<*>) => any

Example

const object = {
    property: {
        nestedProperty: 'Nested Value!',
    },
}
const var = getDeep(object, ['property', 'nestedProperty'])

setIn

Returns a new object with the property key set to value.

setIn: (object: Object, key, value) => O

Example

const person = {name: 'Stijn Tytgat', nickname: 'stinodes', age: 23}
const newPerson = setIn(person, 'name', 'Not my true name >:)')

deleteIn

Returns a new object without the property key.

deleteIn: (object: Object, key) => O

Example

const person = {name: 'Stijn Tytgat', nickname: 'stinodes', age: 23}
const personWithoutNickname = deleteIn(person, 'nickname')

shallowMerge

Returns a new object made up of the properties of both passed objects.

shallowMerge: (object: Object1, object: Object2) => {...Object1, ...Object2}

Example

const numbers = {three: 3, two: 2, one: 1}
const letters = {a: a, b: b, c: c}
const numbersAndLetters = shallowMerge(number, letters)

composeReturn

Accepts a function and a value, and returns a new function always returning the passed value, ignoring the original function's return.

composeReturn: (returnValue: R, fn: Params => any) => Params => R

Example

const logger = {log: console.log}
logger.log = composeReturn(logger, log)
logger.log('test')
  .log('test')
  .log('test')
  

onCatch

Calls a callback when an error is thrown.

onCatch: (Params => R, (Error, ...Params) => any) => (Params) => R

Example

const returnString = (value) => {
  if (typeof value !== 'string') throw 'NOT A STRING'
  return value
}
const handled = onCatch(returnString, console.error)
handled('A string')     // callback not called
handled(420)            // callback called

throwIf

Throws the given error if the condition matches

throwIf: (condition: boolean, error: Error|() => Error) => void

Example

const person = {name: 'Stijn'}
const car = {brand: 'Cannot improvise a car brand'}
function validPerson(personObject) {
  return !!personObject.name
}
throwIf(validPerson(person), new Error('This is no person')) // No error
throwIf(validPerson(car), new Error('This is no person'))    // Error!