mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -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;
|
return value instanceof RegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPrimitive(value: unknown): boolean {
|
||||||
|
return (
|
||||||
|
value === null || (typeof value !== "object" && typeof value !== "function")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function validateIntegerRange(
|
export function validateIntegerRange(
|
||||||
value: number,
|
value: number,
|
||||||
name: string,
|
name: string,
|
||||||
|
|
|
@ -124,3 +124,27 @@ test({
|
||||||
assert(!util.isArray(null));
|
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…
Add table
Reference in a new issue