Skip to content

Commit 56992b2

Browse files
refactor: enforce uniform naming convention of internal functions
1 parent 1fbca7b commit 56992b2

File tree

186 files changed

+2650
-1920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+2650
-1920
lines changed

packages/api/src/mixins/igrid.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const IGrid2DMixin = mixin(<IGrid2D<any, any>>{
9292
*/
9393
export const IGrid3DMixin = mixin(<IGrid3D<any, any>>{
9494
order() {
95-
return strideOrder(this.stride);
95+
return __strideOrder(this.stride);
9696
},
9797

9898
includes(x: number, y: number, z: number) {
@@ -148,7 +148,7 @@ export const IGrid3DMixin = mixin(<IGrid3D<any, any>>{
148148
*/
149149
export const IGrid4DMixin = mixin(<IGrid4D<any, any>>{
150150
order() {
151-
return strideOrder(this.stride);
151+
return __strideOrder(this.stride);
152152
},
153153

154154
includes(x: number, y: number, z: number, w: number) {
@@ -202,7 +202,8 @@ export const IGrid4DMixin = mixin(<IGrid4D<any, any>>{
202202
},
203203
});
204204

205-
const strideOrder = (strides: NumericArray) =>
205+
/** @internal */
206+
const __strideOrder = (strides: NumericArray) =>
206207
[...strides]
207208
.map((x, i) => [x, i])
208209
.sort((a, b) => Math.abs(b[0]) - Math.abs(a[0]))

packages/args/src/parse.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const parse = <T extends IObjectOf<any>>(
1515
): Maybe<ParseResult<T>> => {
1616
opts = { start: 2, showUsage: true, help: ["--help", "-h"], ...opts };
1717
try {
18-
return parseOpts(specs, argv, opts);
18+
return __parseOpts(specs, argv, opts);
1919
} catch (e) {
2020
if (opts.showUsage) {
2121
console.log(
@@ -26,12 +26,13 @@ export const parse = <T extends IObjectOf<any>>(
2626
}
2727
};
2828

29-
const parseOpts = <T extends IObjectOf<any>>(
29+
/** @internal */
30+
const __parseOpts = <T extends IObjectOf<any>>(
3031
specs: Args<T>,
3132
argv: string[],
3233
opts: Partial<ParseOpts>
3334
): Maybe<ParseResult<T>> => {
34-
const aliases = aliasIndex<T>(specs);
35+
const aliases = __aliasIndex<T>(specs);
3536
const acc: any = {};
3637
let id: Nullable<string>;
3738
let spec: Nullable<ArgSpecExt>;
@@ -43,27 +44,28 @@ const parseOpts = <T extends IObjectOf<any>>(
4344
console.log(usage(specs, opts.usageOpts));
4445
return;
4546
}
46-
const state = parseKey(specs, aliases, acc, a);
47+
const state = __parseKey(specs, aliases, acc, a);
4748
id = state.id;
4849
spec = state.spec;
4950
i = i + ~~(state.state < 2);
5051
if (state.state) break;
5152
} else {
52-
if (parseValue(spec!, acc, id, a)) break;
53+
if (__parseValue(spec!, acc, id, a)) break;
5354
id = null;
5455
i++;
5556
}
5657
}
5758
id && illegalArgs(`missing value for: --${id}`);
5859
return {
59-
result: processResults(specs, acc),
60+
result: __processResults(specs, acc),
6061
index: i,
6162
rest: argv.slice(i),
6263
done: i >= argv.length,
6364
};
6465
};
6566

66-
const aliasIndex = <T extends IObjectOf<any>>(specs: Args<T>) =>
67+
/** @internal */
68+
const __aliasIndex = <T extends IObjectOf<any>>(specs: Args<T>) =>
6769
Object.entries(specs).reduce(
6870
(acc, [k, v]) => (v.alias ? ((acc[v.alias] = k), acc) : acc),
6971
<IObjectOf<string>>{}
@@ -75,7 +77,8 @@ interface ParseKeyResult {
7577
spec?: ArgSpecExt;
7678
}
7779

78-
const parseKey = <T extends IObjectOf<any>>(
80+
/** @internal */
81+
const __parseKey = <T extends IObjectOf<any>>(
7982
specs: Args<T>,
8083
aliases: IObjectOf<string>,
8184
acc: any,
@@ -105,7 +108,8 @@ const parseKey = <T extends IObjectOf<any>>(
105108
return { state: 2 };
106109
};
107110

108-
const parseValue = (spec: ArgSpecExt, acc: any, id: string, a: string) => {
111+
/** @internal */
112+
const __parseValue = (spec: ArgSpecExt, acc: any, id: string, a: string) => {
109113
/^-[a-z]/i.test(a) && illegalArgs(`missing value for: --${id}`);
110114
if (spec!.multi) {
111115
isArray(acc[id!]) ? acc[id!].push(a) : (acc[id!] = [a]);
@@ -115,7 +119,11 @@ const parseValue = (spec: ArgSpecExt, acc: any, id: string, a: string) => {
115119
return spec!.fn && !spec!.fn(a);
116120
};
117121

118-
const processResults = <T extends IObjectOf<any>>(specs: Args<T>, acc: any) => {
122+
/** @internal */
123+
const __processResults = <T extends IObjectOf<any>>(
124+
specs: Args<T>,
125+
acc: any
126+
) => {
119127
let spec: Nullable<ArgSpecExt>;
120128
for (let id in specs) {
121129
spec = specs[id];
@@ -126,13 +134,14 @@ const processResults = <T extends IObjectOf<any>>(specs: Args<T>, acc: any) => {
126134
illegalArgs(`missing arg: --${id}`);
127135
}
128136
} else if (spec.coerce) {
129-
coerceValue(spec, acc, id);
137+
__coerceValue(spec, acc, id);
130138
}
131139
}
132140
return acc;
133141
};
134142

135-
const coerceValue = (spec: ArgSpecExt, acc: any, id: string) => {
143+
/** @internal */
144+
const __coerceValue = (spec: ArgSpecExt, acc: any, id: string) => {
136145
try {
137146
if (spec.multi && spec.delim) {
138147
acc[id] = (<string[]>acc[id]).reduce(

packages/args/src/usage.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const usage = <T extends IObjectOf<any>>(
3434
: <ColorTheme>{};
3535
const indent = repeat(" ", opts.paramWidth!);
3636
const format = (ids: string[]) =>
37-
ids.map((id) => argUsage(id, specs[id], opts, theme, indent));
37+
ids.map((id) => __argUsage(id, specs[id], opts, theme, indent));
3838
const sortedIDs = Object.keys(specs).sort();
3939
const groups: Pair<string, string[]>[] = opts.groups
4040
? opts.groups
@@ -47,70 +47,75 @@ export const usage = <T extends IObjectOf<any>>(
4747
.filter((g) => !!g[1].length)
4848
: [["options", sortedIDs]];
4949
return [
50-
...wrap(opts.prefix, opts.lineWidth!),
50+
...__wrap(opts.prefix, opts.lineWidth!),
5151
...groups.map(([gid, ids]) =>
5252
[
5353
...(opts.showGroupNames ? [`${capitalize(gid)}:\n`] : []),
5454
...format(ids),
5555
"",
5656
].join("\n")
5757
),
58-
...wrap(opts.suffix, opts.lineWidth!),
58+
...__wrap(opts.suffix, opts.lineWidth!),
5959
].join("\n");
6060
};
6161

62-
const argUsage = (
62+
/** @internal */
63+
const __argUsage = (
6364
id: string,
6465
spec: ArgSpecExt,
6566
opts: Partial<UsageOpts>,
6667
theme: ColorTheme,
6768
indent: string
6869
) => {
69-
const hint = argHint(spec, theme);
70-
const alias = argAlias(spec, theme, hint);
71-
const name = ansi(`--${kebab(id)}`, theme.param!);
70+
const hint = __argHint(spec, theme);
71+
const alias = __argAlias(spec, theme, hint);
72+
const name = __ansi(`--${kebab(id)}`, theme.param!);
7273
const params = `${alias}${name}${hint}`;
7374
const isRequired = spec.optional === false && spec.default === undefined;
7475
const prefixes: string[] = [];
7576
isRequired && prefixes.push("required");
7677
spec.multi && prefixes.push("multiple");
7778
const body =
78-
argPrefix(prefixes, theme, isRequired) +
79+
__argPrefix(prefixes, theme, isRequired) +
7980
(spec.desc || "") +
80-
argDefault(spec, opts, theme);
81+
__argDefault(spec, opts, theme);
8182
return (
8283
padRight(opts.paramWidth!)(params, lengthAnsi(params)) +
83-
wrap(body, opts.lineWidth! - opts.paramWidth!)
84+
__wrap(body, opts.lineWidth! - opts.paramWidth!)
8485
.map((l, i) => (i > 0 ? indent + l : l))
8586
.join("\n")
8687
);
8788
};
8889

89-
const argHint = (spec: ArgSpecExt, theme: ColorTheme) =>
90-
spec.hint ? ansi(" " + spec.hint, theme.hint!) : "";
90+
/** @internal */
91+
const __argHint = (spec: ArgSpecExt, theme: ColorTheme) =>
92+
spec.hint ? __ansi(" " + spec.hint, theme.hint!) : "";
9193

92-
const argAlias = (spec: ArgSpecExt, theme: ColorTheme, hint: string) =>
93-
spec.alias ? `${ansi("-" + spec.alias, theme.param!)}${hint}, ` : "";
94+
/** @internal */
95+
const __argAlias = (spec: ArgSpecExt, theme: ColorTheme, hint: string) =>
96+
spec.alias ? `${__ansi("-" + spec.alias, theme.param!)}${hint}, ` : "";
9497

95-
const argPrefix = (
98+
/** @internal */
99+
const __argPrefix = (
96100
prefixes: string[],
97101
theme: ColorTheme,
98102
isRequired: boolean
99103
) =>
100104
prefixes.length
101-
? ansi(
105+
? __ansi(
102106
`[${prefixes.join(", ")}] `,
103107
isRequired ? theme.required! : theme.multi!
104108
)
105109
: "";
106110

107-
const argDefault = (
111+
/** @internal */
112+
const __argDefault = (
108113
spec: ArgSpecExt,
109114
opts: Partial<UsageOpts>,
110115
theme: ColorTheme
111116
) =>
112117
opts.showDefaults && spec.default != null && spec.default !== false
113-
? ansi(
118+
? __ansi(
114119
` (default: ${stringify(true)(
115120
spec.defaultHint != undefined
116121
? spec.defaultHint
@@ -120,10 +125,12 @@ const argDefault = (
120125
)
121126
: "";
122127

123-
const ansi = (x: string, col: number) =>
128+
/** @internal */
129+
const __ansi = (x: string, col: number) =>
124130
col != null ? `\x1b[${col}m${x}\x1b[0m` : x;
125131

126-
const wrap = (str: Maybe<string>, width: number) =>
132+
/** @internal */
133+
const __wrap = (str: Maybe<string>, width: number) =>
127134
str
128135
? wordWrapLines(str, {
129136
width,

packages/arrays/src/levenshtein.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Predicate2 } from "@thi.ng/api";
22

3-
const eqStrict = (a: any, b: any) => a === b;
3+
/** @internal */
4+
const __eqStrict = (a: any, b: any) => a === b;
45

56
/**
67
* Computes Levenshtein distance w/ optionally given `maxDist` (for
@@ -46,7 +47,7 @@ export const levenshtein = <T>(
4647
a: ArrayLike<T>,
4748
b: ArrayLike<T>,
4849
maxDist = Infinity,
49-
equiv: Predicate2<T> = eqStrict
50+
equiv: Predicate2<T> = __eqStrict
5051
): number => {
5152
if (a === b) {
5253
return 0;
@@ -161,7 +162,7 @@ export const normalizedLevenshtein = <T>(
161162
a: ArrayLike<T>,
162163
b: ArrayLike<T>,
163164
maxDist = Infinity,
164-
equiv = eqStrict
165+
equiv = __eqStrict
165166
): number => {
166167
const n = Math.max(a.length, b.length);
167168
return n > 0 ? levenshtein(a, b, maxDist, equiv) / n : 0;

packages/associative/src/hash-map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ interface HashMapState<K, V> {
2828
size: number;
2929
}
3030

31+
/** @internal */
3132
const __private = new WeakMap<HashMap<any, any>, HashMapState<any, any>>();
3233

34+
/** @internal */
3335
const __iterator = <K, V>(map: HashMap<K, V>, id: 0 | 1) =>
3436
function* () {
3537
for (let p of __private.get(map)!.bins) {

packages/associative/src/internal/inspect.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ isNode() &&
1616
inspect = m.inspect;
1717
});
1818

19-
const inspectSet = (coll: Set<any>, opts: any) =>
19+
/** @internal */
20+
const __inspectSet = (coll: Set<any>, opts: any) =>
2021
[...map((x) => inspect!(x, opts), coll)].join(", ");
2122

22-
const inspectMap = (coll: Map<any, any>, opts: any) =>
23+
/** @internal */
24+
const __inspectMap = (coll: Map<any, any>, opts: any) =>
2325
[
2426
...map(
2527
([k, v]) => `${inspect!(k, opts)} => ${inspect!(v, opts)}`,
@@ -48,9 +50,9 @@ export const __inspectable = mixin({
4850
`${name}(${this.size || 0}) {`,
4951
inspect
5052
? this instanceof Set
51-
? inspectSet(this, childOpts)
53+
? __inspectSet(this, childOpts)
5254
: this instanceof Map
53-
? inspectMap(this, childOpts)
55+
? __inspectMap(this, childOpts)
5456
: ""
5557
: "",
5658
"}",

packages/associative/src/sparse-set.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ interface SparseSetProps {
1212
n: number;
1313
}
1414

15+
/** @internal */
1516
const __private = new WeakMap<ASparseSet<any>, SparseSetProps>();
1617

17-
const fail = () => illegalArgs(`dense & sparse arrays must be of same size`);
18+
/** @internal */
19+
const __fail = () => illegalArgs(`dense & sparse arrays must be of same size`);
1820

1921
/**
2022
* After "An Efficient Representation for Sparse Sets" Preston Briggs and Linda
@@ -165,7 +167,7 @@ export class SparseSet8
165167
? super(new Uint8Array(n), new Uint8Array(n))
166168
: n.length === sparse!.length
167169
? super(n, sparse!)
168-
: fail();
170+
: __fail();
169171
}
170172

171173
get [Symbol.species]() {
@@ -196,7 +198,7 @@ export class SparseSet16
196198
? super(new Uint16Array(n), new Uint16Array(n))
197199
: n.length === sparse!.length
198200
? super(n, sparse!)
199-
: fail();
201+
: __fail();
200202
}
201203

202204
get [Symbol.species]() {
@@ -227,7 +229,7 @@ export class SparseSet32
227229
? super(new Uint32Array(n), new Uint32Array(n))
228230
: n.length === sparse!.length
229231
? super(n, sparse!)
230-
: fail();
232+
: __fail();
231233
}
232234

233235
get [Symbol.species]() {

0 commit comments

Comments
 (0)