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

slice-foo

v0.1.4

Published

Slices foo any way you'd like

Downloads

7

Readme

slice-foo

Slices foo any way you'd like

Install

$ npm install --save slice-foo

Written in ES6 and uses generators so you'll need Node 6 or a transpiler to use it.

Usage

const sliceFoo = require('slice-foo')

sliceFoo.slice([4, 4, 4, 4], '4040414142424343')
//=> ['4040', '4141', '4242', '4343']


// It's curried so you can do compose functions like
const parseCardNumber = sliceFoo.slice([4, 4, 4, 4])

parseCardNumber('4040414142424343')
//=> ['4040', '4141', '4242', '4343']

parseCardNumber('4040414142')
//=> ['4040', '4141', '42']

parseCardNumber('40404141')
//=> ['4040', '4141']

// easily join into the format you'd like
parseCardNumber('4040414142424343').join(' ')
//=> '4040 4141 4242 4343'
  • sliceWith functions to specify chunk sizes dynamically, see API.

Read the tests to see how it behaves.

API

Note:

Sliceable: A type that implements .slice (eg. Array and String)

.slice

slice :: [Number] -> Sliceable -> [a]

Slices a sliceable into chunks specified by an array of numbers

const sliceFoo = require('slice-foo')

sliceFoo.slice([4, 4, 4, 4], '4040414142424343')
//=> ['4040', '4141', '4242', '4343']

.sliceWith

sliceWith :: (() -> Number) -> Sliceable -> [a]

Slices a sliceable into chunks using a function

const sliceFoo = require('slice-foo')

let i = 0
const getChuckSize = () => {
  if (i++ % 2 === 0)
    return 4
  else
    return 2
}

sliceFoo.sliceWith(getChuckSize, '4040414142424343')
//=> ['4040', '41', '4142', '42', '4343']

.sliceWithGenerator

sliceWithGenerator :: (function* -> Number) -> Sliceable -> [a]

Slices a sliceable into chunks using a generator

const sliceFoo = require('slice-foo')

function* chunkGenerator () {
  let n = 0
  while (n++ < 2)
    yield 4
}

sliceFoo.sliceWithGenerator(chunkGenerator, '4040414142424343')
//=> ['4040', '4141']

Why?

I needed a module to format strings and found most modules do too many things. It's built to be useful on it's own and composed into more specific functions. Aaand I wanted to publish my first open source project ☝️

License

MIT © Sindre Seppola