@evokedset/utils
v0.0.5
Published
Utility Library for EvokedSet
Downloads
6
Readme
@evokedset/utils
General JavaScript we don't care to write again. Written in TypeScript and / or ES6. Because you have to start somewhere. Not very thoughtfully organized into vaguely related files.
Methods
Types and Shapes
getType(input, restricted=false)
⇒ string
Returns name of type of input. A bit more versatile than typeof in that it will also recognize and return the expected result for any custom type.
| Param | Type | Required | Default value |
| ---------- | --------- | -------- | ------------- |
| input | *
| Yes | |
| restricted | boolean
| No | false
|
getShape(input, depth=1)
⇒ string
Returns the 'shape' of the object in the style of react proptypes. Handy for declaring very precise objects.
| Param | Type | Required | Default value |
| ----- | -------- | -------- | ------------- |
| input | object
| Yes | |
| depth | number
| No | 1
|
Strings and lists
humanizeList(list, config)
⇒ string
Transforms ['Tom', 'Dick', 'Harry']
into Tom, Dick and Harry
. Takes an array of strings and an optional config object. Also exported as thingCommaThingAndThing
for obvious reasons.
| Param | Type | Required | Default value |
| ------ | -------- | -------- | --------------------------------------------- |
| list | array
| Yes | |
| config | object
| No | { oxford: false, and: 'and', andThen: '.' }
|
Config object:
| Param | Type | Default | Explanation |
| ------ | -------- | -------- | -------- |
| oxford | boolean
| false
| Use oxford comma? |
| and | string
| and
| Tom, Dick and
Harry. |
| andThen | string
| .
| Tom, Dick and Harry.
|
Dates
isDateInRange(checkDate, startDate, endDate)
=> boolean
Is checkDate
after startDate
and before endDate
?
| Param | Type | required |
| --------- | -------------------- | -------- |
| checkDate | Date
* | true |
| startDate | Date
* | true |
| endDate | Date
* | true |
isDateBeforeDate(firstDate, secondDate)
=> boolean
Is firstDate
before secondDate
?
| Param | Type | required |
| ---------- | -------------------- | -------- |
| firstDate | Date
* | true |
| secondDate | Date
* | true |
* will accept any value castable to date, such as certain formats of numbers and strings.