Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions __tests__/type-of.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { typeOf } from "@extremejs/utils";

it("should Returns the typeof result of value", () => {
expect(typeOf("foo")).toBe("string");

expect(typeOf(1)).toBe("number");
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export { default as sumByFn } from "./sum-by-fn.js";
export { default as sumByProperty } from "./sum-by-property.js";
export { default as tail, type TailT } from "./tail.js";
export { default as toPath, type PathT, type PropertyT } from "./to-path.js";
export { default as typeOf, type JSTypeT } from "./type-of.js";
export { default as upperCase } from "./upper-case.js";
export { default as upperFirst } from "./upper-first.js";
3 changes: 2 additions & 1 deletion src/is-boolean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isInstanceOf from "./is-instance-of.js";
import typeOf from "./type-of.js";

/**
* It will determine whether the provided `value` is a boolean or not.
Expand All @@ -12,5 +13,5 @@ import isInstanceOf from "./is-instance-of.js";
* // => false
*/
export default function isBoolean(value: unknown): value is boolean {
return typeof value === "boolean" || isInstanceOf(value, Boolean);
return typeOf(value) === "boolean" || isInstanceOf(value, Boolean);
}
4 changes: 3 additions & 1 deletion src/is-function.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typeOf from "./type-of.js";

/**
* It will determine whether the provided `value` is a function or not.
* @since 1.0.0
Expand All @@ -10,7 +12,7 @@
* // => false
*/
export default function isFunction(value: unknown): value is FunctionT {
return typeof value === "function";
return typeOf(value) === "function";
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
3 changes: 2 additions & 1 deletion src/is-number.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isInstanceOf from "./is-instance-of.js";
import typeOf from "./type-of.js";

/**
* It will determine whether the provided `value` is a number or not.
Expand All @@ -12,5 +13,5 @@ import isInstanceOf from "./is-instance-of.js";
* // => true
*/
export default function isNumber(value: unknown): value is number {
return typeof value === "number" || isInstanceOf(value, Number);
return typeOf(value) === "number" || isInstanceOf(value, Number);
}
3 changes: 2 additions & 1 deletion src/is-object-like.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RecordT } from "./get.js";
import isNil from "./is-nil.js";
import typeOf from "./type-of.js";

/**
* Checks if `value` is object-like.
Expand All @@ -20,5 +21,5 @@ import isNil from "./is-nil.js";
* // => false
*/
export default function isObjectLike(value: unknown): value is RecordT {
return !isNil(value) && typeof value === "object";
return !isNil(value) && typeOf(value) === "object";
}
3 changes: 2 additions & 1 deletion src/is-string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isInstanceOf from "./is-instance-of.js";
import typeOf from "./type-of.js";

/**
* It will determine whether the provided `value` is a string or not.
Expand All @@ -12,5 +13,5 @@ import isInstanceOf from "./is-instance-of.js";
* // => false
*/
export default function isString(value: unknown): value is string {
return typeof value === "string" || isInstanceOf(value, String);
return typeOf(value) === "string" || isInstanceOf(value, String);
}
3 changes: 2 additions & 1 deletion src/is-symbol.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isInstanceOf from "./is-instance-of.js";
import typeOf from "./type-of.js";

/**
* It will determine whether the provided `value` is a symbol or not.
Expand All @@ -12,5 +13,5 @@ import isInstanceOf from "./is-instance-of.js";
* // => true
*/
export default function isSymbol(value: unknown): value is symbol {
return typeof value === "symbol" || isInstanceOf(value, Symbol);
return typeOf(value) === "symbol" || isInstanceOf(value, Symbol);
}
13 changes: 13 additions & 0 deletions src/type-of.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Returns the `typeof` result of `value`.
* @since 1.0.0
* @param value
* @example
* typeOf(1);
* // => "number"
*/
export default function typeOf<Value>(value: Value): JSTypeT {
return typeof value;
}

export type JSTypeT = "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined";