@heliosgraphics/utils 6.0.0-alpha.12 → 6.0.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/classnames.ts +35 -12
  2. package/equals.ts +1 -1
  3. package/package.json +1 -1
package/classnames.ts CHANGED
@@ -1,21 +1,44 @@
1
1
  export const getClasses = (...args: Array<unknown>): string => {
2
- const classNames: Set<string> = new Set()
2
+ if (args.length === 1) {
3
+ const arg: unknown = args[0]
4
+ if (typeof arg === "string" && arg.length > 0) {
5
+ return arg
6
+ }
7
+ }
3
8
 
4
- for (const item of args) {
5
- const itemType: string = typeof item
6
- const isValidString: boolean = itemType === "string" && (item as string).length > 0
7
- const isValidObject: boolean = itemType === "object" && item !== null
9
+ let result: string = ""
10
+ let seen: Record<string, boolean> | null = null
8
11
 
9
- if (isValidString) {
10
- classNames.add(item as string)
11
- }
12
+ for (let i: number = 0; i < args.length; i++) {
13
+ const item: unknown = args[i]
14
+ const itemType: string = typeof item
12
15
 
13
- if (isValidObject) {
14
- for (const [key, value] of Object.entries(item as Record<string, unknown>)) {
15
- if (value) classNames.add(key)
16
+ if (itemType === "string") {
17
+ const str: string = item as string
18
+ if (str.length > 0) {
19
+ if (seen === null) {
20
+ seen = { [str]: true }
21
+ result = str
22
+ } else if (!seen[str]) {
23
+ seen[str] = true
24
+ result = result.length > 0 ? result + " " + str : str
25
+ }
26
+ }
27
+ } else if (itemType === "object" && item !== null) {
28
+ const obj: Record<string, unknown> = item as Record<string, unknown>
29
+ for (const key in obj) {
30
+ if (obj[key]) {
31
+ if (seen === null) {
32
+ seen = { [key]: true }
33
+ result = key
34
+ } else if (!seen[key]) {
35
+ seen[key] = true
36
+ result = result.length > 0 ? result + " " + key : key
37
+ }
38
+ }
16
39
  }
17
40
  }
18
41
  }
19
42
 
20
- return [...classNames].join(" ")
43
+ return result
21
44
  }
package/equals.ts CHANGED
@@ -73,7 +73,7 @@ const _getIsEqual = <T extends FracturesComparable>(a: T, b: T, seen = new WeakM
73
73
  if (a instanceof Date && b instanceof Date) return getAreDatesEqual(a, b)
74
74
  if (a instanceof Error && b instanceof Error) return getAreErrorsEqual(a, b)
75
75
  if (a instanceof RegExp && b instanceof RegExp) return getAreRegExpsEqual(a, b)
76
- if (Buffer.isBuffer(a) && Buffer.isBuffer(b)) return getAreBuffersEqual(a, b)
76
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(a) && Buffer.isBuffer(b)) return getAreBuffersEqual(a, b)
77
77
 
78
78
  const keysA: Array<string | symbol> = [...Object.keys(a as object), ...Object.getOwnPropertySymbols(a as object)]
79
79
  const keysB: Array<string | symbol> = [...Object.keys(b as object), ...Object.getOwnPropertySymbols(b as object)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosgraphics/utils",
3
- "version": "6.0.0-alpha.12",
3
+ "version": "6.0.0-alpha.14",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "author": "Chris Puska <chris@puska.org>",