@patrtorg/minima-exercitationem-minus
v5.6.93
Published
@patrtorg/minima-exercitationem-minus / [Exports]()
Downloads
1,938
Maintainers
Keywords
Readme
@patrtorg/minima-exercitationem-minus / Exports
@patrtorg/minima-exercitationem-minus
Utility library in TypeScript, with a focus on Node and FP utils and emphasis on not rewriting builtin features.
Installation
npm i @patrtorg/minima-exercitationem-minus
Usage
See the docs below for details (generated from types and comments). Example:
import * as z from '@patrtorg/minima-exercitationem-minus'
const answer = await z.prompt('Pick a letter')
if (z.isEmpty(answer)) process.exit(1)
@patrtorg/minima-exercitationem-minus
Table of contents
Interfaces
Type Aliases
Variables
Functions
- and
- average
- basename
- camelCaseToLispCase
- camelCaseToPascalCase
- camelCaseToSnakeCase
- capitalizeFirstChar
- chunk
- clamp
- collapseNewlines
- collapseWhitespace
- collectBy
- combineRegex
- compose
- countIn
- countItemsInArray
- curry
- debounce
- diff
- div
- doubleUntil
- drop
- dropWhile
- each
- elem
- escapeForRegex
- execute
- fileExists
- filter
- findIndices
- findPort
- flattenAndUniq
- flip
- fold
- getFreeDisk
- getFreeMemory
- getGlobal
- getHashFromDate
- getHashFromSystem
- getKeyByValue
- getLoadAverage
- getMemoryUsage
- getOrdinal
- getProjectRoot
- getRandomString
- getRegexFlags
- getStdin
- getTerminalColumns
- getTerminalRows
- getTerminalSize
- getUserHome
- getUserShell
- greater
- groupBy
- gt
- gte
- has
- hasColor
- hasDuplicate
- head
- id
- init
- initials
- intersection
- is
- isArrayLike
- isBetween
- isBoolean
- isClass
- isDate
- isDefined
- isDirectory
- isEmpty
- isError
- isEven
- isFile
- isFloat
- isFunction
- isGenerator
- isGeneratorFunction
- isInstalled
- isInteger
- isJson
- isMap
- isNode
- isNull
- isNullOrUndefined
- isNumber
- isObject
- isOdd
- isPow2
- isPrimitive
- isPromise
- isRegExp
- isRoot
- isSemver
- isSet
- isString
- isSymLink
- isSymbol
- isUndefined
- isValidDate
- keep
- last
- len
- lesser
- lightenOrDarken
- lines
- lispCaseToCamelCase
- lispCaseToPascalCase
- lispCaseToSnakeCase
- lt
- lte
- mapObject
- memoize
- mzero
- nco
- noop
- notElem
- objectToString
- once
- open
- pair
- pairWith
- pascalCaseToCamelCase
- pascalCaseToLispCase
- pascalCaseToSnakeCase
- pick
- pipe
- pluck
- product
- prompt
- range
- readJson
- reduce
- removeBOM
- replicate
- rgbToHex
- safeGet
- scaleToFit
- shuffle
- sleep
- snakeCaseToCamelCase
- snakeCaseToLispCase
- snakeCaseToPascalCase
- sortBy
- sortObject
- span
- splitAt
- store
- stripAnsi
- sub
- sum
- tail
- take
- takeLast
- takeWhile
- tap
- touch
- truncate
- tryJson
- typeOf
- union
- uniq
- uniqBy
- unless
- unlines
- until
- unwords
- unzip
- watch
- words
- writeJson
- xor
- zip
- zipWith
Type Aliases
AnyFn
Ƭ AnyFn: (...args
: any
[]) => any
Type declaration
▸ (...args
): any
Parameters
| Name | Type |
| :------ | :------ |
| ...args
| any
[] |
Returns
any
Defined in
AnyMap
Ƭ AnyMap: Record
<string
, any
>
Defined in
Cb
Ƭ Cb: (error
: c.ExecFileException
| null
, stdout
: string
| Buffer
, stderr
: string
| Buffer
) => void
Type declaration
▸ (error
, stdout
, stderr
): void
Parameters
| Name | Type |
| :------ | :------ |
| error
| c.ExecFileException
| null
|
| stdout
| string
| Buffer
|
| stderr
| string
| Buffer
|
Returns
void
Defined in
ColMap
Ƭ ColMap: Record
<string
, (t
: string
) => string
>
Defined in
F
Ƭ F: (...args
: any
[]) => any
Type declaration
▸ (...args
): any
Parameters
| Name | Type |
| :------ | :------ |
| ...args
| any
[] |
Returns
any
Defined in
Listener
Ƭ Listener: (a
: AnyMap
, b
: AnyMap
) => any
Type declaration
▸ (a
, b
): any
Parameters
| Name | Type |
| :------ | :------ |
| a
| AnyMap
|
| b
| AnyMap
|
Returns
any
Defined in
R
Ƭ R: Record
<string
, number
>
Defined in
R
Ƭ R: (...args
: any
[]) => Timer
Type declaration
▸ (...args
): Timer
Parameters
| Name | Type |
| :------ | :------ |
| ...args
| any
[] |
Returns
Defined in
R
Ƭ R: string
| any
[] | AnyMap
Defined in
Timer
Ƭ Timer: NodeJS.Timeout
| number
| null
Defined in
Updater
Ƭ Updater: (a
: AnyMap
) => AnyMap
Type declaration
▸ (a
): AnyMap
Parameters
| Name | Type |
| :------ | :------ |
| a
| AnyMap
|
Returns
Defined in
Variables
colorize
• Const
colorize: ColMap
Defined in
Functions
and
▸ and<T
>(a
): boolean
Returns false if any in input array is false
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| a
| T
[] |
Returns
boolean
Example
and([ 1, 2, 3 ]) // => true
and([ 1, 2, 3, false ]) // => false
Defined in
average
▸ average(xs
): number
Averages a list of numbers
Parameters
| Name | Type |
| :------ | :------ |
| xs
| number
[] |
Returns
number
Example
average([ 2, 4, 6, 8 ]) // => 5
Defined in
basename
▸ basename(str?
): string
basename
for Node
Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| str
| string
| ''
|
Returns
string
Example
basename() // => string
Defined in
camelCaseToLispCase
▸ camelCaseToLispCase(str
): string
Takes a camelCase string and returns one in lisp-case
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
camelCaseToLispCase('fooBar') // => 'foo-bar'
Defined in
camelCaseToPascalCase
▸ camelCaseToPascalCase(str
): string
Takes a camelCase string and returns one in PascalCase
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
camelCaseToPascalCase('fooBar') // => 'FooBar'
Defined in
camel-case-to-pascal-case.ts:7
camelCaseToSnakeCase
▸ camelCaseToSnakeCase(str
): string
Takes a camelCase string and returns one in snake_case
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
camelCaseToSnakeCase('fooBar') // => 'foo_bar'
Defined in
capitalizeFirstChar
▸ capitalizeFirstChar(str
): string
Capitalizes the first character of string
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
capitalizeFirstChar('things and stuff') // => 'Things and stuff'
Defined in
chunk
▸ chunk<T
>(arr
, n
): T
[][]
Splits an array into chunks
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| T
[] |
| n
| number
|
Returns
T
[][]
Example
chunk([1, 2, 3, 4 ], 2) // => [ [ 1, 2 ], [ 3, 4 ] ]
Defined in
clamp
▸ clamp(val
, min
, max
): number
Takes a number, min, and max If number is between min and max, returns number Otherwise returns min or max
Parameters
| Name | Type |
| :------ | :------ |
| val
| number
|
| min
| number
|
| max
| number
|
Returns
number
Example
clamp(100, 0, 1000) // => 100
clamp(100, 101, 1000) // => 101
clamp(100, 0, 99) // => 00
Defined in
collapseNewlines
▸ collapseNewlines(str
): string
Collapses multiple newlines to two
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
collapseNewlines('\n\n\n\n') // => '\n\n'
Defined in
collapseWhitespace
▸ collapseWhitespace(str
): string
Collapses consecutive whitespace to a single space
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
collapseWhitespace('a\n\r\t\nb') // => 'a b'
Defined in
collectBy
▸ collectBy(p
): (a
: any
[]) => AnyMap
Collect an an array of objects by string key cred: gh:uniqname
Parameters
| Name | Type |
| :------ | :------ |
| p
| string
|
Returns
fn
▸ (a
): AnyMap
Parameters
| Name | Type |
| :------ | :------ |
| a
| any
[] |
Returns
Example
const data = [ { foo: 'a', bar: 'baz' }, { foo: 'b', bar: 'quux' }, { foo: 'a', bar: 'whatever' } ]
collectBy('foo')(data) // => { a: { foo: 'a', bar: 'whatever' }, b: { foo: 'b', bar: 'quux' } }
Defined in
combineRegex
▸ combineRegex(rs
, opts?
): RegExp
Combines regular expressions
Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| rs
| RegExp
[] | undefined
|
| opts
| string
| ''
|
Returns
RegExp
Example
combineRegex([/[a-z]/, /[0-9]], 'g') ==> /[a-z][0-9]/g
Defined in
compose
▸ compose<T
>(...fns
): (t
: T
) => T
Right to left composition
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| ...fns
| (t
: T
) => T
[] |
Returns
fn
▸ (t
): T
Parameters
| Name | Type |
| :------ | :------ |
| t
| T
|
Returns
T
Example
const addOne = (a) => a + 1
const timesTwo = (a) => a * 2
compose(addOne, timesTwo)(2) // => 5
Defined in
countIn
▸ countIn<T
>(el
, ls
): number
Find out how many of a given element is in an array or string.
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| el
| T
|
| ls
| string
| T
[] |
Returns
number
Example
countIn('a', 'abc') // => 1
countIn('a', [ 'a', 'b', 'c' ]) // => 1
Defined in
countItemsInArray
▸ countItemsInArray<T
>(arr
): R
Get an object of items in an array with count
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| T
[] |
Returns
Example
countItemsInArray([ 1, 1, 2, 3, 4 ]) // => { '1': 2, '2': 1, '3': 1, '4': 1 }
Defined in
curry
▸ curry<T
>(fn
): F
Takes a function and returns a function that takes any number of arguments
Produces a curried function
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| fn
| F
|
Returns
Example
const addThree = (a, b, c) => a + b + c
curry(addThree)(1)(1)(1) // => 3
Defined in
debounce
▸ debounce(fn
, ms
): R
Simple debounce
Parameters
| Name | Type |
| :------ | :------ |
| fn
| (...args
: any
) => any
|
| ms
| number
|
Returns
Example
debounce(() => console.log('hi'), 5000)
Defined in
diff
▸ diff<T
>(a
, b
): T
[]
Diff two arrays
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| a
| T
[] |
| b
| T
[] |
Returns
T
[]
Example
diff([ 1, 2, 3 ], [ 2, 3 ]) // => [ 1 ]
Defined in
div
▸ div(ns
): number
Divide any amount of numbers
Parameters
| Name | Type |
| :------ | :------ |
| ns
| number
[] |
Returns
number
Example
div([ 4, 2, 1 ]) // => 2
Defined in
doubleUntil
▸ doubleUntil(minSize?
): <T>(arr
: T
[]) => T
[]
Double an array until it's n long
Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| minSize
| number
| 0
|
Returns
fn
▸ <T
>(arr
): T
[]
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| T
[] |
Returns
T
[]
Example
doubleUntil(2)([ 'hi' ]) // => [ 'hi', 'hi' ]
Defined in
drop
▸ drop<A
>(n
, arr
): A
[]
Like Haskell's drop
Type parameters
| Name |
| :------ |
| A
|
Parameters
| Name | Type |
| :------ | :------ |
| n
| number
|
| arr
| A
[] |
Returns
A
[]
Example
drop(2, [ 1, 2, 3 ]) // => 3
Defined in
dropWhile
▸ dropWhile<T
>(pred
, arr
): T
[]
The opposite of takeWhile
:
takes a predicate and array and returns an
array of the elements that didn't pass the predicate
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| pred
| (x
: T
) => boolean
|
| arr
| T
[] |
Returns
T
[]
Example
dropWhile(lessThanThree, [ 1, 2, 3, 4 ]) // => [ 3, 4 ]
Defined in
each
▸ each<T
>(xs
, fn
): Record
<string
, any
> | T
[]
Takes an array or object and a function, and runs the function on each element
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| xs
| string
| any
[] | Record
<string
, any
> |
| fn
| (a
: any
, b
: string
| number
) => T
|
Returns
Record
<string
, any
> | T
[]
Example
each([ 'a', 'b', 'c' ], id) // => 'a'
Defined in
elem
▸ elem<T
>(el
, ls
): boolean
Check if a string or array contains an element
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| el
| string
& T
|
| ls
| string
| T
[] |
Returns
boolean
Example
elem('a', 'asdf') // => true
elem('a', 'asdf'.split('')) // => true
Defined in
escapeForRegex
▸ escapeForRegex(s?
): string
Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| s
| string
| ''
|
Returns
string
Example
escapeForRegex('foo') // => foo
escapeForRegex('1 \\ {} []|') // => '1 \\\\ \{\} \\[\\]\\|'
Defined in
execute
▸ execute(cmd
): void
Like a standalone npm run
that obeys npm bin
Parameters
| Name | Type |
| :------ | :------ |
| cmd
| string
|
Returns
void
Example
execute('standard-format -w')
Defined in
fileExists
▸ fileExists(filePath
): Promise
<boolean
>
Returns bool based on if passed path exists
Parameters
| Name | Type |
| :------ | :------ |
| filePath
| string
|
Returns
Promise
<boolean
>
Example
await fileExists('./foo') // => Promise<true>
Defined in
filter
▸ filter<T
>(fn
, list
): T
[] | Record
<string
, T
>
filter
for array and object
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| fn
| (x
: T
, y
: string
| number
) => boolean
|
| list
| string
| AnyMap
| T
[] |
Returns
T
[] | Record
<string
, T
>
Example
filter(id, [ 1, 2 ]) // => [ 1, 2 ]
filter(lessThanThree, [ 1, 2, 3, 4 ]) // => [ 1, 2 ]
filter(lessThanThree, { a: 1, b: 4 }) // => { a: 1 }
Defined in
findIndices
▸ findIndices(el
, arr
): number
[]
Find all indices of an item in an array
Parameters
| Name | Type |
| :------ | :------ |
| el
| any
|
| arr
| any
[] |
Returns
number
[]
Example
findIndices(1, [ 1, 2, 1 ]) // => [ 0, 2 ]
Defined in
findPort
▸ findPort(port
, cb
): void
Find next open port
Parameters
| Name | Type |
| :------ | :------ |
| port
| number
|
| cb
| (x
: null
| Error
, y?
: number
) => void
|
Returns
void
Example
findPort(8000, (err, port) => console.log(`${port} is open`))
Defined in
flattenAndUniq
▸ flattenAndUniq<T
>(arr
): T
[]
Recursively flatten arrays then uniq what's left
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| T
[] |
Returns
T
[]
Example
flattenAndUniq([ 1, 2, 3, [ 1, 2, 3 ]]) // => [ 1, 2, 3 ]
Defined in
flip
▸ flip(f
): (...args
: any
[]) => any
Flips order of received arguments and calls f.
Parameters
| Name | Type |
| :------ | :------ |
| f
| (...xs
: any
[]) => any
|
Returns
fn
▸ (...args
): any
Parameters
| Name | Type |
| :------ | :------ |
| ...args
| any
[] |
Returns
any
Example
const minus = (a, b) => a - b
minus(2, 1) // => 1
flip(minus)(2, 1) // => -1
Defined in
fold
▸ fold<T
>(f
, a
): T
Applies f to first two items of list, then to next, etc.
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| f
| (x
: T
, y
: T
) => T
|
| a
| T
[] |
Returns
T
Example
foldl1(increment, [ 1, 1, 1 ]) // => 3
Defined in
getFreeDisk
▸ getFreeDisk(): number
Get free disk space
Returns
number
Example
getFreeDisk()
Defined in
getFreeMemory
▸ getFreeMemory(): number
Get free memory
Returns
number
Example
getFreeMemory()
Defined in
getGlobal
▸ getGlobal(): undefined
| typeof globalThis
Gets the global for your current context.
Returns
undefined
| typeof globalThis
Example
getGlobal() // => window, global, whatever
Defined in
getHashFromDate
▸ getHashFromDate(): string
Returns a hash based on current timestamp
Returns
string
Example
getHashFromDate()
Defined in
getHashFromSystem
▸ getHashFromSystem(): string
Get a md5 hash based on hostname, process.ppid, and date
Returns
string
Example
getHashFromSystem()
Defined in
getKeyByValue
▸ getKeyByValue(value
, object
): undefined
| string
Get the key for a value
Parameters
| Name | Type |
| :------ | :------ |
| value
| any
|
| object
| AnyMap
|
Returns
undefined
| string
Example
getKeyByValue('bar', { foo: 'bar' }) // => 'foo'
Defined in
getLoadAverage
▸ getLoadAverage(): number
Get load average
Returns
number
Example
getLoadAverage()
Defined in
getMemoryUsage
▸ getMemoryUsage(): number
Get memory usage
Returns
number
Example
getMemoryUsage()
Defined in
getOrdinal
▸ getOrdinal(n
): string
Adds ordinal onto integer
Works up to 999
Parameters
| Name | Type |
| :------ | :------ |
| n
| number
|
Returns
string
Example
getOrdinal(1) // => '1st'
Defined in
getProjectRoot
▸ getProjectRoot(): string
Get project root
Returns
string
Example
getProjectRoot() // /path/to/project
Defined in
getRandomString
▸ getRandomString(n?
): string
Returns random string of n length (defaults to 8)
Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| n
| number
| 8
|
Returns
string
Example
getRandomString()
getRandomString(32)
Defined in
getRegexFlags
▸ getRegexFlags(r
): string
[]
Returns the flags for a given regular expression
Parameters
| Name | Type |
| :------ | :------ |
| r
| RegExp
|
Returns
string
[]
Example
getRegexFlags(/foo/ig) // => [ 'g', 'i' ]
Defined in
getStdin
▸ getStdin(f
): void
Get stdin and do something with it.
Parameters
| Name | Type |
| :------ | :------ |
| f
| (a
: string
) => void
|
Returns
void
Example
getStdin((str) => {
console.log(str.split(''))
})
Defined in
getTerminalColumns
▸ getTerminalColumns(): number
Get columns of current terminal
Returns
number
Example
getTerminalColumns()
Defined in
getTerminalRows
▸ getTerminalRows(): number
Get current terminal rows
Returns
number
Example
getTerminalRows()
Defined in
getTerminalSize
▸ getTerminalSize(): Size
Returns size of the current terminal
Returns
Example
getTerminalSize() // => { columns: number, rows: number }
Defined in
getUserHome
▸ getUserHome(): string
Get current user's home directory
Returns
string
Example
getUserHome() // => /home/z
Defined in
getUserShell
▸ getUserShell(): string
Get the current user's shell, or an empty string on shell-less platforms
Returns
string
Example
getUserShell()
Defined in
greater
▸ greater(a
, b
): number
Get the greater of two numbers
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
Returns
number
Example
greater(1, 2) // => 2
Defined in
groupBy
▸ groupBy(p
): (a
: any
[]) => AnyMap
Collect an an array of objects by string key
Parameters
| Name | Type |
| :------ | :------ |
| p
| string
|
Returns
fn
▸ (a
): AnyMap
Parameters
| Name | Type |
| :------ | :------ |
| a
| any
[] |
Returns
Example
const data = [ { foo: 'a', bar: 'baz' }, { foo: 'b', bar: 'quux' }, { foo: 'a', bar: 'whatever' } ]
groupBy('foo')(data) // => { a: { foo: 'a', bar: 'whatever' }, b: { foo: 'b', bar: 'quux' } }
Defined in
gt
▸ gt(a
, b
): boolean
Returns true if first param is greater than second param
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
Returns
boolean
Example
gt(2, 1) // => true
gt(1, 2) // => false
Defined in
gte
▸ gte(a
, b
): boolean
Returns true if first param is greater than or equal to second param
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
Returns
boolean
Example
gte(2, 2) // => true
gte(2, 1) // => true
gte(2, 3) // => false
Defined in
has
▸ has(p
, o
): boolean
See if an object has a property
Parameters
| Name | Type |
| :------ | :------ |
| p
| string
|
| o
| AnyMap
|
Returns
boolean
Example
has('a' { b: 'c' }) // => false
Defined in
hasColor
▸ hasColor(): boolean
Returns true if the current terminal supports color
Returns
boolean
Example
hasColor()
Defined in
hasDuplicate
▸ hasDuplicate<T
>(arr
): boolean
Returns true if an array has any duplicate elements
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| T
[] |
Returns
boolean
Example
hasDuplicate([ 1, 1, 2 ]) // => true
Defined in
head
▸ head<T
>(arr
): T
First element
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| T
[] |
Returns
T
Example
head([ 1, 2, 3 ]) // => 1
Defined in
id
▸ id<A
>(a
): A
id
Type parameters
| Name |
| :------ |
| A
|
Parameters
| Name | Type |
| :------ | :------ |
| a
| A
|
Returns
A
Example
id(1) // => 1
id() // => undefined
Defined in
init
▸ init(arr
): any
[]
Returns all but the last item of an array
Parameters
| Name | Type |
| :------ | :------ |
| arr
| any
[] |
Returns
any
[]
Example
init([ 1, 2, 3 ]) // => [ 1, 2 ]
Defined in
initials
▸ initials(str
): string
Trims a string to just caps
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
initials('Zac Anger') // => 'ZA'
Defined in
intersection
▸ intersection<T
>(xs
, ys
): T
[]
Get the intersection of two arrays
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| xs
| T
[] |
| ys
| T
[] |
Returns
T
[]
Example
intersection([ 1, 2 ], []) // => []
intersection([ 1, 2, 3 ], [1, 2]) // => [ 1, 2 ]
Defined in
is
▸ is(t
, val
): boolean
Returns true if the value is of the type
Parameters
| Name | Type |
| :------ | :------ |
| t
| string
|
| val
| any
|
Returns
boolean
Example
is('number', 2) // => true
Defined in
isArrayLike
▸ isArrayLike(v
): boolean
Returns true if the passed value is array-like
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isArrayLike({}) // => false
isArrayLike([ 1, 2 ]) // => true
Defined in
isBetween
▸ isBetween(a
, b
, mid
): boolean
Returns true if the last parameter is before the first and second parameters
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
| mid
| number
|
Returns
boolean
Example
isBetween(1, 3, 2) // => true
isBetween(2, 1, 2) // => false
Defined in
isBoolean
▸ isBoolean(v
): boolean
Returns true if the value is a boolean
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isBoolean(true) // => true
Defined in
isClass
▸ isClass(fn
): boolean
Returns true if passed fn is an ES2015 class
Parameters
| Name | Type |
| :------ | :------ |
| fn
| () => any
|
Returns
boolean
Example
isClass(noop) // => false
Defined in
isDate
▸ isDate(v
): boolean
Returns true if the value is a date
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isDate(new Date()) // => true
Defined in
isDefined
▸ isDefined(v
): boolean
Returns true if the value is defined
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isDefined(null) // => true
Defined in
isDirectory
▸ isDirectory(filePath
): Promise
<boolean
>
Returns true if the path is a directory
Parameters
| Name | Type |
| :------ | :------ |
| filePath
| string
|
Returns
Promise
<boolean
>
Example
await isDirectory('.') // => true
await isDirectory('./fake-path') // => false
Defined in
isEmpty
▸ isEmpty(v
): boolean
Returns true if the value is empty
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isEmpty('') // => true
isEmpty({}) // => true
isEmpty([]) // => true
isEmpty(null) // => true
Defined in
isError
▸ isError(a
): boolean
Returns true if value is an error
Parameters
| Name | Type |
| :------ | :------ |
| a
| any
|
Returns
boolean
Example
isError(new Error()) // => true
Defined in
isEven
▸ isEven(n
): boolean
Returns true if the number is even
Parameters
| Name | Type |
| :------ | :------ |
| n
| number
|
Returns
boolean
Example
isEven(2) // => true
Defined in
isFile
▸ isFile(filePath
): Promise
<boolean
>
Returns true if the path is a file
Parameters
| Name | Type |
| :------ | :------ |
| filePath
| string
|
Returns
Promise
<boolean
>
Example
isFile('./README.md') // => true
isFile('.') // => false
Defined in
isFloat
▸ isFloat(n
): boolean
Returns true if the number is a float
Parameters
| Name | Type |
| :------ | :------ |
| n
| number
|
Returns
boolean
Example
isFloat(2) // => false
isFloat(2.2) // => true
Defined in
isFunction
▸ isFunction(v
): boolean
Returns true if the value is a function
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
const noop = () => {}
isFunction(2) // => false
isFunction(noop) // => true
Defined in
isGenerator
▸ isGenerator(v
): boolean
Returns true if passed val is a generator
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isGenerator(2) // => false
Defined in
isGeneratorFunction
▸ isGeneratorFunction(v
): boolean
Returns true if val is a generator function
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isGeneratorFunction(2) // => false
Defined in
isInstalled
▸ isInstalled(pkgName
): boolean
Returns true if the passed node_module name is installed
Parameters
| Name | Type |
| :------ | :------ |
| pkgName
| string
|
Returns
boolean
Example
isInstalled('@patrtorg/minima-exercitationem-minus') // => true
Defined in
isInteger
▸ isInteger(v
): boolean
Returns true if the value is an integer
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isInteger(2) // => true
isInteger(1.1) // => false
Defined in
isJson
▸ isJson(str
): boolean
Returns true if the string is valid JSON
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
boolean
Example
isJson(JSON.stringify({ a: 'b' })) // => true
Defined in
isMap
▸ isMap(v
): boolean
Returns true if value is a map
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isMap(new Map()) // => true
Defined in
isNode
▸ isNode(): boolean
Returns true if code is in Node
Returns
boolean
Example
isNode()
Defined in
isNull
▸ isNull(v
): boolean
Returns true if the value is null
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isNull(null) // => true
Defined in
isNullOrUndefined
▸ isNullOrUndefined(v
): boolean
Returns true if the value is null or undefined
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isNullOrUndefined(null) // => true
Defined in
isNumber
▸ isNumber(v
): boolean
Returns true if the value is a number and is not NaN
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isNumber(2) // => true
isNumber(NaN) // => false
Defined in
isObject
▸ isObject(v
): boolean
Returns true if the value is an object
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isObject('asdf') // => false
Defined in
isOdd
▸ isOdd(n
): boolean
Returns true if the number is odd
Parameters
| Name | Type |
| :------ | :------ |
| n
| number
|
Returns
boolean
Example
isOdd(1) // => true
Defined in
isPow2
▸ isPow2(n
): boolean
Returns true if number is a power of two
Parameters
| Name | Type |
| :------ | :------ |
| n
| number
|
Returns
boolean
Example
isPow2(16) // => true
Defined in
isPrimitive
▸ isPrimitive(v
): boolean
Returns true if value is a primitive
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isPrimitive(1) // => true
Defined in
isPromise
▸ isPromise(a
): boolean
Returns true if value is a promise
Parameters
| Name | Type |
| :------ | :------ |
| a
| any
|
Returns
boolean
Example
isPromise(Promise.resolve())
Defined in
isRegExp
▸ isRegExp(v
): boolean
Returns true if value is a RegExp
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isRegExp(/a/) // => true
Defined in
isRoot
▸ isRoot(): boolean
Check if current process is running as root.
Returns
boolean
Example
isRoot() // => true
Defined in
isSemver
▸ isSemver(v
): boolean
Returns true if the provided string is a valid semantic version
Parameters
| Name | Type |
| :------ | :------ |
| v
| string
|
Returns
boolean
Example
isSemver("0.0.0") // => true
isSemver("0.") // => false
Defined in
isSet
▸ isSet(v
): boolean
Returns true if value is a set
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isSet(new Set()) // => true
Defined in
isString
▸ isString(v
): boolean
Returns true if value is a string
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isString('a') // => true
Defined in
isSymLink
▸ isSymLink(filePath
): Promise
<boolean
>
Returns true if path is a symlink
Parameters
| Name | Type |
| :------ | :------ |
| filePath
| string
|
Returns
Promise
<boolean
>
Example
isSymLink('.') // => false
Defined in
isSymbol
▸ isSymbol(a
): boolean
Returns true if value is a symbol
Parameters
| Name | Type |
| :------ | :------ |
| a
| any
|
Returns
boolean
Example
isSymbol(Symbol.for('foo')) // => true
Defined in
isUndefined
▸ isUndefined(v
): boolean
Returns true if value is undefined
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
boolean
Example
isUndefined(undefined) // => true
Defined in
isValidDate
▸ isValidDate(d
): boolean
Returns true if the passed object is a valid Date
Parameters
| Name | Type |
| :------ | :------ |
| d
| Date
|
Returns
boolean
Example
isValidDate('1234') // => false
Defined in
keep
▸ keep(x
): R
Returns an array or object with all falsey values removed
Parameters
| Name | Type |
| :------ | :------ |
| x
| R
|
Returns
Example
keep([ 'a', null, '', 2]) // => [ 'a', 2 ]
keep({ a: '', b: null, c: 2 }) // => { c: 2 }
Defined in
last
▸ last<A
>(arr
): A
Returns the last element of the array
Type parameters
| Name |
| :------ |
| A
|
Parameters
| Name | Type |
| :------ | :------ |
| arr
| A
[] |
Returns
A
Example
last([ 1, 2, 3 ]) // => 3
Defined in
len
▸ len(val
): number
Get length of element
Works for array, object, string, set, map, and function
Parameters
| Name | Type |
| :------ | :------ |
| val
| any
|
Returns
number
Example
len('foo') // => 3
len([ 1, 2 ]) => 2
len((a, b) => a + b) // => 2
Defined in
lesser
▸ lesser(a
, b
): number
Returns the lesser of two numbers
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
Returns
number
Example
lesser(1, 2) // => 1
Defined in
lightenOrDarken
▸ lightenOrDarken(col
, amt
): string
Lighten or darken a color
Parameters
| Name | Type |
| :------ | :------ |
| col
| string
|
| amt
| number
|
Returns
string
Example
// lighten
const newCol = lightenOrDarken('#F06D06', 20)
// darken
const newCol = lightenOrDarken('#F06D06', -20)
Defined in
lines
▸ lines(str
): string
[]
Split a string on lines
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
[]
Example
lines('foo\nbar') // => [ 'foo', 'bar' ]
Defined in
lispCaseToCamelCase
▸ lispCaseToCamelCase(str
): string
From lisp-case to camelCase
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
lispCaseToCamelCase('foo-bar') // => 'fooBar'
Defined in
lispCaseToPascalCase
▸ lispCaseToPascalCase(str
): string
From lisp-case to PascalCase
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
lispCaseToPascalCase('foo-bar') // => 'FooBar'
Defined in
lispCaseToSnakeCase
▸ lispCaseToSnakeCase(str
): string
From lisp-case to snake_case
Parameters
| Name | Type |
| :------ | :------ |
| str
| string
|
Returns
string
Example
lispCaseToSnakeCase('foo-bar') // => 'foo_bar'
Defined in
lt
▸ lt(a
, b
): boolean
Returns true if first param is less than second param
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
Returns
boolean
Example
lt(2, 1) // => false
Defined in
lte
▸ lte(a
, b
): boolean
Returns true if first param is less than or equal to second param
Parameters
| Name | Type |
| :------ | :------ |
| a
| number
|
| b
| number
|
Returns
boolean
Example
lte(2, 1) // => false
lte(1, 1) // => true
Defined in
mapObject
▸ mapObject(f
, o
, ctx?
): AnyMap
Map for objects
Parameters
| Name | Type |
| :------ | :------ |
| f
| (a
: any
, b
: string
, c
: any
) => any
|
| o
| AnyMap
|
| ctx
| any
|
Returns
Example
const f = (a) => a + ' world'
const d = { a: 'hello', b: 'sup' }
mapObject(f, d) // => { a: 'hello world', b: 'sup world' }
Defined in
memoize
▸ memoize(fn
): any
A simple memoizing util
Parameters
| Name | Type |
| :------ | :------ |
| fn
| any
|
Returns
any
Example
memoize((a) => a) // => [Function]
memoize((a) => a)(1) // => 1
Defined in
mzero
▸ mzero(v?
): any
Get monadic empty/zero value for a type
Parameters
| Name | Type |
| :------ | :------ |
| v?
| any
|
Returns
any
Example
mzero(1) // =>
mzero([1]) // => []
Defined in
nco
▸ nco<A
, B
>(variable
, defaultValue
): A
| B
nco
Type parameters
| Name |
| :------ |
| A
|
| B
|
Parameters
| Name | Type |
| :------ | :------ |
| variable
| A
|
| defaultValue
| B
|
Returns
A
| B
Example
nco(null, 1) // => 1
nco(1, 2) // => 1
Defined in
noop
▸ noop(): void
noop
Returns
void
Example
noop() // => undefined
Defined in
notElem
▸ notElem<T
>(el
, ls
): boolean
The opposite of elem
Returns true if the element is not in the string or array
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| el
| T
& string
|
| ls
| string
| T
[] |
Returns
boolean
Example
notElem('a', 'asdf') // => false
notElem('b', 'asdf') // => true
Defined in
objectToString
▸ objectToString(v
): string
toString
Parameters
| Name | Type |
| :------ | :------ |
| v
| any
|
Returns
string
Example
objectToString({}) // => '[object Object]'
Defined in
once
▸ once<U
>(fn
): (...args
: U
[]) => U
Only calls fn once; subsequent calls just return first val
Type parameters
| Name |
| :------ |
| U
|
Parameters
| Name | Type |
| :------ | :------ |
| fn
| <T>(...args
: T
[]) => T
|
Returns
fn
▸ (...args
): U
Parameters
| Name | Type |
| :------ | :------ |
| ...args
| U
[] |
Returns
U
Example
const o = once(id)
o(1) // => 1
o() // => 1
o(2) // => 1
Defined in
open
▸ open(args
, opts
, cb
): void
Opens things. Works on Linux, Mac, and Windows
Parameters
| Name | Type |
| :------ | :------ |
| args
| string
|
| opts
| AnyMap
|
| cb
| Cb
|
Returns
void
Example
open('http://zacanger.com')
Defined in
pair
▸ pair<A
, B
>(first
, second
): [A
, B
]
Make a pair out of any two values
Type parameters
| Name |
| :------ |
| A
|
| B
|
Parameters
| Name | Type |
| :------ | :------ |
| first
| A
|
| second
| B
|
Returns
[A
, B
]
Example
pair('a', 'b') // => [ 'a', 'b' ]
Defined in
pairWith
▸ pairWith<T
>(f
, a
, b
): T
[]
Returns an array made by calling f on a and b.
Type parameters
| Name |
| :------ |
| T
|
Parameters
| Name | Type |
| :------ | :------ |
| f
| (x
: T
) => T
|
| `a