@semantic-ui/utils
Advanced tools
Comparing version 0.0.16 to 0.0.17
{ | ||
"name": "@semantic-ui/utils", | ||
"version": "0.0.16", | ||
"type": "module", | ||
@@ -11,3 +10,4 @@ "main": "src/utils.js", | ||
"vitest": "^1.5.2" | ||
} | ||
}, | ||
"version": "0.0.17" | ||
} |
@@ -60,2 +60,3 @@ # @semantic-ui/utils | ||
- `isEmpty(x)` Checks if the value is empty like {} | ||
- `isClassInstance(x)` - Checks if the value is an instance of a custom class | ||
@@ -62,0 +63,0 @@ ### Date |
@@ -136,2 +136,34 @@ /* | ||
export const isClassInstance = (obj) => { | ||
if (obj === null || typeof obj !== 'object') { | ||
return false; | ||
} | ||
const proto = Object.getPrototypeOf(obj); | ||
const constructorName = proto.constructor.name; | ||
const builtInTypes = [ | ||
'Object', | ||
'Array', | ||
'Date', | ||
'RegExp', | ||
'Map', | ||
'Set', | ||
'Error', | ||
'Uint8Array', | ||
'Int8Array', | ||
'Uint16Array', | ||
'Int16Array', | ||
'Uint32Array', | ||
'Int32Array', | ||
'Float32Array', | ||
'Float64Array', | ||
'BigInt64Array', | ||
'BigUint64Array', | ||
'NodeList', | ||
]; | ||
return !builtInTypes.includes(constructorName); | ||
}; | ||
/*------------------- | ||
@@ -692,7 +724,7 @@ Date | ||
let copy; | ||
/*if (src.nodeType && 'cloneNode' in src) { | ||
if (src.nodeType && 'cloneNode' in src) { | ||
copy = src.cloneNode(true); | ||
seen.set(src, copy); | ||
} | ||
else */if (src instanceof Date) { | ||
else if (src instanceof Date) { | ||
// Date | ||
@@ -699,0 +731,0 @@ copy = new Date(src.getTime()); |
@@ -30,2 +30,3 @@ import { describe, expect, it, vi } from 'vitest'; | ||
isFunction, | ||
isClassInstance, | ||
isNumber, | ||
@@ -220,2 +221,60 @@ isObject, | ||
}); | ||
describe('isClassInstance', () => { | ||
it('should return true for a custom class instance', () => { | ||
class MyClass {} | ||
const instance = new MyClass(); | ||
expect(isClassInstance(instance)).toBe(true); | ||
}); | ||
it('should return false for a plain object', () => { | ||
const obj = {}; | ||
expect(isClassInstance(obj)).toBe(false); | ||
}); | ||
it('should return false for primitive values', () => { | ||
expect(isClassInstance(null)).toBe(false); | ||
expect(isClassInstance(undefined)).toBe(false); | ||
expect(isClassInstance(42)).toBe(false); | ||
expect(isClassInstance('hello')).toBe(false); | ||
expect(isClassInstance(true)).toBe(false); | ||
}); | ||
it('should return false for an array', () => { | ||
expect(isClassInstance([])).toBe(false); | ||
}); | ||
it('should return false for a Date object', () => { | ||
expect(isClassInstance(new Date())).toBe(false); | ||
}); | ||
it('should return false for a regular expression', () => { | ||
expect(isClassInstance(/regex/)).toBe(false); | ||
}); | ||
it('should return false for a Map object', () => { | ||
expect(isClassInstance(new Map())).toBe(false); | ||
}); | ||
it('should return false for a Set object', () => { | ||
expect(isClassInstance(new Set())).toBe(false); | ||
}); | ||
it('should return false for an Error object', () => { | ||
expect(isClassInstance(new Error())).toBe(false); | ||
}); | ||
it('should return false for a Uint8Array', () => { | ||
expect(isClassInstance(new Uint8Array())).toBe(false); | ||
}); | ||
// Add more test cases for other built-in object types as needed | ||
it('should return false for functions', () => { | ||
expect(isClassInstance(() => {})).toBe(false); | ||
function testFunction() {} | ||
expect(isClassInstance(testFunction)).toBe(false); | ||
}); | ||
}); | ||
describe('groupBy', () => { | ||
@@ -222,0 +281,0 @@ it('should group objects by a simple property', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67490
1958
103