jssm 5.65.3 → 5.65.7
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/es6/jssm.d.ts +81 -2
- package/dist/es6/jssm.js +81 -2
- package/dist/es6/jssm_util.d.ts +43 -1
- package/dist/es6/jssm_util.js +53 -2
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +81 -2
- package/jssm_util.d.ts +43 -1
- package/package.json +1 -1
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -82,13 +82,15 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
|
|
|
82
82
|
* operator `sm`, and mostly falls back to `.from` when needing to parse
|
|
83
83
|
* strings dynamically instead of from template literals.
|
|
84
84
|
*
|
|
85
|
+
* Operator {@link sm}:
|
|
86
|
+
*
|
|
85
87
|
* ```typescript
|
|
86
88
|
* import { sm } from './jssm';
|
|
87
89
|
*
|
|
88
90
|
* const switch = sm`on <=> off;`;
|
|
89
91
|
* ```
|
|
90
92
|
*
|
|
91
|
-
*
|
|
93
|
+
* Method {@link from}:
|
|
92
94
|
*
|
|
93
95
|
* ```typescript
|
|
94
96
|
* import * as jssm from './jssm';
|
|
@@ -131,13 +133,15 @@ declare function wrap_parse(input: string, options?: Object): any;
|
|
|
131
133
|
* operator `sm`, and mostly falls back to `.from` when needing to parse
|
|
132
134
|
* strings dynamically instead of from template literals.
|
|
133
135
|
*
|
|
136
|
+
* Operator {@link sm}:
|
|
137
|
+
*
|
|
134
138
|
* ```typescript
|
|
135
139
|
* import { sm } from './jssm';
|
|
136
140
|
*
|
|
137
141
|
* const switch = sm`on <=> off;`;
|
|
138
142
|
* ```
|
|
139
143
|
*
|
|
140
|
-
*
|
|
144
|
+
* Method {@link from}:
|
|
141
145
|
*
|
|
142
146
|
* ```typescript
|
|
143
147
|
* import * as jssm from './jssm';
|
|
@@ -210,6 +214,21 @@ declare class Machine<mDT> {
|
|
|
210
214
|
_any_transition_hook: HookHandler | undefined;
|
|
211
215
|
constructor({ start_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name }: JssmGenericConfig<mDT>);
|
|
212
216
|
_new_state(state_config: JssmGenericState): StateType;
|
|
217
|
+
/*********
|
|
218
|
+
*
|
|
219
|
+
* Get the current state of a machine.
|
|
220
|
+
*
|
|
221
|
+
* ```typescript
|
|
222
|
+
* import * as jssm from './jssm';
|
|
223
|
+
*
|
|
224
|
+
* const switch = jssm.from('on <=> off;');
|
|
225
|
+
* console.log( switch.state() ); // 'on'
|
|
226
|
+
*
|
|
227
|
+
* switch.transition('off');
|
|
228
|
+
* console.log( switch.state() ); // 'off'
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
*/
|
|
213
232
|
state(): StateType;
|
|
214
233
|
state_is_final(whichState: StateType): boolean;
|
|
215
234
|
is_final(): boolean;
|
|
@@ -228,8 +247,35 @@ declare class Machine<mDT> {
|
|
|
228
247
|
state_declarations(): Map<StateType, JssmStateDeclaration>;
|
|
229
248
|
fsl_version(): string;
|
|
230
249
|
machine_state(): JssmMachineInternalState<mDT>;
|
|
250
|
+
/*********
|
|
251
|
+
*
|
|
252
|
+
* List all the states known by the machine. Please note that the order of
|
|
253
|
+
* these states is not guaranteed.
|
|
254
|
+
*
|
|
255
|
+
* ```typescript
|
|
256
|
+
* import * as jssm from './jssm';
|
|
257
|
+
*
|
|
258
|
+
* const switch = jssm.from('on <=> off;');
|
|
259
|
+
* console.log( switch.states() ); // ['on', 'off']
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
231
263
|
states(): Array<StateType>;
|
|
232
264
|
state_for(whichState: StateType): JssmGenericState;
|
|
265
|
+
/*********
|
|
266
|
+
*
|
|
267
|
+
* Check whether the machine knows a given state.
|
|
268
|
+
*
|
|
269
|
+
* ```typescript
|
|
270
|
+
* import * as jssm from './jssm';
|
|
271
|
+
*
|
|
272
|
+
* const switch = jssm.from('on <=> off;');
|
|
273
|
+
|
|
274
|
+
* console.log( switch.has_state('off') ); // true
|
|
275
|
+
* console.log( switch.has_state('dance') ); // false
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
*/
|
|
233
279
|
has_state(whichState: StateType): boolean;
|
|
234
280
|
list_edges(): Array<JssmTransition<mDT>>;
|
|
235
281
|
list_named_transitions(): Map<StateType, number>;
|
|
@@ -281,6 +327,39 @@ declare class Machine<mDT> {
|
|
|
281
327
|
instance_name(): string | undefined;
|
|
282
328
|
sm(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
283
329
|
}
|
|
330
|
+
/*********
|
|
331
|
+
*
|
|
332
|
+
* Create a state machine from a template string. This is one of the two main
|
|
333
|
+
* paths for working with JSSM, alongside {@link from}.
|
|
334
|
+
*
|
|
335
|
+
* Use this method when you want to work directly and conveniently with a
|
|
336
|
+
* constant template expression. Use `.from` when you want to pull from
|
|
337
|
+
* dynamic strings.
|
|
338
|
+
*
|
|
339
|
+
*
|
|
340
|
+
* ```typescript
|
|
341
|
+
* import * as jssm from './jssm';
|
|
342
|
+
*
|
|
343
|
+
* const switch = jssm.from('on <=> off;');
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
*/
|
|
284
347
|
declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: any[]): Machine<mDT>;
|
|
348
|
+
/*********
|
|
349
|
+
*
|
|
350
|
+
* Create a state machine from an implementation string. This is one of the
|
|
351
|
+
* two main paths for working with JSSM, alongside {@link sm}.
|
|
352
|
+
*
|
|
353
|
+
* Use this method when you want to conveniently pull a state machine from a
|
|
354
|
+
* string dynamically. Use operator `sm` when you just want to work with a
|
|
355
|
+
* template expression.
|
|
356
|
+
*
|
|
357
|
+
* ```typescript
|
|
358
|
+
* import * as jssm from './jssm';
|
|
359
|
+
*
|
|
360
|
+
* const switch = jssm.from('on <=> off;');
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
363
|
+
*/
|
|
285
364
|
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
|
|
286
365
|
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors };
|
package/dist/es6/jssm.js
CHANGED
|
@@ -253,13 +253,15 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
|
|
|
253
253
|
* operator `sm`, and mostly falls back to `.from` when needing to parse
|
|
254
254
|
* strings dynamically instead of from template literals.
|
|
255
255
|
*
|
|
256
|
+
* Operator {@link sm}:
|
|
257
|
+
*
|
|
256
258
|
* ```typescript
|
|
257
259
|
* import { sm } from './jssm';
|
|
258
260
|
*
|
|
259
261
|
* const switch = sm`on <=> off;`;
|
|
260
262
|
* ```
|
|
261
263
|
*
|
|
262
|
-
*
|
|
264
|
+
* Method {@link from}:
|
|
263
265
|
*
|
|
264
266
|
* ```typescript
|
|
265
267
|
* import * as jssm from './jssm';
|
|
@@ -376,13 +378,15 @@ function compile_rule_handler(rule) {
|
|
|
376
378
|
* operator `sm`, and mostly falls back to `.from` when needing to parse
|
|
377
379
|
* strings dynamically instead of from template literals.
|
|
378
380
|
*
|
|
381
|
+
* Operator {@link sm}:
|
|
382
|
+
*
|
|
379
383
|
* ```typescript
|
|
380
384
|
* import { sm } from './jssm';
|
|
381
385
|
*
|
|
382
386
|
* const switch = sm`on <=> off;`;
|
|
383
387
|
* ```
|
|
384
388
|
*
|
|
385
|
-
*
|
|
389
|
+
* Method {@link from}:
|
|
386
390
|
*
|
|
387
391
|
* ```typescript
|
|
388
392
|
* import * as jssm from './jssm';
|
|
@@ -646,6 +650,21 @@ class Machine {
|
|
|
646
650
|
this._states.set(state_config.name, state_config);
|
|
647
651
|
return state_config.name;
|
|
648
652
|
}
|
|
653
|
+
/*********
|
|
654
|
+
*
|
|
655
|
+
* Get the current state of a machine.
|
|
656
|
+
*
|
|
657
|
+
* ```typescript
|
|
658
|
+
* import * as jssm from './jssm';
|
|
659
|
+
*
|
|
660
|
+
* const switch = jssm.from('on <=> off;');
|
|
661
|
+
* console.log( switch.state() ); // 'on'
|
|
662
|
+
*
|
|
663
|
+
* switch.transition('off');
|
|
664
|
+
* console.log( switch.state() ); // 'off'
|
|
665
|
+
* ```
|
|
666
|
+
*
|
|
667
|
+
*/
|
|
649
668
|
state() {
|
|
650
669
|
return this._state;
|
|
651
670
|
}
|
|
@@ -723,6 +742,19 @@ class Machine {
|
|
|
723
742
|
return false; // todo whargarbl
|
|
724
743
|
}
|
|
725
744
|
*/
|
|
745
|
+
/*********
|
|
746
|
+
*
|
|
747
|
+
* List all the states known by the machine. Please note that the order of
|
|
748
|
+
* these states is not guaranteed.
|
|
749
|
+
*
|
|
750
|
+
* ```typescript
|
|
751
|
+
* import * as jssm from './jssm';
|
|
752
|
+
*
|
|
753
|
+
* const switch = jssm.from('on <=> off;');
|
|
754
|
+
* console.log( switch.states() ); // ['on', 'off']
|
|
755
|
+
* ```
|
|
756
|
+
*
|
|
757
|
+
*/
|
|
726
758
|
states() {
|
|
727
759
|
return Array.from(this._states.keys());
|
|
728
760
|
}
|
|
@@ -735,6 +767,20 @@ class Machine {
|
|
|
735
767
|
throw new JssmError(this, 'No such state', { requested_state: whichState });
|
|
736
768
|
}
|
|
737
769
|
}
|
|
770
|
+
/*********
|
|
771
|
+
*
|
|
772
|
+
* Check whether the machine knows a given state.
|
|
773
|
+
*
|
|
774
|
+
* ```typescript
|
|
775
|
+
* import * as jssm from './jssm';
|
|
776
|
+
*
|
|
777
|
+
* const switch = jssm.from('on <=> off;');
|
|
778
|
+
|
|
779
|
+
* console.log( switch.has_state('off') ); // true
|
|
780
|
+
* console.log( switch.has_state('dance') ); // false
|
|
781
|
+
* ```
|
|
782
|
+
*
|
|
783
|
+
*/
|
|
738
784
|
has_state(whichState) {
|
|
739
785
|
return this._states.get(whichState) !== undefined;
|
|
740
786
|
}
|
|
@@ -1195,6 +1241,23 @@ class Machine {
|
|
|
1195
1241
|
return sm(template_strings, ...remainder);
|
|
1196
1242
|
}
|
|
1197
1243
|
}
|
|
1244
|
+
/*********
|
|
1245
|
+
*
|
|
1246
|
+
* Create a state machine from a template string. This is one of the two main
|
|
1247
|
+
* paths for working with JSSM, alongside {@link from}.
|
|
1248
|
+
*
|
|
1249
|
+
* Use this method when you want to work directly and conveniently with a
|
|
1250
|
+
* constant template expression. Use `.from` when you want to pull from
|
|
1251
|
+
* dynamic strings.
|
|
1252
|
+
*
|
|
1253
|
+
*
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* import * as jssm from './jssm';
|
|
1256
|
+
*
|
|
1257
|
+
* const switch = jssm.from('on <=> off;');
|
|
1258
|
+
* ```
|
|
1259
|
+
*
|
|
1260
|
+
*/
|
|
1198
1261
|
function sm(template_strings, ...remainder /* , arguments */) {
|
|
1199
1262
|
// foo`a${1}b${2}c` will come in as (['a','b','c'],1,2)
|
|
1200
1263
|
// this includes when a and c are empty strings
|
|
@@ -1208,6 +1271,22 @@ function sm(template_strings, ...remainder /* , arguments */) {
|
|
|
1208
1271
|
/* eslint-enable prefer-rest-params */
|
|
1209
1272
|
)));
|
|
1210
1273
|
}
|
|
1274
|
+
/*********
|
|
1275
|
+
*
|
|
1276
|
+
* Create a state machine from an implementation string. This is one of the
|
|
1277
|
+
* two main paths for working with JSSM, alongside {@link sm}.
|
|
1278
|
+
*
|
|
1279
|
+
* Use this method when you want to conveniently pull a state machine from a
|
|
1280
|
+
* string dynamically. Use operator `sm` when you just want to work with a
|
|
1281
|
+
* template expression.
|
|
1282
|
+
*
|
|
1283
|
+
* ```typescript
|
|
1284
|
+
* import * as jssm from './jssm';
|
|
1285
|
+
*
|
|
1286
|
+
* const switch = jssm.from('on <=> off;');
|
|
1287
|
+
* ```
|
|
1288
|
+
*
|
|
1289
|
+
*/
|
|
1211
1290
|
function from(MachineAsString, ExtraConstructorFields) {
|
|
1212
1291
|
const to_decorate = make(MachineAsString);
|
|
1213
1292
|
if (ExtraConstructorFields !== undefined) {
|
package/dist/es6/jssm_util.d.ts
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
3
|
+
* Predicate for validating an array for uniqueness. Not generally meant for
|
|
4
|
+
* external use.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
1
7
|
declare function arr_uniq_p<T>(el: T, i: number, source: T[]): boolean;
|
|
2
8
|
declare const array_box_if_string: (n: any) => any;
|
|
3
9
|
declare const weighted_rand_select: Function;
|
|
4
|
-
|
|
10
|
+
/*******
|
|
11
|
+
*
|
|
12
|
+
* Returns, for a non-negative integer argument `n`, the series `[0 .. n]`.
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { seq } from './jssm';
|
|
16
|
+
*
|
|
17
|
+
* seq(5); // [0, 1, 2, 3, 4]
|
|
18
|
+
* seq(0); // []
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
declare function seq(n: number): number[];
|
|
23
|
+
/*******
|
|
24
|
+
*
|
|
25
|
+
* Returns the histograph of an array as a `Map`. Makes no attempt to cope
|
|
26
|
+
* with deep equality; will fail for complex contents, as such.
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { histograph } from './jssm';
|
|
30
|
+
*
|
|
31
|
+
* histograph( [0, 0, 1, 1, 2, 2, 1] ); // Map()
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
5
35
|
declare const histograph: Function;
|
|
6
36
|
declare const weighted_sample_select: Function;
|
|
7
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
|
+
*/
|
|
8
44
|
declare const hook_name: (from: string, to: string) => string;
|
|
45
|
+
/*******
|
|
46
|
+
*
|
|
47
|
+
* Internal method generating names for actions for the hook lookup map. Not
|
|
48
|
+
* meant for external use.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
9
51
|
declare const named_hook_name: (from: string, to: string, action: string) => string;
|
|
10
52
|
export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name };
|
package/dist/es6/jssm_util.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/*******
|
|
2
|
+
*
|
|
3
|
+
* Predicate for validating an array for uniqueness. Not generally meant for
|
|
4
|
+
* external use.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
1
7
|
function arr_uniq_p(el, i, source) {
|
|
2
8
|
return source.indexOf(el) === i;
|
|
3
9
|
}
|
|
@@ -17,8 +23,41 @@ const weighted_rand_select = (options, probability_property = 'probability') =>
|
|
|
17
23
|
return options[cursor - 1];
|
|
18
24
|
};
|
|
19
25
|
/* eslint-enable flowtype/no-weak-types */
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
/*******
|
|
27
|
+
*
|
|
28
|
+
* Returns, for a non-negative integer argument `n`, the series `[0 .. n]`.
|
|
29
|
+
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { seq } from './jssm';
|
|
32
|
+
*
|
|
33
|
+
* seq(5); // [0, 1, 2, 3, 4]
|
|
34
|
+
* seq(0); // []
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
function seq(n) {
|
|
39
|
+
if (!(Number.isInteger(n))) {
|
|
40
|
+
throw new TypeError('seq/1 takes a non-negative integer n as an argument');
|
|
41
|
+
}
|
|
42
|
+
if (n < 0) {
|
|
43
|
+
throw new TypeError('seq/1 takes a non-negative integer n as an argument');
|
|
44
|
+
}
|
|
45
|
+
return (new Array(n))
|
|
46
|
+
.fill(true)
|
|
47
|
+
.map((_, i) => i);
|
|
48
|
+
}
|
|
49
|
+
/*******
|
|
50
|
+
*
|
|
51
|
+
* Returns the histograph of an array as a `Map`. Makes no attempt to cope
|
|
52
|
+
* with deep equality; will fail for complex contents, as such.
|
|
53
|
+
*
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { histograph } from './jssm';
|
|
56
|
+
*
|
|
57
|
+
* histograph( [0, 0, 1, 1, 2, 2, 1] ); // Map()
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
22
61
|
const histograph = (ar) => // eslint-disable-line flowtype/no-weak-types
|
|
23
62
|
ar.sort()
|
|
24
63
|
.reduce((m, v) => // TODO FIXME eslint-disable-line flowtype/no-weak-types,no-sequences
|
|
@@ -31,6 +70,18 @@ const weighted_histo_key = (n, opts, prob_prop, extract) => // TODO FIXME no any
|
|
|
31
70
|
histograph(weighted_sample_select(n, opts, prob_prop)
|
|
32
71
|
.map((s) => s[extract] // TODO FIXME eslint-disable-line flowtype/no-weak-types
|
|
33
72
|
));
|
|
73
|
+
/*******
|
|
74
|
+
*
|
|
75
|
+
* Internal method generating names for edges for the hook lookup map. Not
|
|
76
|
+
* meant for external use.
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
34
79
|
const hook_name = (from, to) => JSON.stringify([from, to]);
|
|
80
|
+
/*******
|
|
81
|
+
*
|
|
82
|
+
* Internal method generating names for actions for the hook lookup map. Not
|
|
83
|
+
* meant for external use.
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
35
86
|
const named_hook_name = (from, to, action) => JSON.stringify([from, to, action]);
|
|
36
87
|
export { seq, arr_uniq_p, histograph, weighted_histo_key, weighted_rand_select, weighted_sample_select, array_box_if_string, hook_name, named_hook_name };
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.65.
|
|
1
|
+
const version = "5.65.7";
|
|
2
2
|
export { version };
|