rockstar-strudel 1.0.7 → 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/package.json +1 -1
- package/src/index.js +18 -1
- package/src/others.js +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rockstar-strudel",
|
|
3
|
-
"version": "1.0.
|
|
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
|
@@ -503,7 +503,7 @@ export async function rockstar_pro(strings, ...values) {
|
|
|
503
503
|
.replace(/\W/g, ''))
|
|
504
504
|
.filter((x)=> x.length);
|
|
505
505
|
|
|
506
|
-
console.log(`samples('shabda/speech:'+prog.speech.join(','))`)
|
|
506
|
+
//console.log(`samples('shabda/speech:'+prog.speech.join(','))`)
|
|
507
507
|
|
|
508
508
|
await runner.Run(
|
|
509
509
|
code,
|
|
@@ -545,3 +545,20 @@ export async function rockstar_pro(strings, ...values) {
|
|
|
545
545
|
listFunctions: () => unsupported('listFunctions()'),
|
|
546
546
|
};
|
|
547
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]])
|