Files
Exponent GitHub Bot e3f6a67ce5 Initial commit
fbshipit-source-id: 04f171ad7fc354fbc437cd07abdee445323d9a0f
2018-07-17 18:51:11 +00:00

50 lines
1.4 KiB
JavaScript

import slugifyLib from 'slugify';
var URL_REGEX = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/;
const appendZero = i => {
if (i < 10) {
i = `0${i}`;
}
return i;
};
// NOTE(jim): Source: https://gist.github.com/mathewbyrne/1280286
export const createSlug = text => {
const a = 'æøåàáäâèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;';
const b = 'aoaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------';
const p = new RegExp(a.split('').join('|'), 'g');
return text
.toString()
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special chars
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
};
export const formatTime = dateString => new Date(dateString).toLocaleTimeString('en-US');
export const formatTimeMilitary = dateString => {
const date = new Date(dateString);
const h = appendZero(date.getHours());
const m = appendZero(date.getMinutes());
return `${h}:${m}`;
};
export const isEmptyOrNull = text => {
return !text || !text.trim();
};
export const slugify = string => {
return slugifyLib(string, {
lower: true,
});
};