pepka 1.12.3 → 1.13.0

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.
package/dist/bundle.cjs CHANGED
@@ -69,8 +69,7 @@ function curry3(fn) {
69
69
  }
70
70
 
71
71
  const length = (s) => s.length;
72
- const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
73
- const is_typed_arr = (t) => typed_arr_re.test(t);
72
+ const is_typed_arr = (x) => ArrayBuffer.isView(x);
74
73
  /** @param start string | any[] @param s string | any[] */
75
74
  const startsWithWith = (comparator) => curry2((start, s) => {
76
75
  const len_start = length(start);
@@ -144,20 +143,32 @@ const type = (s) => {
144
143
  const typeIs = curry2((t, s) => type(s) === t);
145
144
  const eq = curry2((a, b) => a === b);
146
145
  const equals = curry2((a, b) => {
146
+ if (a === b)
147
+ return true;
147
148
  const typea = type(a);
148
- if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
149
+ const ta = is_typed_arr(a);
150
+ if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || ta)) {
151
+ if (ta) {
152
+ if (typea === 'Buffer')
153
+ return a.equals(b);
154
+ const len = length(a);
155
+ if (len !== length(b))
156
+ return false;
157
+ for (let i = 0; i < len; i++)
158
+ if (a[i] !== b[i])
159
+ return false;
160
+ return true;
161
+ }
149
162
  if (isNull(a) || isNull(b))
150
163
  return eq(a, b);
151
- if (eq(a, b))
152
- return true;
153
164
  for (const v of [a, b])
154
165
  for (const k in v)
155
- if (!((eq(v, b)) && (k in a)) &&
156
- !((eq(v, a)) && (k in b) && equals(a[k], b[k])))
166
+ if (!(v === b && (k in a)) &&
167
+ !(v === a && (k in b) && equals(a[k], b[k])))
157
168
  return false;
158
169
  return true;
159
170
  }
160
- return eq(a, b);
171
+ return false;
161
172
  });
162
173
  const includes = curry2((s, ss) => {
163
174
  if (isStr(ss))
@@ -571,7 +582,7 @@ const clone = (s, shallow = false) => {
571
582
  case 'Symbol':
572
583
  return s;
573
584
  default:
574
- return is_typed_arr(t) ? s.constructor.from(s) : s;
585
+ return is_typed_arr(s) ? s.constructor.from(s) : s;
575
586
  }
576
587
  };
577
588
  const cloneShallow = (s) => clone(s, true);
package/dist/bundle.mjs CHANGED
@@ -67,8 +67,7 @@ function curry3(fn) {
67
67
  }
68
68
 
69
69
  const length = (s) => s.length;
70
- const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
71
- const is_typed_arr = (t) => typed_arr_re.test(t);
70
+ const is_typed_arr = (x) => ArrayBuffer.isView(x);
72
71
  /** @param start string | any[] @param s string | any[] */
73
72
  const startsWithWith = (comparator) => curry2((start, s) => {
74
73
  const len_start = length(start);
@@ -142,20 +141,32 @@ const type = (s) => {
142
141
  const typeIs = curry2((t, s) => type(s) === t);
143
142
  const eq = curry2((a, b) => a === b);
144
143
  const equals = curry2((a, b) => {
144
+ if (a === b)
145
+ return true;
145
146
  const typea = type(a);
146
- if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
147
+ const ta = is_typed_arr(a);
148
+ if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || ta)) {
149
+ if (ta) {
150
+ if (typea === 'Buffer')
151
+ return a.equals(b);
152
+ const len = length(a);
153
+ if (len !== length(b))
154
+ return false;
155
+ for (let i = 0; i < len; i++)
156
+ if (a[i] !== b[i])
157
+ return false;
158
+ return true;
159
+ }
147
160
  if (isNull(a) || isNull(b))
148
161
  return eq(a, b);
149
- if (eq(a, b))
150
- return true;
151
162
  for (const v of [a, b])
152
163
  for (const k in v)
153
- if (!((eq(v, b)) && (k in a)) &&
154
- !((eq(v, a)) && (k in b) && equals(a[k], b[k])))
164
+ if (!(v === b && (k in a)) &&
165
+ !(v === a && (k in b) && equals(a[k], b[k])))
155
166
  return false;
156
167
  return true;
157
168
  }
158
- return eq(a, b);
169
+ return false;
159
170
  });
160
171
  const includes = curry2((s, ss) => {
161
172
  if (isStr(ss))
@@ -569,7 +580,7 @@ const clone = (s, shallow = false) => {
569
580
  case 'Symbol':
570
581
  return s;
571
582
  default:
572
- return is_typed_arr(t) ? s.constructor.from(s) : s;
583
+ return is_typed_arr(s) ? s.constructor.from(s) : s;
573
584
  }
574
585
  };
575
586
  const cloneShallow = (s) => clone(s, true);
package/package.json CHANGED
@@ -42,7 +42,7 @@
42
42
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
43
43
  "all": "npm run dev && npm run prod"
44
44
  },
45
- "version": "1.12.3",
45
+ "version": "1.13.0",
46
46
  "devDependencies": {
47
47
  "@rollup/plugin-commonjs": "^29.0.2",
48
48
  "@rollup/plugin-node-resolve": "^16.0.3",
package/src/common.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { curry2 } from "./curry"
2
- import { is_typed_arr } from "./internal"
2
+ import { is_typed_arr, length } from "./internal"
3
3
  import { isNull, isStr, to } from "./utils"
4
4
  const {isNaN} = Number
5
5
 
@@ -21,19 +21,26 @@ export const typeIs = curry2((t: string, s: any) => type(s)===t)
21
21
 
22
22
  export const eq = curry2((a: any, b: any) => a===b)
23
23
  export const equals = curry2((a: any, b: any) => {
24
+ if(a===b) return true
24
25
  const typea = type(a)
25
- if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
26
+ const ta = is_typed_arr(a)
27
+ if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || ta)) {
28
+ if(ta) {
29
+ if(typea==='Buffer') return (a as Buffer).equals(b)
30
+ const len = length(a as any)
31
+ if(len!==length(b)) return false
32
+ for(let i=0; i<len; i++) if(a[i]!==b[i]) return false
33
+ return true
34
+ }
26
35
  if(isNull(a) || isNull(b)) return eq(a, b)
27
- if(eq(a, b)) return true
28
- for(const v of [a, b])
29
- for(const k in v)
30
- if(
31
- !((eq(v, b)) && (k in a)) &&
32
- !((eq(v, a)) && (k in b) && equals(a[k], b[k]))
33
- ) return false
36
+ for(const v of [a, b]) for(const k in v)
37
+ if(
38
+ !(v===b && (k in a)) &&
39
+ !(v===a && (k in b) && equals(a[k], b[k]))
40
+ ) return false
34
41
  return true
35
42
  }
36
- return eq(a, b)
43
+ return false
37
44
  })
38
45
  export const includes = curry2(
39
46
  <T>(s: T, ss: T[]) => {
@@ -49,3 +56,4 @@ export const identity = <T extends any>(s: T) => s
49
56
  export const trim = (s: string) => s.trim()
50
57
 
51
58
  export { length } from './internal'
59
+
package/src/internal.ts CHANGED
@@ -2,8 +2,7 @@ import { curry2 } from "./curry"
2
2
  import { AnyArray, StrLen } from "./internal_types"
3
3
 
4
4
  export const length = <T extends AnyArray | string>(s: T): T extends string ? StrLen<T> : T['length'] => s.length as any
5
- const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/
6
- export const is_typed_arr = (t: string) => typed_arr_re.test(t)
5
+ export const is_typed_arr = (x: any) => ArrayBuffer.isView(x)
7
6
  /** @param start string | any[] @param s string | any[] */
8
7
  export const startsWithWith = (comparator: (x: any, y: any)=>boolean) => curry2(
9
8
  (start: any[] | string, s: any[] | string) => {
package/src/safe.ts CHANGED
@@ -301,7 +301,7 @@ export const clone = <T extends any>(s: T, shallow = false): T => {
301
301
  case 'Boolean': case 'Symbol':
302
302
  return s
303
303
  default:
304
- return is_typed_arr(t) ? (s as any).constructor.from(s) : s
304
+ return is_typed_arr(s) ? (s as any).constructor.from(s) : s
305
305
  }
306
306
  }
307
307
  export const cloneShallow = (s: any) => clone(s, true)