0.0.5 • Published 5 years ago

@evokedset/utils v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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

ParamTypeRequiredDefault value
input*Yes
restrictedbooleanNofalse

getShape(input, depth=1)string

Returns the 'shape' of the object in the style of react proptypes. Handy for declaring very precise objects.

ParamTypeRequiredDefault value
inputobjectYes
depthnumberNo1

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.

ParamTypeRequiredDefault value
listarrayYes
configobjectNo{ 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 Typerequired
checkDateDate *true
startDateDate *true
endDateDate *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.

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago