@corefunc/corefunc
Advanced tools
Comparing version 0.1.44 to 0.1.45
@@ -5,6 +5,7 @@ "use strict"; | ||
/** | ||
* @category Object Get | ||
* @name objectGetClass | ||
* @description Retrieve instance class name | ||
* @param {*} value | ||
* @returns {string} | ||
* @returns {String} | ||
* @since 1.0.2 | ||
@@ -11,0 +12,0 @@ */ |
/** | ||
* @category Object Get | ||
* @name objectGetClass | ||
* @description Retrieve instance class name | ||
* @param {*} value | ||
* @returns {string} | ||
* @returns {String} | ||
* @since 1.0.2 | ||
*/ | ||
export function objectGetClass(value: object): string { | ||
export function objectGetClass(value: Record<string, unknown>): string { | ||
if (value && typeof value === "object" && "constructor" in value && "name" in value.constructor) { | ||
@@ -10,0 +11,0 @@ return value.constructor.name; |
@@ -5,5 +5,6 @@ "use strict"; | ||
/** | ||
* @category Object Get | ||
* @name objectGetKeys | ||
* @param {Object} object | ||
* @returns {Array.<string>} | ||
* @returns {Array.<String>} | ||
*/ | ||
@@ -10,0 +11,0 @@ function objectGetKeys(object) { |
/** | ||
* @category Object Get | ||
* @name objectGetKeys | ||
* @param {Object} object | ||
* @returns {Array.<string>} | ||
* @returns {Array.<String>} | ||
*/ | ||
@@ -6,0 +7,0 @@ export function objectGetKeys(object: object): string[] { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.objectGetProperty = void 0; | ||
const clone_1 = require("../../v8/clone"); | ||
/** | ||
* @category Object Get | ||
* @name objectGetProperty | ||
* @description Gets the value at path of object. | ||
* @param {Object} object Object to search in | ||
* @param {String|Array.<String>>} key String key or array of string to form path | ||
* @param {*=} defaultValue Default value if path is not exists. Does not replace undefined values | ||
* @param {String|Array.<String>} keyOrPath String key or array of string to form path | ||
* @param {*=} [defaultValue] Default value if path is not exists. Does not replace undefined values | ||
* @returns {*} Value in path or default value | ||
* @since 0.0.47 | ||
*/ | ||
function objectGetProperty(object, key, defaultValue) { | ||
function objectGetProperty(object, keyOrPath, defaultValue) { | ||
if (!object || typeof object !== "object") { | ||
return defaultValue; | ||
} | ||
if (typeof key === "string" && key in object) { | ||
return object[key]; | ||
if (typeof keyOrPath === "string" && keyOrPath in object) { | ||
return object[keyOrPath]; | ||
} | ||
let keySet; | ||
if (typeof key === "string") { | ||
keySet = key.split("."); | ||
if (typeof keyOrPath === "string") { | ||
keySet = keyOrPath.split("."); | ||
} | ||
else if (Array.isArray(key)) { | ||
keySet = key; | ||
else if (Array.isArray(keyOrPath)) { | ||
keySet = keyOrPath; | ||
} | ||
@@ -43,15 +43,10 @@ else { | ||
try { | ||
newObject = clone_1.v8Clone(object); | ||
newObject = Object.assign({}, object); | ||
} | ||
catch (_a) { | ||
try { | ||
newObject = Object.assign({}, object); | ||
newObject = JSON.parse(JSON.stringify(object)); | ||
} | ||
catch (_b) { | ||
try { | ||
newObject = JSON.parse(JSON.stringify(object)); | ||
} | ||
catch (_c) { | ||
return defaultValue; | ||
} | ||
return defaultValue; | ||
} | ||
@@ -58,0 +53,0 @@ } |
@@ -1,24 +0,27 @@ | ||
import { v8Clone } from "../../v8/clone"; | ||
/** | ||
* @category Object Get | ||
* @name objectGetProperty | ||
* @description Gets the value at path of object. | ||
* @param {Object} object Object to search in | ||
* @param {String|Array.<String>>} key String key or array of string to form path | ||
* @param {*=} defaultValue Default value if path is not exists. Does not replace undefined values | ||
* @param {String|Array.<String>} keyOrPath String key or array of string to form path | ||
* @param {*=} [defaultValue] Default value if path is not exists. Does not replace undefined values | ||
* @returns {*} Value in path or default value | ||
* @since 0.0.47 | ||
*/ | ||
export function objectGetProperty(object: Record<string, any>, key: string | string[], defaultValue?: any): any { | ||
export function objectGetProperty<D>( | ||
object: Record<string, unknown>, | ||
keyOrPath: string | string[], | ||
defaultValue?: D, | ||
): unknown { | ||
if (!object || typeof object !== "object") { | ||
return defaultValue; | ||
} | ||
if (typeof key === "string" && key in object) { | ||
return object[key]; | ||
if (typeof keyOrPath === "string" && keyOrPath in object) { | ||
return object[keyOrPath]; | ||
} | ||
let keySet; | ||
if (typeof key === "string") { | ||
keySet = key.split("."); | ||
} else if (Array.isArray(key)) { | ||
keySet = key; | ||
if (typeof keyOrPath === "string") { | ||
keySet = keyOrPath.split("."); | ||
} else if (Array.isArray(keyOrPath)) { | ||
keySet = keyOrPath; | ||
} else { | ||
@@ -38,12 +41,8 @@ return defaultValue; | ||
try { | ||
newObject = v8Clone(object); | ||
newObject = { ...object }; | ||
} catch { | ||
try { | ||
newObject = { ...object }; | ||
newObject = JSON.parse(JSON.stringify(object)); | ||
} catch { | ||
try { | ||
newObject = JSON.parse(JSON.stringify(object)); | ||
} catch { | ||
return defaultValue; | ||
} | ||
return defaultValue; | ||
} | ||
@@ -50,0 +49,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.objectGetType = void 0; | ||
/** | ||
* @category Object Get | ||
* @name objectGetType | ||
* @description Get type of object | ||
* @param {*=} value | ||
* @returns {String} | ||
*/ | ||
function objectGetType(value) { | ||
@@ -5,0 +12,0 @@ const type = Object.prototype.toString.call(value).toLowerCase().split("[object ").pop().split("]").shift(); |
@@ -1,2 +0,9 @@ | ||
export function objectGetType(value: object): string { | ||
/** | ||
* @category Object Get | ||
* @name objectGetType | ||
* @description Get type of object | ||
* @param {*=} value | ||
* @returns {String} | ||
*/ | ||
export function objectGetType(value: Record<string, unknown>): string { | ||
const type = Object.prototype.toString.call(value).toLowerCase().split("[object ").pop().split("]").shift(); | ||
@@ -3,0 +10,0 @@ if (["global", "window"].includes(type)) { |
@@ -15,2 +15,3 @@ "use strict"; | ||
__exportStar(require("./get"), exports); | ||
__exportStar(require("./is"), exports); | ||
__exportStar(require("./set"), exports); |
export * from "./from"; | ||
export * from "./get"; | ||
export * from "./is"; | ||
export * from "./set"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.objectIsEmpty = void 0; | ||
/** | ||
* @category Object Is | ||
* @name objectIsEmpty | ||
* @description Get type of object | ||
* @param {Object} object | ||
* @returns {boolean} | ||
* @param {Boolean} [withNotEnumerable=false] | ||
* @returns {Boolean} | ||
* @example | ||
* const object = {}; | ||
* Object.defineProperties(object, { key: { enumerable: false } }); | ||
* objectIsEmpty(object) ➜ true | ||
* objectIsEmpty(object, false) ➜ true | ||
* objectIsEmpty(object, true) ➜ false | ||
* @since 0.1.45 | ||
*/ | ||
function objectIsEmpty(object) { | ||
return Object.keys(object).length === 0; | ||
function objectIsEmpty(object, withNotEnumerable = false) { | ||
return !(withNotEnumerable ? Object.getOwnPropertyNames(object) : Object.keys(object)).length; | ||
} | ||
exports.default = objectIsEmpty; | ||
exports.objectIsEmpty = objectIsEmpty; |
/** | ||
* @category Object Is | ||
* @name objectIsEmpty | ||
* @description Get type of object | ||
* @param {Object} object | ||
* @returns {boolean} | ||
* @param {Boolean} [withNotEnumerable=false] | ||
* @returns {Boolean} | ||
* @example | ||
* const object = {}; | ||
* Object.defineProperties(object, { key: { enumerable: false } }); | ||
* objectIsEmpty(object) ➜ true | ||
* objectIsEmpty(object, false) ➜ true | ||
* objectIsEmpty(object, true) ➜ false | ||
* @since 0.1.45 | ||
*/ | ||
export default function objectIsEmpty(object: Object): boolean { | ||
return Object.keys(object).length === 0; | ||
export function objectIsEmpty(object: Record<string, unknown>, withNotEnumerable = false): boolean { | ||
return !(withNotEnumerable ? Object.getOwnPropertyNames(object) : Object.keys(object)).length; | ||
} |
@@ -70,3 +70,3 @@ { | ||
}, | ||
"version": "0.1.44" | ||
"version": "0.1.45" | ||
} |
@@ -20,8 +20,8 @@ ![CoreFunc](https://raw.githubusercontent.com/corefunc/corefunc/master/.github/assets/logo_128.png?raw=true "CoreFunc") | ||
- You can steal the code if you don't want to use whole package. | ||
Most functions are not bind to other functions in the library. | ||
- You can steal the code if you don't want to use the whole package. | ||
Most functions are not bound to other functions in the library. | ||
- Super easy for Tree Shaking, no need for Dead Code Hunting. | ||
- It's super easy for Tree Shaking, no need for Dead Code Hunting. | ||
What is the purpose. | ||
What is the purpose? | ||
@@ -28,0 +28,0 @@ - Iterate, check, sort, find on primitives, arrays, objects. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
618581
963
16112