jssm 5.65.0 → 5.65.3

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.
@@ -4,12 +4,164 @@ JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmAr
4
4
  import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
5
5
  import { shapes, gviz_shapes, named_colors } from './jssm_constants';
6
6
  import { version } from './version';
7
+ /*********
8
+ *
9
+ * Return the direction of an arrow - `right`, `left`, or `both`.
10
+ *
11
+ * ```typescript
12
+ * import { arrow_direction } from './jssm';
13
+ *
14
+ * arrow_direction('->'); // 'right'
15
+ * arrow_direction('<~=>'); // 'both'
16
+ * ```
17
+ *
18
+ */
7
19
  declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
20
+ /*********
21
+ *
22
+ * Return the direction of an arrow - `right`, `left`, or `both`.
23
+ *
24
+ * ```typescript
25
+ * import { arrow_left_kind } from './jssm';
26
+ *
27
+ * arrow_left_kind('<-'); // 'legal'
28
+ * arrow_left_kind('<='); // 'main'
29
+ * arrow_left_kind('<~'); // 'forced'
30
+ * arrow_left_kind('<->'); // 'legal'
31
+ * arrow_left_kind('->'); // 'none'
32
+ * ```
33
+ *
34
+ */
8
35
  declare function arrow_left_kind(arrow: JssmArrow): JssmArrowKind;
36
+ /*********
37
+ *
38
+ * Return the direction of an arrow - `right`, `left`, or `both`.
39
+ *
40
+ * ```typescript
41
+ * import { arrow_left_kind } from './jssm';
42
+ *
43
+ * arrow_left_kind('->'); // 'legal'
44
+ * arrow_left_kind('=>'); // 'main'
45
+ * arrow_left_kind('~>'); // 'forced'
46
+ * arrow_left_kind('<->'); // 'legal'
47
+ * arrow_left_kind('<-'); // 'none'
48
+ * ```
49
+ *
50
+ */
9
51
  declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
52
+ /*********
53
+ *
54
+ * This method wraps the parser call that comes from the peg grammar,
55
+ * {@link parse}. Generally neither this nor that should be used directly
56
+ * unless you mean to develop plugins or extensions for the machine.
57
+ *
58
+ * Parses the intermediate representation of a compiled string down to a
59
+ * machine configuration object. If you're using this (probably don't,) you're
60
+ * probably also using {@link compile} and {@link Machine.constructor}.
61
+ *
62
+ * ```typescript
63
+ * import { parse, compile, Machine } from './jssm';
64
+ *
65
+ * const intermediate = wrap_parse('a -> b;', {});
66
+ * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
67
+ *
68
+ * const cfg = compile(intermediate);
69
+ * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
70
+ *
71
+ * const machine = new Machine(cfg);
72
+ * // Machine { _instance_name: undefined, _state: 'a', ...
73
+ * ```
74
+ *
75
+ * This method is mostly for plugin and intermediate tool authors, or people
76
+ * who need to work with the machine's intermediate representation.
77
+ *
78
+ * # Hey!
79
+ *
80
+ * Most people looking at this want either the `sm` operator or method `from`,
81
+ * which perform all the steps in the chain. The library's author mostly uses
82
+ * operator `sm`, and mostly falls back to `.from` when needing to parse
83
+ * strings dynamically instead of from template literals.
84
+ *
85
+ * ```typescript
86
+ * import { sm } from './jssm';
87
+ *
88
+ * const switch = sm`on <=> off;`;
89
+ * ```
90
+ *
91
+ * &hellip; or &hellip;
92
+ *
93
+ * ```typescript
94
+ * import * as jssm from './jssm';
95
+ *
96
+ * const toggle = jssm.from('up <=> down;');
97
+ * ```
98
+ *
99
+ * `wrap_parse` itself is an internal convenience method for alting out an
100
+ * object as the options call. Not generally meant for external use.
101
+ *
102
+ */
10
103
  declare function wrap_parse(input: string, options?: Object): any;
104
+ /*********
105
+ *
106
+ * Compile a machine's JSON intermediate representation to a config object. If
107
+ * you're using this (probably don't,) you're probably also using
108
+ * {@link parse} to get the IR, and the object constructor
109
+ * {@link Machine.construct} to turn the config object into a workable machine.
110
+ *
111
+ * ```typescript
112
+ * import { parse, compile, Machine } from './jssm';
113
+ *
114
+ * const intermediate = parse('a -> b;');
115
+ * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
116
+ *
117
+ * const cfg = compile(intermediate);
118
+ * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
119
+ *
120
+ * const machine = new Machine(cfg);
121
+ * // Machine { _instance_name: undefined, _state: 'a', ...
122
+ * ```
123
+ *
124
+ * This method is mostly for plugin and intermediate tool authors, or people
125
+ * who need to work with the machine's intermediate representation.
126
+ *
127
+ * # Hey!
128
+ *
129
+ * Most people looking at this want either the `sm` operator or method `from`,
130
+ * which perform all the steps in the chain. The library's author mostly uses
131
+ * operator `sm`, and mostly falls back to `.from` when needing to parse
132
+ * strings dynamically instead of from template literals.
133
+ *
134
+ * ```typescript
135
+ * import { sm } from './jssm';
136
+ *
137
+ * const switch = sm`on <=> off;`;
138
+ * ```
139
+ *
140
+ * &hellip; or &hellip;
141
+ *
142
+ * ```typescript
143
+ * import * as jssm from './jssm';
144
+ *
145
+ * const toggle = jssm.from('up <=> down;');
146
+ * ```
147
+ *
148
+ */
11
149
  declare function compile<mDT>(tree: JssmParseTree): JssmGenericConfig<mDT>;
150
+ /*********
151
+ *
152
+ * An internal convenience wrapper for parsing then compiling a machine string.
153
+ * Not generally meant for external use. Please see {@link compile} or
154
+ * {@link sm}.
155
+ *
156
+ */
12
157
  declare function make<mDT>(plan: string): JssmGenericConfig<mDT>;
158
+ /*********
159
+ *
160
+ * An internal method meant to take a series of declarations and fold them into
161
+ * a single multi-faceted declaration, in the process of building a state. Not
162
+ * generally meant for external use.
163
+ *
164
+ */
13
165
  declare function transfer_state_properties(state_decl: JssmStateDeclaration): JssmStateDeclaration;
