ssv

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

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 " ) ssv . all ( " mark tom travis " , " mark tom " ) ssv . all ( " mark tom travis " , " mark scott " )

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 " )

let many = [ " mark tom " , " mark travis " , " mark matt " ] many . reduce ( ssv . and )

any

Test if SSV contains any search values

ssv . any ( SSV = " " , search = " " )

ssv . any ( " mark tom travis " , " matt " ) ssv . any ( " mark tom travis " , " mark " ) ssv . any ( " mark tom travis " , " mark scott " ) ssv . any ( " mark tom travis " , " mark travis " )

at

Get the value at index

ssv . at ( SSV = " " , index )

ssv . at ( " mark tom travis " , 0 ) ssv . at ( " mark tom travis " , 1 ) ssv . at ( " mark tom travis " , - 1 ) ssv . at ( " mark tom travis " , - 2 ) ssv . at ( " mark tom travis " , 5 )

blank

Test if SSV is blank

ssv . blank ( SSV = " " )

ssv . blank ( " travis " ) ssv . blank ( " " ) ssv . blank ( " " ) ssv . blank ( 0 ) ssv . blank ( )

count

Count SSV values

ssv . count ( SSV = " " )

ssv . count ( " matt matt matt " ) ssv . count ( " mark tom " )

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

if is string ssv.state uses ssv.edit

ssv . edit ( SSV = " " , boss = { } )

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

ssv . edit ( " mark tom scott " , Object . assign ( { scott : false } , { travis : true } ) )

let bosses = [ ] bosses . reduce ( ssv . edit , " " ) bosses . reduceRight ( ssv . edit , " " )

gum

Concatenate with compact space

ssv . gum ( left = " " , right = " " )

ssv . gum ( " mark tom " , " scott travis " ) ssv . gum ( " mark tom " , " tom travis " )

let many = [ " tom tom " , null , " travis travis " , " " ] many . reduce ( ssv . gum )

jam

Compact excess space

ssv . jam ( SSV )

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

not

Get values in left that are not in right

that are in Ideal for removing values or diffing

ssv . not ( left = " " , right = " " )

ssv . not ( " mark tom travis " , " tom " ) ssv . not ( " mark tom tom " , " mark matt " ) ssv . not ( " matt matt matt " , " " ) ssv . not ( " mark mark " , " tom tom " ) ssv . not ( " mark tom tom tom " , " tom " )

let many = [ " mark tom " , " mark travis " , " mark matt " ] many . reduce ( ssv . not )

or

Get unique values found in left or right or both

both Ideal for adding values or unioning

ssv . or ( left = " " , right = " " )

ssv . or ( " mark tom " , " travis tom " ) ssv . or ( " mark tom tom " , " travis tom " ) ssv . or ( " matt mark " , " matt " )

let many = [ " mark tom " , " mark travis " , " mark matt " ] many . reduce ( ssv . or )

say

Simply stringify unknown

ssv . say ( unknown = " " )

ssv . say ( undefined ) ssv . say ( null ) ssv . say ( 0 ) ssv . say ( NaN ) ssv . say ( 182 ) ssv . say ( " tom " ) ssv . say ( true ) ssv . say ( 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 " ) ssv . split ( " mark tom " ) ssv . split ( " 0 0 182 " ) ssv . split ( 0 ) ssv . split ( " " ) ssv . split ( " " ) ssv . split ( )

state

Get unique compact SSV string from state object or string

Shorthand for ssv.edit("", state)

Like ssv.yolo(state) if string

if string Optimal for conditional CSS classes

ssv . state ( state = { } )

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

let states = [ ] ssv . yolo ( states . map ( ssv . state ) . join ( " " ) )

xor

Get unique values found in either left or right but not both

but both Ideal for toggling values

ssv . xor ( left = " " , right = " " )

ssv . xor ( " " , " mark mark " ) ssv . xor ( " mark tom " , " mark " ) ssv . xor ( " mark tom " , " travis " ) ssv . xor ( " mark tom " , " travis tom " ) ssv . xor ( " mark tom travis " , " tom matt " ) ssv . xor ( " mark tom tom " , " mark mark " ) ssv . xor ( " mark mark " , " tom tom " )

let many = [ " mark tom " , " mark travis " , " mark matt " ] many . reduce ( ssv . xor ) many . reduceRight ( ssv . xor )

yolo

Get unique SSV values

Hella fast unique loop

Be unique because yolo

Case sensitive

ssv . yolo ( SSV = " " )