Opinionated javascript utilities used at Konnektid.
They include functional utilities, validation utilities and more.
The goals of this project is to enhance reusability, promote functional programming and simplicity.
Generic purpose utilities
import { slugify } from "konnektid-js-utils";
// or
import slugify from "konnektid-js-utils/dist/slugify";
It converts strings to slugs that can be use in urls.
These utilities functions are used to check if values are of a certain types.
Returns true id the value is given. A not given value is undefined, null or empty string.
Returns true if the value is a string.
Returns true if the value is valid email string.
Returns true if the value is valid phone number.
Returns true if the value is a boolean.
Returns true if the value can be used as price. If the value given is a string that represents a number, false is returned anyway.
Returns true if the value is a geo point representing coordinates. A geopoint is an object with properties:
- lat: latitude of the coordinates that should be a number between -90 and 90
- lng: longitude of the coordinates that should be a number between -180 and 180
These utilities are used in Konnektid to handle values generated by draft-js
Gets a string and tried to parse is as a raw object with JSON.parse
. If the parse fails, returns the value as it is.
Takes a string and tries to parse it in a ContentState.
If the string does not represent a draft-js
raw object, than the string itself is used to create a ContentState by using createFromText factory from draft-js
.
Returns true if the ContentState does not contains checks.
This utilities also trims the text, so strings with only empty characters are not considered as not empty.