exports.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. // src/exports.ts
  20. var exports_exports = {};
  21. __export(exports_exports, {
  22. isArray: () => isArray,
  23. isArrayOf: () => isArrayOf,
  24. isAsyncFunction: () => isAsyncFunction,
  25. isAsyncGeneratorFunction: () => isAsyncGeneratorFunction,
  26. isBigInt: () => isBigInt,
  27. isBoolean: () => isBoolean,
  28. isDate: () => isDate,
  29. isDefined: () => isDefined,
  30. isDomElement: () => isDomElement,
  31. isEmpty: () => isEmpty,
  32. isError: () => isError,
  33. isFunction: () => isFunction,
  34. isGenerator: () => isGenerator,
  35. isGeneratorFunction: () => isGeneratorFunction,
  36. isInstanceOf: () => isInstanceOf,
  37. isIterable: () => isIterable,
  38. isMap: () => isMap,
  39. isNan: () => isNan,
  40. isNull: () => isNull,
  41. isNullOrUndefined: () => isNullOrUndefined,
  42. isNumber: () => isNumber,
  43. isNumericString: () => isNumericString,
  44. isObject: () => isObject,
  45. isOneOf: () => isOneOf,
  46. isPlainFunction: () => isPlainFunction,
  47. isPlainObject: () => isPlainObject,
  48. isPrimitive: () => isPrimitive,
  49. isPromise: () => isPromise,
  50. isPropertyOf: () => isPropertyOf,
  51. isRegexp: () => isRegexp,
  52. isSet: () => isSet,
  53. isString: () => isString,
  54. isSymbol: () => isSymbol,
  55. isUndefined: () => isUndefined,
  56. isWeakMap: () => isWeakMap,
  57. isWeakSet: () => isWeakSet
  58. });
  59. module.exports = __toCommonJS(exports_exports);
  60. // src/helpers.ts
  61. var objectTypes = [
  62. "Array",
  63. "ArrayBuffer",
  64. "AsyncFunction",
  65. "AsyncGenerator",
  66. "AsyncGeneratorFunction",
  67. "Date",
  68. "Error",
  69. "Function",
  70. "Generator",
  71. "GeneratorFunction",
  72. "HTMLElement",
  73. "Map",
  74. "Object",
  75. "Promise",
  76. "RegExp",
  77. "Set",
  78. "WeakMap",
  79. "WeakSet"
  80. ];
  81. var primitiveTypes = [
  82. "bigint",
  83. "boolean",
  84. "null",
  85. "number",
  86. "string",
  87. "symbol",
  88. "undefined"
  89. ];
  90. function getObjectType(value) {
  91. const objectTypeName = Object.prototype.toString.call(value).slice(8, -1);
  92. if (/HTML\w+Element/.test(objectTypeName)) {
  93. return "HTMLElement";
  94. }
  95. if (isObjectType(objectTypeName)) {
  96. return objectTypeName;
  97. }
  98. return void 0;
  99. }
  100. function isObjectOfType(type) {
  101. return (value) => getObjectType(value) === type;
  102. }
  103. function isObjectType(name) {
  104. return objectTypes.includes(name);
  105. }
  106. function isOfType(type) {
  107. return (value) => typeof value === type;
  108. }
  109. function isPrimitiveType(name) {
  110. return primitiveTypes.includes(name);
  111. }
  112. // src/index.ts
  113. var DOM_PROPERTIES_TO_CHECK = [
  114. "innerHTML",
  115. "ownerDocument",
  116. "style",
  117. "attributes",
  118. "nodeValue"
  119. ];
  120. function is(value) {
  121. if (value === null) {
  122. return "null";
  123. }
  124. switch (typeof value) {
  125. case "bigint":
  126. return "bigint";
  127. case "boolean":
  128. return "boolean";
  129. case "number":
  130. return "number";
  131. case "string":
  132. return "string";
  133. case "symbol":
  134. return "symbol";
  135. case "undefined":
  136. return "undefined";
  137. default:
  138. }
  139. if (is.array(value)) {
  140. return "Array";
  141. }
  142. if (is.plainFunction(value)) {
  143. return "Function";
  144. }
  145. const tagType = getObjectType(value);
  146. if (tagType) {
  147. return tagType;
  148. }
  149. return "Object";
  150. }
  151. is.array = Array.isArray;
  152. is.arrayOf = (target, predicate) => {
  153. if (!is.array(target) && !is.function(predicate)) {
  154. return false;
  155. }
  156. return target.every((d) => predicate(d));
  157. };
  158. is.asyncGeneratorFunction = (value) => getObjectType(value) === "AsyncGeneratorFunction";
  159. is.asyncFunction = isObjectOfType("AsyncFunction");
  160. is.bigint = isOfType("bigint");
  161. is.boolean = (value) => {
  162. return value === true || value === false;
  163. };
  164. is.date = isObjectOfType("Date");
  165. is.defined = (value) => !is.undefined(value);
  166. is.domElement = (value) => {
  167. return is.object(value) && !is.plainObject(value) && value.nodeType === 1 && is.string(value.nodeName) && DOM_PROPERTIES_TO_CHECK.every((property) => property in value);
  168. };
  169. is.empty = (value) => {
  170. return is.string(value) && value.length === 0 || is.array(value) && value.length === 0 || is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length === 0 || is.set(value) && value.size === 0 || is.map(value) && value.size === 0;
  171. };
  172. is.error = isObjectOfType("Error");
  173. is.function = isOfType("function");
  174. is.generator = (value) => {
  175. return is.iterable(value) && is.function(value.next) && is.function(value.throw);
  176. };
  177. is.generatorFunction = isObjectOfType("GeneratorFunction");
  178. is.instanceOf = (instance, class_) => {
  179. if (!instance || !class_) {
  180. return false;
  181. }
  182. return Object.getPrototypeOf(instance) === class_.prototype;
  183. };
  184. is.iterable = (value) => {
  185. return !is.nullOrUndefined(value) && is.function(value[Symbol.iterator]);
  186. };
  187. is.map = isObjectOfType("Map");
  188. is.nan = (value) => {
  189. return Number.isNaN(value);
  190. };
  191. is.null = (value) => {
  192. return value === null;
  193. };
  194. is.nullOrUndefined = (value) => {
  195. return is.null(value) || is.undefined(value);
  196. };
  197. is.number = (value) => {
  198. return isOfType("number")(value) && !is.nan(value);
  199. };
  200. is.numericString = (value) => {
  201. return is.string(value) && value.length > 0 && !Number.isNaN(Number(value));
  202. };
  203. is.object = (value) => {
  204. return !is.nullOrUndefined(value) && (is.function(value) || typeof value === "object");
  205. };
  206. is.oneOf = (target, value) => {
  207. if (!is.array(target)) {
  208. return false;
  209. }
  210. return target.indexOf(value) > -1;
  211. };
  212. is.plainFunction = isObjectOfType("Function");
  213. is.plainObject = (value) => {
  214. if (getObjectType(value) !== "Object") {
  215. return false;
  216. }
  217. const prototype = Object.getPrototypeOf(value);
  218. return prototype === null || prototype === Object.getPrototypeOf({});
  219. };
  220. is.primitive = (value) => is.null(value) || isPrimitiveType(typeof value);
  221. is.promise = isObjectOfType("Promise");
  222. is.propertyOf = (target, key, predicate) => {
  223. if (!is.object(target) || !key) {
  224. return false;
  225. }
  226. const value = target[key];
  227. if (is.function(predicate)) {
  228. return predicate(value);
  229. }
  230. return is.defined(value);
  231. };
  232. is.regexp = isObjectOfType("RegExp");
  233. is.set = isObjectOfType("Set");
  234. is.string = isOfType("string");
  235. is.symbol = isOfType("symbol");
  236. is.undefined = isOfType("undefined");
  237. is.weakMap = isObjectOfType("WeakMap");
  238. is.weakSet = isObjectOfType("WeakSet");
  239. var src_default = is;
  240. // src/exports.ts
  241. var isArray = src_default.array;
  242. var isArrayOf = src_default.arrayOf;
  243. var isAsyncGeneratorFunction = src_default.asyncGeneratorFunction;
  244. var isAsyncFunction = src_default.asyncFunction;
  245. var isBigInt = src_default.bigint;
  246. var isBoolean = src_default.boolean;
  247. var isDate = src_default.date;
  248. var isDefined = src_default.defined;
  249. var isDomElement = src_default.domElement;
  250. var isEmpty = src_default.empty;
  251. var isError = src_default.error;
  252. var isFunction = src_default.function;
  253. var isGenerator = src_default.generator;
  254. var isGeneratorFunction = src_default.generatorFunction;
  255. var isInstanceOf = src_default.instanceOf;
  256. var isIterable = src_default.iterable;
  257. var isMap = src_default.map;
  258. var isNan = src_default.nan;
  259. var isNull = src_default.null;
  260. var isNullOrUndefined = src_default.nullOrUndefined;
  261. var isNumber = src_default.number;
  262. var isNumericString = src_default.numericString;
  263. var isObject = src_default.object;
  264. var isOneOf = src_default.oneOf;
  265. var isPlainFunction = src_default.plainFunction;
  266. var isPlainObject = src_default.plainObject;
  267. var isPrimitive = src_default.primitive;
  268. var isPromise = src_default.promise;
  269. var isPropertyOf = src_default.propertyOf;
  270. var isRegexp = src_default.regexp;
  271. var isSet = src_default.set;
  272. var isString = src_default.string;
  273. var isSymbol = src_default.symbol;
  274. var isUndefined = src_default.undefined;
  275. var isWeakMap = src_default.weakMap;
  276. var isWeakSet = src_default.weakSet;
  277. // Annotate the CommonJS export names for ESM import in node:
  278. 0 && (module.exports = {
  279. isArray,
  280. isArrayOf,
  281. isAsyncFunction,
  282. isAsyncGeneratorFunction,
  283. isBigInt,
  284. isBoolean,
  285. isDate,
  286. isDefined,
  287. isDomElement,
  288. isEmpty,
  289. isError,
  290. isFunction,
  291. isGenerator,
  292. isGeneratorFunction,
  293. isInstanceOf,
  294. isIterable,
  295. isMap,
  296. isNan,
  297. isNull,
  298. isNullOrUndefined,
  299. isNumber,
  300. isNumericString,
  301. isObject,
  302. isOneOf,
  303. isPlainFunction,
  304. isPlainObject,
  305. isPrimitive,
  306. isPromise,
  307. isPropertyOf,
  308. isRegexp,
  309. isSet,
  310. isString,
  311. isSymbol,
  312. isUndefined,
  313. isWeakMap,
  314. isWeakSet
  315. });
  316. //# sourceMappingURL=exports.js.map