Skip to content

Several javascript utilities used throughout Konnektid

Notifications You must be signed in to change notification settings

Konnektid/konnektid-js-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javascript utilities we use at Konnektid

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.

Utils

Generic purpose utilities

slugify

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.

Types

These utilities functions are used to check if values are of a certain types.

isGiven(value: any): Boolean

Returns true id the value is given. A not given value is undefined, null or empty string.

isString(value: any): Boolean

Returns true if the value is a string.

isEmail(value: String): Boolean

Returns true if the value is valid email string.

isPhoneNumber(value: String): Boolean

Returns true if the value is valid phone number.

isBoolean(value: any): Boolean

Returns true if the value is a boolean.

isPrice(value: any): 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.

isGeoPoint

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

Draft-js

These utilities are used in Konnektid to handle values generated by draft-js

parseRaw(value: String): Object | String

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.

parseContentState(value: String): ContentState

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.

isEmpty(value: String): Boolean

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.