strings
#
Installation#
API#
capitalizeReturns the given string with it's first character uppercased
#
pluralizePluralize is a higher-order function useful for making pluralization helpers. Given a singular and plural form of a word, you get a fn that takes in the object count and returns a string with the count and the correct singular/plural form.
#
formatPhoneNumberformatPhoneNumber takes in a phone number of unknown format returns a US standard formatting
#
formatUsCurrencyformatUsCurrency takes in a number and formats it as US currency, optionally hiding the cents.
NOTE: If using hideCents, it's up to you to round/ceil/floor the number as needed before passing it to the fn.
#
safeJsonParsesafeJsonParse takes in a string (hopefully serialized JSON!) and attempts to parse it. If parsing fails, it will return the optional fallback or undefined.
#
safeJoin (and friends)safeJoin is a higher-order function to make joining functions that will clean up it's input. Given variadic unknown arguments, it will remove any falsey values, convert numbers to strings, trim each component and join with the given delimiter. There are some pre-built safeJoin fns included, (safeJoinWithSpace, safeJoinWithComma, safeJoinWithEnDash, safeJoinWithEmDash)
#
makeQueryStringGiven an object of key/values, returns a properly encoded querystring for appending to a URL after removing any falsey/missing values. Values as arrays will be appended multiple times. If you want to add an array as comma separated, you will need to pass it as a string for the value.
#
makeUrlWhen constructing URLs, makeUrl
will help with token replacement, querystring parameters, and can
optionally control trailing slashes.
When given a url with tokens, makeUrl
will type check the tokens in the given url. This provides
autocompletion of tokens and ensures that values for all tokens are provided.
makeUrl has several options available,
- Control over trailing slashes in your URLS.
- "ignore" will leave slash as-is (default)
- "ensure" will ensure urls always end with a slash
- "remove" will ensure urls never end with a slash
- Manage absolute url creation, as well as the origin and protocol
- Choose Dynamic URL pathname parameter type.
express
uses:userId
style params (default)nextjs
uses[userId]
style params
#
createMakeUrlConstructs a custom version of makeUrl
with default options. This makes it easy to add trailing
slashes to every link on your site as well as creating a second instance that is used for creating
absolute URLs. All options can be overriden manually during use by passing as the 4th argument.