1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

feat(std/node): add isPrimitive (#4673)

This commit is contained in:
Ali Hasani 2020-04-09 03:14:39 +04:30 committed by GitHub
parent 68bde7a0c6
commit 90d6831271
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -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,

View file

@ -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));
},
});