jssm 5.78.0 → 5.79.2

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.
@@ -35,6 +35,13 @@ declare function seq(n: number): number[];
35
35
  declare const histograph: Function;
36
36
  declare const weighted_sample_select: Function;
37
37
  declare const weighted_histo_key: Function;
38
+ /*******
39
+ *
40
+ * Internal method generating names for edges for the hook lookup map. Not
41
+ * meant for external use.
42
+ *
43
+ */
44
+ declare function name_bind_prop_and_state(prop: string, state: string): string;
38
45
  /*******
39
46
  *
40
47
  * Internal method generating names for edges for the hook lookup map. Not
@@ -57,4 +64,40 @@ declare const named_hook_name: (from: string, to: string, action: string) => str
57
64
  *
58
65
  */
59
66
  declare const make_mulberry_rand: (a?: number | undefined) => () => number;
60
- export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name, make_mulberry_rand };
67
+ /*******
68
+ *
69
+ * Reduces an array to its unique contents. Compares with `===` and makes no
70
+ * effort to deep-compare contents; two matching arrays or objects contained
71
+ * will be treated as distinct, according to javascript rules. This also means
72
+ * that `NaNs` will be ***dropped***, because they do not self-compare.
73
+ *
74
+ * ```typescript
75
+ * unique( [] ); // []
76
+ * unique( [0,0] ); // [0]
77
+ * unique( [0,1,2, 0,1,2, 0,1,2] ); // [0,1,2]
78
+ * unique( [ [1], [1] ] ); // [ [1], [1] ] because arrays don't match
79
+ * unique( [0,NaN,2] ); // [0,2]
80
+ * ```
81
+ *
82
+ */
83
+ declare const unique: <T>(arr?: T[]) => T[];
84
+ /*******
85
+ *
86
+ * Lists all repeated items in an array along with their counts. Subject to
87
+ * matching rules of Map. `NaN` is manually removed because of conflict rules
88
+ * around {@link unique}. Because these are compared with `===` and because
89
+ * arrays and objects never match that way unless they're the same object,
90
+ * arrays and objects are never considered repeats.
91
+ *
92
+ * ```typescript
93
+ * find_repeated<string>([ ]); // []
94
+ * find_repeated<string>([ "one" ]); // []
95
+ * find_repeated<string>([ "one", "two" ]); // []
96
+ * find_repeated<string>([ "one", "one" ]); // [ ["one", 2] ]
97
+ * find_repeated<string>([ "one", "two", "one" ]); // [ ["one", 2] ]
98
+ * find_repeated<number>([ 0, NaN, 0, NaN ]); // [ [0, 2] ]
99
+ * ```
100
+ *
101
+ */
102
+ declare function find_repeated<T>(arr: T[]): [T, number][];
103
+ export { seq, unique, find_repeated, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name, make_mulberry_rand };
@@ -1,3 +1,4 @@
1
+ import { JssmError } from './jssm_error';
1
2
  /*******
2
3
  *
3
4
  * Predicate for validating an array for uniqueness. Not generally meant for
@@ -70,6 +71,21 @@ const weighted_histo_key = (n, opts, prob_prop, extract) => // TODO FIXME no any
70
71
  histograph(weighted_sample_select(n, opts, prob_prop)
71
72
  .map((s) => s[extract] // TODO FIXME eslint-disable-line flowtype/no-weak-types
72
73
  ));
74
+ /*******
75
+ *
76
+ * Internal method generating names for edges for the hook lookup map. Not
77
+ * meant for external use.
78
+ *
79
+ */
80
+ function name_bind_prop_and_state(prop, state) {
81
+ if (typeof prop !== 'string') {
82
+ throw new JssmError(undefined, `Name of property must be a string; got ${prop}`);
83
+ }
84
+ if (typeof state !== 'string') {
85
+ throw new JssmError(undefined, `Name of state must be a string; got ${prop}`);
86
+ }
87
+ return JSON.stringify([prop, state]);
88
+ }
73
89
  /*******
74
90
  *
75
91
  * Internal method generating names for edges for the hook lookup map. Not
@@ -100,4 +116,55 @@ const make_mulberry_rand = (a) => () => {
100
116
  t ^= t + Math.imul(t ^ t >>> 7, t | 61);
101
117
  return ((t ^ t >>> 14) >>> 0) / 4294967296;
102
118
  };
103
- export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name, make_mulberry_rand };
119
+ /*******
120
+ *
121
+ * Reduces an array to its unique contents. Compares with `===` and makes no
122
+ * effort to deep-compare contents; two matching arrays or objects contained
123
+ * will be treated as distinct, according to javascript rules. This also means
124
+ * that `NaNs` will be ***dropped***, because they do not self-compare.
125
+ *
126
+ * ```typescript
127
+ * unique( [] ); // []
128
+ * unique( [0,0] ); // [0]
129
+ * unique( [0,1,2, 0,1,2, 0,1,2] ); // [0,1,2]
130
+ * unique( [ [1], [1] ] ); // [ [1], [1] ] because arrays don't match
131
+ * unique( [0,NaN,2] ); // [0,2]
132
+ * ```
133
+ *
134
+ */
135
+ const unique = (arr) => arr.filter((v, i, a) => a.indexOf(v) === i);
136
+ /*******
137
+ *
138
+ * Lists all repeated items in an array along with their counts. Subject to
139
+ * matching rules of Map. `NaN` is manually removed because of conflict rules
140
+ * around {@link unique}. Because these are compared with `===` and because
141
+ * arrays and objects never match that way unless they're the same object,
142
+ * arrays and objects are never considered repeats.
143
+ *
144
+ * ```typescript
145
+ * find_repeated<string>([ ]); // []
146
+ * find_repeated<string>([ "one" ]); // []
147
+ * find_repeated<string>([ "one", "two" ]); // []
148
+ * find_repeated<string>([ "one", "one" ]); // [ ["one", 2] ]
149
+ * find_repeated<string>([ "one", "two", "one" ]); // [ ["one", 2] ]
150
+ * find_repeated<number>([ 0, NaN, 0, NaN ]); // [ [0, 2] ]
151
+ * ```
152
+ *
153
+ */
154
+ function find_repeated(arr) {
155
+ const uniqued = unique(arr);
156
+ if (uniqued.length !== arr.length) {
157
+ const residue_keys = new Map();
158
+ arr.forEach(k => residue_keys.set(k, residue_keys.has(k)
159
+ ? (residue_keys.get(k) + 1)
160
+ : 1));
161
+ uniqued.forEach(k => residue_keys.set(k, residue_keys.get(k) - 1));
162
+ return [...residue_keys.entries()]
163
+ .filter((e) => ((e[1] > 0) && (!(Number.isNaN(e[0])))))
164
+ .map((e) => [e[0], e[1] + 1]);
165
+ }
166
+ else {
167
+ return [];
168
+ }
169
+ }
170
+ export { seq, unique, find_repeated, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, name_bind_prop_and_state, hook_name, named_hook_name, make_mulberry_rand };
@@ -1,2 +1,2 @@
1
- const version = "5.78.0";
1
+ const version = "5.79.2";
2
2
  export { version };