59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.PrimitivePrototype = exports.IterResult = void 0;
|
|
exports.isObject = isObject;
|
|
exports.isPlainObject = isPlainObject;
|
|
exports.isFunction = isFunction;
|
|
exports.isIterable = isIterable;
|
|
exports.isString = isString;
|
|
exports.isNumber = isNumber;
|
|
exports.Null = Null;
|
|
exports.type = type;
|
|
function isObject(value) {
|
|
return typeof value === 'object' && !Array.isArray(value);
|
|
}
|
|
function isPlainObject(value) {
|
|
return Object.getPrototypeOf(value) === Object.prototype;
|
|
}
|
|
function isFunction(value) {
|
|
return value != null && typeof value === 'function';
|
|
}
|
|
function isIterable(value) {
|
|
return isFunction(value[Symbol.iterator]);
|
|
}
|
|
function isString(value) {
|
|
return typeof value === 'string';
|
|
}
|
|
function isNumber(value) {
|
|
return !isNaN(value);
|
|
}
|
|
class IterResult {
|
|
static Next(value) {
|
|
return { done: false, value };
|
|
}
|
|
static Done() {
|
|
return { done: true, value: undefined };
|
|
}
|
|
}
|
|
exports.IterResult = IterResult;
|
|
function Null(...args) {
|
|
return null;
|
|
}
|
|
exports.PrimitivePrototype = Object.freeze({
|
|
undefined: Null,
|
|
boolean: Boolean,
|
|
number: Number,
|
|
bigint: BigInt,
|
|
string: String,
|
|
symbol: Symbol,
|
|
object: Object,
|
|
function: Function
|
|
});
|
|
function type(value) {
|
|
switch (true) {
|
|
case Array.isArray(value): return Array;
|
|
case isPlainObject(value): return Object;
|
|
case isObject(value): return value.constructor;
|
|
default: return exports.PrimitivePrototype[typeof value];
|
|
}
|
|
}
|