rockstar-strudel 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -51,6 +51,11 @@ const pro = await rockstar_pro`
51
51
  // Fully stringified values for speech/text workflows
52
52
  // pro.text_output === ["hello world", ["12", ["my dreams", "7"]]]
53
53
 
54
+ // Sanitized source tokens for Shaba/Shabda speech sample names
55
+ // pro.speech === ["say_hello_world", "shout__012_my_dreams_007_"]
56
+ // Use in Strudel as:
57
+ // samples('shabda/speech:'+pro.speech.join(','))
58
+
54
59
  // Raw callback lines from WASM
55
60
  // pro.raw_output keeps trailing newlines exactly as emitted
56
61
 
@@ -104,6 +109,8 @@ Tagged-template function with richer parallel output views:
104
109
  - `output`: numeric-first values (`number` or nested numeric arrays).
105
110
  - `mixed_output`: mixed typed values with words preserved.
106
111
  - `text_output`: fully stringified values for text/speech use.
112
+ - `speech`: sanitized line tokens derived from source code for Shabda speech
113
+ sample lookup (for example `samples('shabda/speech:'+prog.speech.join(','))`).
107
114
  - `templateValues`: the interpolation values used for this run.
108
115
  - `rerun(...values)`: run the same template again, replacing interpolation
109
116
  values positionally. Calling `rerun()` with no arguments repeats the same run.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rockstar-strudel",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Run Rockstar lang programs via the Starship WASM engine, returning output as a JS array. Designed for use in the strudel.cc live-coding REPL.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -482,6 +482,7 @@ export async function rockstar(strings, ...values) {
482
482
  * output: Array<number|Array<unknown>>,
483
483
  * mixed_output: Array<number|string|Array<unknown>>,
484
484
  * text_output: Array<string|Array<unknown>>,
485
+ * speech: Array<string>, // samples('shabda/speech:'+prog.speech.join(','))
485
486
  * rerun: (...values: Array<unknown>) => Promise<object>,
486
487
  * getVariables: () => never,
487
488
  * callFunction: (name: string, ...args: Array<unknown>) => never,
@@ -495,6 +496,14 @@ export async function rockstar_pro(strings, ...values) {
495
496
  const output = [];
496
497
  const mixed_output = [];
497
498
  const text_output = [];
499
+ const lines = code.split('\n')
500
+ const speech = lines.map((x) => x.toLowerCase()
501
+ .trim()
502
+ .replaceAll(' ', '_')
503
+ .replace(/\W/g, ''))
504
+ .filter((x)=> x.length);
505
+
506
+ //console.log(`samples('shabda/speech:'+prog.speech.join(','))`)
498
507
 
499
508
  await runner.Run(
500
509
  code,
@@ -526,6 +535,7 @@ export async function rockstar_pro(strings, ...values) {
526
535
  output,
527
536
  mixed_output,
528
537
  text_output,
538
+ speech,
529
539
  rerun: (...nextArgs) => {
530
540
  const nextValues = resolveRerunValues(values, ...nextArgs);
531
541
  return rockstar_pro(strings, ...nextValues);
@@ -535,3 +545,20 @@ export async function rockstar_pro(strings, ...values) {
535
545
  listFunctions: () => unsupported('listFunctions()'),
536
546
  };
537
547
  }
548
+
549
+ export const to_base = function (number, base) {
550
+ const convertOne = function (value) {
551
+ let digit = [];
552
+ while (value > 0) {
553
+ digit.unshift(value % base);
554
+ value = Math.floor(value / base);
555
+ }
556
+ return digit;
557
+ };
558
+
559
+ if (Array.isArray(number)) {
560
+ return number.map(convertOne);
561
+ }
562
+
563
+ return convertOne(number);
564
+ }
package/src/others.js ADDED
@@ -0,0 +1,26 @@
1
+ import assert from 'node:assert/strict';
2
+
3
+ const to_base = function (number, base) {
4
+ const convertOne = function (value) {
5
+ let digit = [];
6
+ while (value > 0) {
7
+ digit.unshift(value % base);
8
+ value = Math.floor(value / base);
9
+ }
10
+ return digit;
11
+ };
12
+
13
+ if (Array.isArray(number)) {
14
+ return number.map(convertOne);
15
+ }
16
+
17
+ return convertOne(number);
18
+ }
19
+
20
+ assert.deepEqual(to_base(1344,10), [1,3,4,4])
21
+ assert.deepEqual(to_base(1344,16), [5, 4, 0])
22
+ assert.deepEqual(to_base(1344,2), [1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0])
23
+
24
+ assert.deepEqual(to_base([1344, 23],10), [[1,3,4,4], [2, 3]])
25
+ assert.deepEqual(to_base([1344, 23],16), [[5, 4, 0], [1, 7]])
26
+ assert.deepEqual(to_base([1344, 23],2), [[1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 1]])