mirror of
https://github.com/expo/dev-tools.git
synced 2026-11-14 09:58:10 -10:00
50 lines
1.4 KiB
JavaScript
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,
|
|
});
|
|
};
|