1.2.1 • Published 3 years ago

@callmekory/utils v1.2.1

Weekly downloads
25
License
ISC
Repository
github
Last release
3 years ago
const {code, stdout, stderr} = await execAsync('date')

print(stdout) // prints Fri 27 Mar 2020 06:47:24 PM PDT
ordinalSuffix(2) // add ordinal suffix to number 2

Returns

2nd
const someList = ["I'm a blue dog", "I'm a red dog", "I'm a green dog"]
const searchTerms = ["dog", "red"]

filterByKeywords(someList, searchTerms)

Returns

["I'm a red dog"]
await asyncForEach(array, (item) => {
  // callback
})
const date = new Date('2020-03-08 05:44:22.185 +00:00') // Random date from a while ago

differenceInHours(date) // Check how many hours ago the date was

Returns

476.69
const sampleArray = ["one", "two", "three", "four", "five", "six"]

chunkArray(sampleArray, 3) // Split array into 3 equal chunks

Returns

[
  ["one", "two"],
  ["three", "four"],
  ["five", "six"]
]
// Find all mp4 files in a directory
findFilesByType("path/to/dir", ".mp4")
// Print Hello World with 5 spaces
console.log(`Hello${addSpace(5)}World`)

Returns

"Hello     World"
capitalize("hello")

Returns

"Hello"
sortByKey(array, "key")
const originalArray = [
  {
    animal: "dog",
    color: "brown"
  },
  {
    animal: "dog",
    color: "white"
  },
  {
    animal: "cat",
    color: "white"
  },
]

// Split array based off of the anime type
groupByProperty(originalArray, "animal")

Returns

[
  dog: [
    { animal: 'dog', color: 'brown' },
    { animal: 'dog', color: 'white' }
  ],
  cat: [ { animal: 'cat', color: 'white' } ]
]
const bytes = 1000000 // 1 megabytes in bytes

const converted = bytesToSize(bytes)

Returns

"1 MB"
// convert 2 minutes in milliseconds to time string
const time = millisecondsToTime(120000) 

Returns

2:00
await sleep(1000) // asynchronously sleeps for 1 second
1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago