@carto/api-client 0.5.0-alpha.15 → 0.5.0-alpha.16

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/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://github.com/CartoDB/carto-api-client#readme",
9
9
  "author": "Don McCurdy <donmccurdy@carto.com>",
10
10
  "packageManager": "yarn@4.3.1",
11
- "version": "0.5.0-alpha.15",
11
+ "version": "0.5.0-alpha.16",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -116,7 +116,6 @@
116
116
  "resolve-package-path": "^4.0.3",
117
117
  "rimraf": "^6.0.1",
118
118
  "semver": "^7.7.1",
119
- "thenby": "^1.3.4",
120
119
  "tinybench": "^3.1.1",
121
120
  "tsup": "^8.3.6",
122
121
  "typescript": "~5.8.2",
@@ -1,4 +1,4 @@
1
- import {firstBy} from 'thenby';
1
+ import {firstBy} from '../vendor/thenby.js';
2
2
  import {SortDirection} from '../types.js';
3
3
  import {FeatureData} from '../types-internal.js';
4
4
 
@@ -0,0 +1,83 @@
1
+ /**
2
+ Copyright 2013 Teun Duynstee
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ // Modifications by Don McCurdy, for minimal TypeScript compatibility. Moved
18
+ // into 'vendor' to avoid CJS/ESM compatibility issues in Web Workers.
19
+
20
+ export const firstBy: any = (function () {
21
+ function identity(v: unknown) {
22
+ return v;
23
+ }
24
+
25
+ function ignoreCase(v: unknown) {
26
+ return typeof v === 'string' ? v.toLowerCase() : v;
27
+ }
28
+
29
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
30
+ function makeCompareFunction(f: Function | string, opt: any) {
31
+ opt = typeof opt === 'object' ? opt : {direction: opt};
32
+
33
+ if (typeof f != 'function') {
34
+ const prop = f;
35
+ // make unary function
36
+ f = function (v1: Record<string, unknown>) {
37
+ return v1[prop] ? v1[prop] : '';
38
+ };
39
+ }
40
+ if (f.length === 1) {
41
+ // f is a unary function mapping a single item to its sort score
42
+ const uf = f;
43
+ const preprocess = opt.ignoreCase ? ignoreCase : identity;
44
+ const cmp =
45
+ opt.cmp ||
46
+ function (v1: number, v2: number) {
47
+ return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;
48
+ };
49
+ f = function (v1: unknown, v2: unknown) {
50
+ return cmp(preprocess(uf(v1)), preprocess(uf(v2)));
51
+ };
52
+ }
53
+ const descTokens = {'-1': '', desc: ''};
54
+ if (opt.direction in descTokens)
55
+ return function (v1: unknown, v2: unknown) {
56
+ return -f(v1, v2);
57
+ };
58
+ return f;
59
+ }
60
+
61
+ /* adds a secondary compare function to the target function (`this` context)
62
+ which is applied in case the first one returns 0 (equal)
63
+ returns a new compare function, which has a `thenBy` method as well */
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
65
+ function tb(func: Function, opt: any) {
66
+ /* should get value false for the first call. This can be done by calling the
67
+ exported function, or the firstBy property on it (for es6 module compatibility)
68
+ */
69
+ // @ts-expect-error Allowing otherwise-unwanted pattern in third-party code.
70
+ const x = typeof this == 'function' && !this.firstBy ? this : false;
71
+ const y = makeCompareFunction(func, opt);
72
+ const f = x
73
+ ? function (a: unknown, b: unknown) {
74
+ return x(a, b) || y(a, b);
75
+ }
76
+ : y;
77
+ // @ts-expect-error Allowing otherwise-unwanted pattern in third-party code.
78
+ f.thenBy = tb;
79
+ return f;
80
+ }
81
+ tb.firstBy = tb;
82
+ return tb;
83
+ })();