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

ssv

v4.1.1

Published

space separated values module

Downloads

50

Readme

ssv

download

<script src="ssv.js"></script>

package

npm install ssv
const ssv = require("ssv")

methods

all

Test if SSV contains all search values

ssv.all(SSV="", search="")
ssv.all("mark tom travis", "scott") // false
ssv.all("mark tom travis", "mark tom") // true
ssv.all("mark tom travis", "mark scott") // false

and

  • Get unique values present both in left and right
  • Ideal for intersecting
ssv.and(left="", right="")
ssv.and("", "mark") // ""
ssv.and("mark matt travis", "tom scott") // ""
ssv.and("mark tom tom", "mark tom travis") // "mark tom"
let many = ["mark tom", "mark travis", "mark matt"]
many.reduce(ssv.and) // "mark"

any

Test if SSV contains any search values

ssv.any(SSV="", search="")
ssv.any("mark tom travis", "matt") // false
ssv.any("mark tom travis", "mark") // true
ssv.any("mark tom travis", "mark scott") // true
ssv.any("mark tom travis", "mark travis") // true

at

Get the value at index

ssv.at(SSV="", index)
ssv.at("mark tom travis", 0) // "mark"
ssv.at("mark tom travis", 1) // "tom"
ssv.at("mark tom travis", -1) // "travis"
ssv.at("mark tom travis", -2) // "tom"
ssv.at("mark tom travis", 5) // ""

blank

Test if SSV is blank

ssv.blank(SSV="")
ssv.blank("travis") // false
ssv.blank("      ") // true
ssv.blank("") // true
ssv.blank(0) // false
ssv.blank() // true

count

Count SSV values

ssv.count(SSV="")
ssv.count("matt matt matt") // 3
ssv.count("mark      tom ") // 2

edit

  • Edit an SSV string via an object or string
  • Optimal for batch editing CSS classes
  • Keys for falsey values are removed
  • Keys for truthy values are added
  • Removals process before adds
  • Result is compact and unique
  • Like ssv.or if boss is string
  • ssv.state uses ssv.edit
ssv.edit(SSV="", boss={})
ssv.edit("mark tom travis", {
  "matt": true,
  "tom scott": false
}) // "mark travis matt"

ssv.edit("mark", {
  "mark travis": true,
  "travis": false
}) // "mark travis"
ssv.edit("mark tom scott", Object.assign(
  { scott: false },
  { travis: true }
)) // "mark tom travis"
let bosses = [/* objects or strings */]
bosses.reduce(ssv.edit, "") // forward
bosses.reduceRight(ssv.edit, "") // backward

gum

Concatenate with compact space

ssv.gum(left="", right="")
ssv.gum("mark tom", "scott travis") // "mark tom scott travis"
ssv.gum("mark tom", "tom   travis") // "mark tom tom travis"
let many = ["tom tom", null, "travis travis", ""]
many.reduce(ssv.gum) // "tom tom travis travis"

jam

Compact excess space

ssv.jam(SSV)
ssv.jam("  mark  travis   matt ") // "mark travis matt"
ssv.jam("  matt      ") // "matt"
ssv.jam("  0     182 ") // "0 182"
ssv.jam(-182) // "-182"
ssv.jam(182) // "182"
ssv.jam(" ") // ""
ssv.jam(0) // "0"
ssv.jam() // ""

not

  • Get values in left that are not in right
  • Ideal for removing values or diffing
ssv.not(left="", right="")
ssv.not("mark tom travis", "tom") // "mark travis"
ssv.not("mark tom tom", "mark matt") // "tom tom"
ssv.not("matt matt matt", "") // "matt matt matt"
ssv.not("mark mark", "tom tom") // "mark mark"
ssv.not("mark tom tom tom", "tom") // "mark"
let many = ["mark tom", "mark travis", "mark matt"]
many.reduce(ssv.not) // "tom"

or

  • Get unique values found in left or right or both
  • Ideal for adding values or unioning
ssv.or(left="", right="")
ssv.or("mark tom ", "travis tom") // "mark tom travis"
ssv.or("mark tom tom", "travis tom") // "mark tom travis"
ssv.or("matt mark", "matt") // "matt mark"
let many = ["mark tom", "mark travis", "mark matt"]
many.reduce(ssv.or) // "mark tom travis matt"

say

Simply stringify unknown

ssv.say(unknown="")
ssv.say(undefined) // ""
ssv.say(null) // ""
ssv.say(0) // "0"
ssv.say(NaN) // "NaN"
ssv.say(182) // "182"
ssv.say("tom") // "tom"
ssv.say(true) // "true"
ssv.say(false) // "false"
ssv.say(new Number(182), "182")
ssv.say(new String("tom"), "tom")
ssv.say(new Boolean(true), "true")
  • Used internally when expecting strings
  • Not intended for arrays or plain objects
  • Join arrays instead like [].join(" ")
  • Plain objects may use ssv.edit or ssv.state

split

Split SSV into dense array

ssv.split(SSV)
ssv.split("mark tom travis") // ["mark", "tom", "travis"]
ssv.split("     mark  tom ") // ["mark", "tom"]
ssv.split("0 0  182       ") // ["0", "0", "182"]
ssv.split(0) // ["0"]
ssv.split(" ") // []
ssv.split("") // []
ssv.split() // []

state

ssv.state(state={})
ssv.state("mark  tom  ") // "mark tom"
ssv.state({
  "mark travis": true,
  "matt": true,
  "tom scott": false
}) // "mark travis matt"

ssv.state({
  "mark": true,
  "mark travis": true,
  "travis": false
}) // "mark mark travis"
let states = [/* objects or strings */]
ssv.yolo(states.map(ssv.state).join(" "))

xor

  • Get unique values found in either left or right but not both
  • Ideal for toggling values
ssv.xor(left="", right="")
ssv.xor("", "mark mark") // "mark"
ssv.xor("mark tom", "mark") // "tom"
ssv.xor("mark tom", "travis") // "mark tom travis"
ssv.xor("mark tom", "travis tom") // "mark travis"
ssv.xor("mark tom travis", "tom matt") // "mark travis matt"
ssv.xor("mark tom tom", "mark mark") // "tom"
ssv.xor("mark mark", "tom tom") // "mark tom"
let many = ["mark tom", "mark travis", "mark matt"]
many.reduce(ssv.xor) // "tom travis mark matt"
many.reduceRight(ssv.xor) // "matt travis mark tom"

yolo

  • Get unique SSV values
  • Hella fast unique loop
  • Be unique because yolo
  • Case sensitive
ssv.yolo(SSV="")
ssv.yolo("tom tom travis") // "tom travis"
ssv.yolo("Na na na na   ") // "Na na"
ssv.yolo("Na na na na".toLowerCase()) // "na"