mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
feat(std/node): add isPrimitive (#4673)
This commit is contained in:
parent
68bde7a0c6
commit
90d6831271
2 changed files with 30 additions and 0 deletions
|
@ -46,6 +46,12 @@ export function isRegExp(value: unknown): boolean {
|
|||
return value instanceof RegExp;
|
||||
}
|
||||
|
||||
export function isPrimitive(value: unknown): boolean {
|
||||
return (
|
||||
value === null || (typeof value !== "object" && typeof value !== "function")
|
||||
);
|
||||
}
|
||||
|
||||
export function validateIntegerRange(
|
||||
value: number,
|
||||
name: string,
|
||||
|
|
|
@ -124,3 +124,27 @@ test({
|
|||
assert(!util.isArray(null));
|
||||
},
|
||||
});
|
||||
|
||||
test({
|
||||
name: "[util] isPrimitive",
|
||||
fn() {
|
||||
const stringType = "hasti";
|
||||
const booleanType = true;
|
||||
const integerType = 2;
|
||||
const symbolType = Symbol("anything");
|
||||
|
||||
const functionType = function doBest(): void {};
|
||||
const objectType = { name: "ali" };
|
||||
const arrayType = [1, 2, 3];
|
||||
|
||||
assert(util.isPrimitive(stringType));
|
||||
assert(util.isPrimitive(booleanType));
|
||||
assert(util.isPrimitive(integerType));
|
||||
assert(util.isPrimitive(symbolType));
|
||||
assert(util.isPrimitive(null));
|
||||
assert(util.isPrimitive(undefined));
|
||||
assert(!util.isPrimitive(functionType));
|
||||
assert(!util.isPrimitive(arrayType));
|
||||
assert(!util.isPrimitive(objectType));
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue