@ondoher/enigma 1.0.3 → 1.0.6

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.
Files changed (46) hide show
  1. package/README.md +72 -46
  2. package/dist/index.d.ts +899 -0
  3. package/jsconfig.json +2 -2
  4. package/lib/enigma/Encoder.js +52 -18
  5. package/lib/enigma/Enigma.js +10 -9
  6. package/lib/enigma/EnigmaTypes.d.ts +17 -12
  7. package/lib/enigma/PlugBoard.js +1 -1
  8. package/lib/enigma/Reflector.js +1 -1
  9. package/lib/enigma/Rotor.js +3 -2
  10. package/lib/enigma/index.js +1 -1
  11. package/lib/enigma/tests/EnigmaSpec.js +5 -5
  12. package/lib/generator/CodeBook.js +3 -3
  13. package/lib/generator/Generator.js +5 -4
  14. package/lib/generator/GeneratorTypes.d.ts +2 -1
  15. package/lib/utils/Random.js +1 -1
  16. package/package.json +7 -2
  17. package/scripts/EnigmaData.js +236 -0
  18. package/scripts/hamlet.html +8880 -0
  19. package/scripts/make-validated-data.js +4 -0
  20. package/scripts/parseHamlet.js +32 -0
  21. package/scripts/test-messages.js +60 -0
  22. package/scripts/test.js +118 -0
  23. package/scripts/x +6446 -0
  24. package/tsconfig.json +19 -0
  25. package/types/enigma/Encoder.d.ts +128 -0
  26. package/types/enigma/Enigma.d.ts +88 -0
  27. package/types/enigma/EntryDisc.d.ts +17 -0
  28. package/types/enigma/Inventory.d.ts +91 -0
  29. package/types/enigma/PlugBoard.d.ts +26 -0
  30. package/types/enigma/Reflector.d.ts +14 -0
  31. package/types/enigma/Rotor.d.ts +59 -0
  32. package/types/enigma/consts.d.ts +1 -0
  33. package/types/enigma/index.d.ts +5 -0
  34. package/types/enigma/standardInventory.d.ts +71 -0
  35. package/types/enigma/tests/EnigmaData.d.ts +46 -0
  36. package/types/enigma/tests/EnigmaSpec.d.ts +1 -0
  37. package/types/enigma/tests/PlugBoardData.d.ts +4 -0
  38. package/types/enigma/tests/PlugBoardSpec.d.ts +1 -0
  39. package/types/enigma/tests/RotorData.d.ts +15 -0
  40. package/types/enigma/tests/RotorSpec.d.ts +1 -0
  41. package/types/generator/CodeBook.d.ts +82 -0
  42. package/types/generator/Generator.d.ts +67 -0
  43. package/types/generator/hamlet.d.ts +2 -0
  44. package/types/generator/index.d.ts +3 -0
  45. package/types/index.d.ts +899 -0
  46. package/types/utils/Random.d.ts +131 -0
package/README.md CHANGED
@@ -66,17 +66,83 @@ will be passed to every constructed component.
66
66
 
67
67
  The signature of this callback should look like this:
68
68
 
69
- `function (event, name, message, info)`
69
+ ---
70
+ `function (event, name, data)`
71
+
72
+ #### **Parameters**
73
+ - **event** - which event is being fired.
74
+ - **name** - the name of the component that has fired this event
75
+ - **data** - an object that contains information relevant to the event
76
+
77
+ ### **Event Types**
78
+ There are five different events, they are.
79
+ - **input** - fired when any component receives a signal
80
+ - **output** - fired when any component sends a signal
81
+ - **translate** - fired when a component outputs a signal, contains information
82
+ about both the input and the output
83
+ - **step** - fired when a rotor steps
84
+ - **double-step** - fired when a rotor performs the double step.
85
+
86
+ ### Common
87
+
88
+ Every event contains these parameters,
89
+
90
+ - **name** - contains the name of the component sending the event
91
+ - **type** - the type of component sending the event. This is one of *Entry Wheel*,
92
+ *Plugboard*, *Reflector*, *Rotor* and *Enigma*
93
+ - **description** - a human readable string that details the event
94
+ - **direction** - this is not sent for all events, but is for *input*, *output*,
95
+ and *translate*, it is one of:
96
+
97
+ - **right** - this is the direction the translation starts until it hits
98
+ the reflector
99
+ - **left** - this is the direction translation happens after going through
100
+ the reflector.
101
+ - **turn-around** - sent by the reflector
102
+ - **end-to-end** - sent by the Enigma
103
+
104
+
105
+ ### input
106
+ This event is fired when any component receives a signal. In addition to the
107
+ common fields, the data object contains these fields:
108
+
109
+ - **input** - this is the input value, it can be either a string or a number
70
110
 
71
- ### **Parameters**
72
- - **event** a string that identifies the specific action being taken.
73
- - **name** the name of the class instance that has fired this event
74
- - **message** a string that describes the event taking place
75
- - **info** an object that contains information relevant to the event
111
+ ### output
112
+
113
+ This event is fired sent when any component sends a signal. In addition to the
114
+ common fields, the data object contains these fields:
115
+
116
+ - **output** - this is the output value, it can be either a string or a number
117
+
118
+ ### translate
119
+
120
+ This event is fired when a component outputs a signal, contains information
121
+ about both the input and the output. In addition to the common fields, the data
122
+ object contains these fields:
123
+
124
+ - **input** - this is the input value, it can be either a string or a number
125
+ - **output** - this is the output value, it can be either a string or a number
126
+
127
+ ### step
128
+
129
+ This event is fired when a rotor steps. In addition to the common fields, the
130
+ data object contains these fields:
131
+
132
+ - **start** - the staring position of the rotor
133
+ - **stop** - the ending position of the rotor
134
+ - **turnover** - true if the the stepping reached the turnover point
76
135
 
77
136
  The specific events and data are defined in the class documentation that
78
137
  follows.
79
138
 
139
+ ### double-step
140
+
141
+ This event is fired when a rotor performs the double step. In addition to the
142
+ common fields, the data object contains these fields:
143
+
144
+ - **offset** - the new position of the rotor
145
+
80
146
  ## PlugBoard
81
147
  Create an instance of this class to simulate the plug board component of an
82
148
  Enigma.
@@ -123,16 +189,6 @@ Call this method to encode a value in the given direction, right vs left.
123
189
  #### **Returns**
124
190
  the output connector
125
191
 
126
- #### **Events**
127
-
128
- `encode-right, encode-left`
129
-
130
- These events will be fired during encoding. The info parameter will have these
131
- fields.
132
-
133
- - **input** the number of the connector that received input
134
- - **output** the number of the connector for the encoded value
135
-
136
192
  ## Rotor
137
193
 
138
194
  Create an instance of this class to construct a Rotor object. The Rotor class
@@ -277,16 +333,6 @@ between a left and right signal path.
277
333
  #### **Returns**
278
334
  the output connector
279
335
 
280
- ### **Events**
281
-
282
- `encode`
283
-
284
- This event will be fired during encoding. The info parameter will have these
285
- fields.
286
-
287
- - **input** the number of the connector that received input
288
- - **output** the number of the connector for the encoded value
289
-
290
336
  ## Enigma
291
337
 
292
338
  Create an instance of this class to construct a full Enigma.
@@ -379,26 +425,6 @@ Call this method to encode a whole string.
379
425
  the encoded string. Passing the result of this method back through the encode
380
426
  method should produce the original text.
381
427
 
382
- ### **Events**
383
-
384
- In addition to firing all the events from its components, the Enigma will also
385
- fire these events.
386
-
387
- `input`
388
-
389
- This is fired at the beginning of encoding each letter. It is fired after
390
- verifying the letter, but before stepping. The info parameter contains these
391
- fields.
392
-
393
- - **letter** the letter to be encoded
394
-
395
- `output`
396
-
397
- This is fired after encoding each letter. The info parameter contains these
398
- fields.
399
-
400
- - **letter** the encoded letter.
401
-
402
428
  ## **Properties**
403
429
 
404
430
  `configuration`