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

@jadesrochers/fpstreamline

v0.1.8

Published

Functional programming additions to pass arrays, manipulate data

Downloads

15

Readme

fpstreamline

A small library for functional programming; functions I found to be
missing elsewhere that were useful. Also shortcuts for fcns that do exist.

Whats the Use?

Whether using ramda or lodash you can get most of what is needed, but there
were some functions I wanted that were not availble or had awkward syntax.

installation

npm install @jadesrochers/fpstreamline

const fps = require('@jadesrochers/fpstreamline')
const R = require('ramda')

Usage

Piping async functions

Allows async functions to be piped, and also handles regular functions.
Consider it a regular piping function that is also async tolerant.

let testprom1 = n => Promise.resolve(n-1)
let testprom2 = n => Promise.resolve(n-2)
let testprom3 = n => Promise.resolve(n-3)
let test = async () => {
 let rslt = await fps.pipeAsync(
     R.adjust(1)(testprom1),
     R.adjust(1)(testprom2),
     R.adjust(1)(testprom3),
  )([0,6])
 console.log('Result: ', rslt)
}
test()
// [0,0]

Array manipulation functions

Append and Prepend automatically convert to array

I wanted to be able to use unknown length/type input, and these do. They will take single values or an array and app/pre pend either way.

R.pipe(
  fps.append(2),
  fps.append(3),
  )(1)
// [ 1, 2, 3 ]

R.pipe(
  fps.prepend(2),
  fps.prepend(3),
  )(1)
// [ 3, 2, 1 ]

Append and Prepend result of fcns on specified input

Also append/prepend, but takes a function and index, and append/prepend the
result of running the function on the index. Can take single value or array, if single value use (0) for index.

let testfn1 = n => n+1
let testfn2 = n => n+2

R.pipe(
  fps.appendUseNth(1)(testfn1),
  fps.appendUseNth(2)(testfn2),
  )([0,1,2])
// [ 0, 1, 2, 2, 4 ]

R.pipe(
  fps.prependUseNth(1)(testfn1),
  fps.prependUseNth(2)(testfn2),
  )([0,1,2])
// [ 3, 2, 0, 1, 2 ]

Insert result of fcn on input array member

R.pipe(
  fps.insertUseNth(1)(1)(testfn1),
  fps.insertUseNth(2)(2)(testfn2),
  )([0,1,2])
// [ 0, 2, 3, 1, 2 ]

runN and runAll run function on some or all array members

The arity must be correct, nothing fancy going on here.

fps.runAll(a => b => c => d => e => a+b+c+d+e)([0,1,2,3,4])
// 10
fps.runN(3)(a => b => c => a+b+c)([0,1,2,3,4])
// 9

Regex functions

For quickly getting correctly escaped/formatted regular expression string
when the text to be searched has special characters.

Escape all special characters and all except periods

fps.regexEscapeAll('-/\\^$*+?.()|[]{}')
fps.regexEscapeExPer('-/\\^$*+?.()|[]{}')

Create regex from text passed

toRegex uses what you pass verbatim, getRegex escaped all special
characters except period.

fps.toRegex('i')('abc*(ghi+)?')
//  /abc*(ghi+)?/i
fps.getRegex('abc*+?[]()ghi')
//  /abc\*\+\?\[\]\(\)ghi/i

Search functions

strSearchBool performs a search of the string using a regex but returns just a boolean of whether a match was found, not how many, where, or anything else.

fps.strSearchBool(/abc/)('filler abc filler')
// true
fps.strSearchBool(/abc/)('filler Abc filler')
// false

Conversions and Type testing

These are mostly just wrappers around other functions to
do testing/converting.
Supported types include object, number, boolean, string, null, array,
regexp, function, undefined

Check the type of a passed object

fps.isTypeof('object')({})
// true
fps.isTypeof('object')({a:1, b:2})
// true

Check if the types of two objects match

Will match R.type rules.

fps.typeMatch('def')('abc')
// true
fps.typeMatch({})({a:1, b:2})
// true
fps.typeMatch(null)(undefined)
// false

Convert string to JSON

fps.toJSON('{"a":1,"b":[1,2,3],"c":3}')
//   { a: 1, b: [ 1, 2, 3 ], c: 3 }

Convert string to number

Converts to number if it has just numbers.

fps.strToNum('4620')
// Converts
fps.strToNum('34-35')
// Keeps as string
fps.strToNum('34,351')
// keeps as string

Convert string to Date

It follows rules of Date() object creation, so anything valid
for that should work with this.

fps.toDate('11-05-1955')
fps.toDate('December 7, 1941')
fps.toDate('1453-05-29')

Convert to array accounting for various scenarios

fps.toArray(5)
// [ 5 ]
fps.toArray('test string')
// [ 'test string' ]
fps.toArray({a: 1})
// [ {a: 1} ]
fps.toArray([1,2,3])
// [ 1, 2, 3 ]

Math functions

These are implemented everywhere of course, I just wanted the option of dividing by the value passed first without R.flip. Not very useful.

R.pipe(
  fps.subtract(3),
  fps.divide(3),
)(12)
// 3