Skip to content
/ j_ Public
forked from jmellicker/j_

j_ - semantic ops for Javascript data objects and strings

License

Notifications You must be signed in to change notification settings

dwolner/j_

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

j_

semantic ops for Javascript data objects and strings

Just barely getting started. Play with j_ here.

string ops

given this string:

x = 'cat.dog.dolphin.shark'

firstItemOf

firstItemOf(x) // => 'cat'

lastItemOf

lastItemOf(x) // => 'shark'

nthItemOf

nthItemOf(x, 3) // => 'dolphin'

allButFirstItemOf

allButFirstItemOf(x) // => 'dog.dolphin.shark'

allButLastItemOf

allButLastItemOf(x) // => 'cat.dog.dolphin'

All string ops will auto-detect a period or comma delimiter. If you are using a different delimiter, pass it as the last argument:

x = 'cat|dog|dolphin|shark'

nthItemOf(x, 2, '|') // => 'dog'

array ops

Given this array:

xmen = [{
  name: 'Nightcrawler',
  power: 'Teleportation'
}, {
  name: 'Cyclops',
  power: 'Optic blast'
}, {
  name: 'Rogue',
  power: 'Absorbing powers'
}, {
  name: 'Wolverine',
  power: 'Regeneration'
}]

indexFromArray

Searches an array of objects for a whole value for a specified key and returns the index of the first matching element

indexFromArray(xmen, 'power', 'Optic blast') // => 1

queryArrayFirstMatch

Searches an array of objects for a whole value for a specified key and returns the first matching array element

queryArrayFirstMatch(xmen, 'power', 'Optic blast') // => { "name": "Cyclops", "power": "Optic blast" }

queryArrayAllMatches

Searches an array of objects for a whole or partial value for a specified key and returns all matching array elements

queryArrayAllMatches(xmen, 'power', 'po') // => [ { "name": "Nightcrawler", "power": "Teleportation" }, { "name": "Rogue", "power": "Absorbing powers" } ]

uniqueKeysFromArray

Returns an array of unique keys from an array of objects

About

j_ - semantic ops for Javascript data objects and strings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%