UNPKG

2.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isSymbol = exports.isEmpty = exports.isNil = exports.isConstructor = exports.isNumber = exports.isString = exports.isFunction = exports.stripEndSlash = exports.normalizePath = exports.addLeadingSlash = exports.isPlainObject = exports.isObject = exports.isUndefined = void 0;
4/* eslint-disable @typescript-eslint/no-use-before-define */
5const isUndefined = (obj) => typeof obj === 'undefined';
6exports.isUndefined = isUndefined;
7const isObject = (fn) => !(0, exports.isNil)(fn) && typeof fn === 'object';
8exports.isObject = isObject;
9const isPlainObject = (fn) => {
10 if (!(0, exports.isObject)(fn)) {
11 return false;
12 }
13 const proto = Object.getPrototypeOf(fn);
14 if (proto === null) {
15 return true;
16 }
17 const ctor = Object.prototype.hasOwnProperty.call(proto, 'constructor') &&
18 proto.constructor;
19 return (typeof ctor === 'function' &&
20 ctor instanceof ctor &&
21 Function.prototype.toString.call(ctor) ===
22 Function.prototype.toString.call(Object));
23};
24exports.isPlainObject = isPlainObject;
25const addLeadingSlash = (path) => path && typeof path === 'string'
26 ? path.charAt(0) !== '/'
27 ? '/' + path
28 : path
29 : '';
30exports.addLeadingSlash = addLeadingSlash;
31const normalizePath = (path) => path
32 ? path.startsWith('/')
33 ? ('/' + path.replace(/\/+$/, '')).replace(/\/+/g, '/')
34 : '/' + path.replace(/\/+$/, '')
35 : '/';
36exports.normalizePath = normalizePath;
37const stripEndSlash = (path) => path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path;
38exports.stripEndSlash = stripEndSlash;
39const isFunction = (val) => typeof val === 'function';
40exports.isFunction = isFunction;
41const isString = (val) => typeof val === 'string';
42exports.isString = isString;
43const isNumber = (val) => typeof val === 'number';
44exports.isNumber = isNumber;
45const isConstructor = (val) => val === 'constructor';
46exports.isConstructor = isConstructor;
47const isNil = (val) => (0, exports.isUndefined)(val) || val === null;
48exports.isNil = isNil;
49const isEmpty = (array) => !(array && array.length > 0);
50exports.isEmpty = isEmpty;
51const isSymbol = (val) => typeof val === 'symbol';
52exports.isSymbol = isSymbol;