14
166
  declare class Machine<mDT> {
15
167
  _state: StateType;
package/dist/es6/jssm.js CHANGED
@@ -6,6 +6,18 @@ import { parse } from './jssm-dot';
6
6
  import { version } from './version'; // replaced from package.js in build
7
7
  import { JssmError } from './jssm_error';
8
8
  /* eslint-disable complexity */
9
+ /*********
10
+ *
11
+ * Return the direction of an arrow - `right`, `left`, or `both`.
12
+ *
13
+ * ```typescript
14
+ * import { arrow_direction } from './jssm';
15
+ *
16
+ * arrow_direction('->'); // 'right'
17
+ * arrow_direction('<~=>'); // 'both'
18
+ * ```
19
+ *
20
+ */
9
21
  function arrow_direction(arrow) {
10
22
  switch (String(arrow)) {
11
23
  case '->':
@@ -59,6 +71,21 @@ function arrow_direction(arrow) {
59
71
  }
60
72
  /* eslint-enable complexity */
61
73
  /* eslint-disable complexity */
74
+ /*********
75
+ *
76
+ * Return the direction of an arrow - `right`, `left`, or `both`.
77
+ *
78
+ * ```typescript
79
+ * import { arrow_left_kind } from './jssm';
80
+ *
81
+ * arrow_left_kind('<-'); // 'legal'
82
+ * arrow_left_kind('<='); // 'main'
83
+ * arrow_left_kind('<~'); // 'forced'
84
+ * arrow_left_kind('<->'); // 'legal'
85
+ * arrow_left_kind('->'); // 'none'
86
+ * ```
87
+ *
88
+ */
62
89
  function arrow_left_kind(arrow) {
63
90
  switch (String(arrow)) {
64
91
  case '->':
@@ -101,6 +128,21 @@ function arrow_left_kind(arrow) {
101
128
  }
102
129
  /* eslint-enable complexity */
103
130
  /* eslint-disable complexity */
131
+ /*********
132
+ *
133
+ * Return the direction of an arrow - `right`, `left`, or `both`.
134
+ *
135
+ * ```typescript
136
+ * import { arrow_left_kind } from './jssm';
137
+ *
138
+ * arrow_left_kind('->'); // 'legal'
139
+ * arrow_left_kind('=>'); // 'main'
140
+ * arrow_left_kind('~>'); // 'forced'
141
+ * arrow_left_kind('<->'); // 'legal'
142
+ * arrow_left_kind('<-'); // 'none'
143
+ * ```
144
+ *
145
+ */
104
146
  function arrow_right_kind(arrow) {
105
147
  switch (String(arrow)) {
106
148
  case '<-':
@@ -142,6 +184,12 @@ function arrow_right_kind(arrow) {
142
184
  }
143
185
  }
144
186
  /* eslint-enable complexity */
187
+ /*********
188
+ *
189
+ * Internal method meant to perform factory assembly of an edge. Not meant for
190
+ * external use.
191
+ *
192
+ */
145
193
  function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
146
194
  const kind = isRight ? arrow_right_kind(this_se.kind) : arrow_left_kind(this_se.kind), edge = {
147
195
  from,
@@ -172,9 +220,66 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
172
220
  }
173
221
  return edge;
174
222
  }
223
+ /*********
224
+ *
225
+ * This method wraps the parser call that comes from the peg grammar,
226
+ * {@link parse}. Generally neither this nor that should be used directly
227
+ * unless you mean to develop plugins or extensions for the machine.
228
+ *
229
+ * Parses the intermediate representation of a compiled string down to a
230
+ * machine configuration object. If you're using this (probably don't,) you're
231
+ * probably also using {@link compile} and {@link Machine.constructor}.
232
+ *
233
+ * ```typescript
234
+ * import { parse, compile, Machine } from './jssm';
235
+ *
236
+ * const intermediate = wrap_parse('a -> b;', {});
237
+ * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
238
+ *
239
+ * const cfg = compile(intermediate);
240
+ * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
241
+ *
242
+ * const machine = new Machine(cfg);
243
+ * // Machine { _instance_name: undefined, _state: 'a', ...
244
+ * ```
245
+ *
246
+ * This method is mostly for plugin and intermediate tool authors, or people
247
+ * who need to work with the machine's intermediate representation.
248
+ *
249
+ * # Hey!
250
+ *
251
+ * Most people looking at this want either the `sm` operator or method `from`,
252
+ * which perform all the steps in the chain. The library's author mostly uses
253
+ * operator `sm`, and mostly falls back to `.from` when needing to parse
254
+ * strings dynamically instead of from template literals.
255
+ *
256
+ * ```typescript
257
+ * import { sm } from './jssm';
258
+ *
259
+ * const switch = sm`on <=> off;`;
260
+ * ```
261
+ *
262
+ * &hellip; or &hellip;
263
+ *
264
+ * ```typescript
265
+ * import * as jssm from './jssm';
266
+ *
267
+ * const toggle = jssm.from('up <=> down;');
268
+ * ```
269
+ *
270
+ * `wrap_parse` itself is an internal convenience method for alting out an
271
+ * object as the options call. Not generally meant for external use.
272
+ *
273
+ */
175
274
  function wrap_parse(input, options) {
176
275
  return parse(input, options || {});
177
276
  }
277
+ /*********
278
+ *
279
+ * Internal method performing one step in compiling rules for transitions. Not
280
+ * generally meant for external use.
281
+ *
282
+ */
178
283
  function compile_rule_transition_step(acc, from, to, this_se, next_se) {
179
284
  const edges = [];
180
285
  const uFrom = (Array.isArray(from) ? from : [from]), uTo = (Array.isArray(to) ? to : [to]);
@@ -198,9 +303,21 @@ function compile_rule_transition_step(acc, from, to, this_se, next_se) {
198
303
  return new_acc;
199
304
  }
200
305
  }
306
+ /*********
307
+ *
308
+ * Internal method performing one step in compiling rules for transitions. Not
309
+ * generally meant for external use.
310
+ *
311
+ */
201
312
  function compile_rule_handle_transition(rule) {
202
313
  return compile_rule_transition_step([], rule.from, rule.se.to, rule.se, rule.se.se);
203
314
  }
315
+ /*********
316
+ *
317
+ * Internal method performing one step in compiling rules for transitions. Not
318
+ * generally meant for external use.
319
+ *
320
+ */
204
321
  function compile_rule_handler(rule) {
205
322
  if (rule.key === 'transition') {
206
323
  return { agg_as: 'transition', val: compile_rule_handle_transition(rule) };
@@ -229,6 +346,51 @@ function compile_rule_handler(rule) {
229
346
  }
230
347
  throw new JssmError(undefined, `compile_rule_handler: Unknown rule: ${JSON.stringify(rule)}`);
231
348
  }
349
+ /*********
350
+ *
351
+ * Compile a machine's JSON intermediate representation to a config object. If
352
+ * you're using this (probably don't,) you're probably also using
353
+ * {@link parse} to get the IR, and the object constructor
354
+ * {@link Machine.construct} to turn the config object into a workable machine.
355
+ *
356
+ * ```typescript
357
+ * import { parse, compile, Machine } from './jssm';
358
+ *
359
+ * const intermediate = parse('a -> b;');
360
+ * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
361
+ *
362
+ * const cfg = compile(intermediate);
363
+ * // { start_states:['a'], transitions: [{ from:'a', to:'b', kind:'legal', forced_only:false, main_path:false }] }
364
+ *
365
+ * const machine = new Machine(cfg);
366
+ * // Machine { _instance_name: undefined, _state: 'a', ...
367
+ * ```
368
+ *
369
+ * This method is mostly for plugin and intermediate tool authors, or people
370
+ * who need to work with the machine's intermediate representation.
371
+ *
372
+ * # Hey!
373
+ *
374
+ * Most people looking at this want either the `sm` operator or method `from`,
375
+ * which perform all the steps in the chain. The library's author mostly uses
376
+ * operator `sm`, and mostly falls back to `.from` when needing to parse
377
+ * strings dynamically instead of from template literals.
378
+ *
379
+ * ```typescript
380
+ * import { sm } from './jssm';
381
+ *
382
+ * const switch = sm`on <=> off;`;
383
+ * ```
384
+ *
385
+ * &hellip; or &hellip;
386
+ *
387
+ * ```typescript
388
+ * import * as jssm from './jssm';
389
+ *
390
+ * const toggle = jssm.from('up <=> down;');
391
+ * ```
392
+ *
393
+ */
232
394
  function compile(tree) {
233
395
  const results = {
234
396
  graph_layout: [],
@@ -286,9 +448,23 @@ function compile(tree) {
286
448
  });
287
449
  return result_cfg;
288
450
  }
451
+ /*********
452
+ *
453
+ * An internal convenience wrapper for parsing then compiling a machine string.
454
+ * Not generally meant for external use. Please see {@link compile} or
455
+ * {@link sm}.
456
+ *
457
+ */
289
458
  function make(plan) {
290
459
  return compile(wrap_parse(plan));
291
460
  }
461
+ /*********
462
+ *
463
+ * An internal method meant to take a series of declarations and fold them into
464
+ * a single multi-faceted declaration, in the process of building a state. Not
465
+ * generally meant for external use.
466
+ *
467
+ */
292
468
  function transfer_state_properties(state_decl) {
293
469
  state_decl.declarations.map((d) => {
294
470
  switch (d.key) {
@@ -1,2 +1,2 @@
1
- const version = "5.65.0";
1
+ const version = "5.65.3";
2
2
  export { version };