@tktb-tess/util-fns 0.4.0 → 0.4.1
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 +36 -3
- package/dist/bundle.js +90 -98
- package/dist/bundle.umd.cjs +3 -2
- package/dist/wasm-init.d.ts +1 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
Utility functions for personal use
|
|
4
4
|
|
|
5
|
-
This package is ESM only.
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npm i @tktb-tess/util-fns
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
##
|
|
11
|
+
## ⚠ Caution
|
|
12
|
+
|
|
13
|
+
Some functions such as `modPow()` use WebAssembly module internally. If you use these funcs, please initialize WebAssembly before you call it by calling `initWasm()` with `await`.
|
|
14
|
+
|
|
15
|
+
`initWasm()` doesn't need to be called multiple times. It must be called once before you use the functions at first.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { modPow, initWasm } from '@tktb-tess/util-fns';
|
|
19
|
+
|
|
20
|
+
const main = async () => {
|
|
21
|
+
await initWasm(); // needed
|
|
22
|
+
|
|
23
|
+
const ans = modPow(2n, 16n, 17n);
|
|
24
|
+
|
|
25
|
+
const ans2 = modPow(2n, 17n, 17n);
|
|
26
|
+
|
|
27
|
+
console.log(ans, ans2); // 1n 2n
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
main();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Wrong example
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { modPow } from '@tktb-tess/util-fns';
|
|
37
|
+
|
|
38
|
+
const main = async () => {
|
|
39
|
+
|
|
40
|
+
const ans = modPow(2n, 16n, 17n); // Uncaught Error: The function 'modPow()' uses wasm internally, but it hasn't been initialized yet. Please call 'initWasm()' before using 'modPow()'.
|
|
41
|
+
|
|
42
|
+
console.log(ans);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
main();
|
|
46
|
+
```
|
|
14
47
|
|
|
15
48
|
|
|
16
49
|
|