0.0.26 • Published 2 years ago

@jmellicker/j_ v0.0.26

Weekly downloads
65
License
MIT
Repository
github
Last release
2 years ago

j_

it's a toolkit of random and useful functions

install:

yarn add @jmellicker/j_

string ops

given this string:

let x = 'cat.dog.dolphin.shark'

firstItemOf

j_.firstItemOf(x) // => 'cat'

lastItemOf

j_.lastItemOf(x) // => 'shark'

nthItemOf

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

allButFirstItemOf

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

allButLastItemOf

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

randomItemOf

j_.randomItemOf(x) // => 'dog' or maybe something else!

All above ops will auto-detect ',' '.' '/' & '|' in that order. For a different delimiter, pass it as the last argument:

let x = 'cat#dog#dolphin#shark'

j_.nthItemOf(x, 2, '#') // => 'dolphin'

removeSpaces

decodeHTML

educateQuotes

replaceHtmlAttributeQuotes

straightenQuotes

dashify

toTitleCase

j_.toTitleCase(tHIs is wEIrD) // => 'This Is Weird"

array ops

j_ array ops only operate on flat object keys in an array.

Given this array:

let 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

j_.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

j_.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

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

sortArrayBy

Sorts an array of objects by a key

uniqueKeysFromArray

Returns an array of unique keys from an array of objects

queryArrayAllUniqueValues

queryArrayOneOfEach

queryArrayMaxValue

removeFirstMatchFromArray

sortArrayBy

shuffleArray

removeKeyFromAllArrayObjs

arrayOfKeyValuesFromObject

stringOfKeyValuesFromObject

queryObjectFirstMatch

removeMatchedObjectsFromArray

convertObj2array

mergeObjects

cloneObject

sortObjectBy

addKeyToTopOfObject

subVars

createTableFromUnstructuredData

randomInteger

randomAlphaNumeric

randomCrayolaColor

randomAnimal

uaid

ucid

uniqID

randomLoadingMessage

randomSuccessQuote

validEmailAddress

luhnCheck

objSub

openCleanWindow

fillCleanWindowWithHTML

secondsToHms

hmsToSeconds

formatMonthYear

decodeHtmlEntity

naturalSorter

0.0.26

2 years ago

0.0.24

3 years ago

0.0.23

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.1

5 years ago

1.0.0

6 years ago