@gkucmierz/utils 1.13.0 → 1.15.0
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/main.mjs +62 -0
- package/package-lock.json +2 -2
- package/package.json +4 -3
- package/scripts/generate_main.mjs +43 -0
- package/spec/base64.spec.mjs +17 -0
- package/spec/main.spec.mjs +8 -0
- package/src/base64.mjs +17 -0
- package/src/main.mjs +0 -25
package/main.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
fromBase64, toBase64
|
|
4
|
+
} from './src/base64.mjs'
|
|
5
|
+
import {
|
|
6
|
+
bijective2num, bijective2numBI, num2bijective, num2bijectiveBI
|
|
7
|
+
} from './src/bijective-numeration.mjs'
|
|
8
|
+
import {
|
|
9
|
+
egcd
|
|
10
|
+
} from './src/egcd.mjs'
|
|
11
|
+
import {
|
|
12
|
+
factors, factorsBI
|
|
13
|
+
} from './src/factors.mjs'
|
|
14
|
+
import {
|
|
15
|
+
gcd, gcdBI
|
|
16
|
+
} from './src/gcd.mjs'
|
|
17
|
+
import {
|
|
18
|
+
getType
|
|
19
|
+
} from './src/get-type.mjs'
|
|
20
|
+
import {
|
|
21
|
+
heronsFormula, heronsFormulaBI
|
|
22
|
+
} from './src/herons-formula.mjs'
|
|
23
|
+
import {
|
|
24
|
+
lcm, lcmBI
|
|
25
|
+
} from './src/lcm.mjs'
|
|
26
|
+
import {
|
|
27
|
+
mod, modBI
|
|
28
|
+
} from './src/mod.mjs'
|
|
29
|
+
import {
|
|
30
|
+
phi, phiBI
|
|
31
|
+
} from './src/phi.mjs'
|
|
32
|
+
import {
|
|
33
|
+
powMod, powModBI
|
|
34
|
+
} from './src/pow-mod.mjs'
|
|
35
|
+
import {
|
|
36
|
+
array2range, range2array
|
|
37
|
+
} from './src/range-array.mjs'
|
|
38
|
+
import {
|
|
39
|
+
squareRoot, squareRootBI
|
|
40
|
+
} from './src/square-root.mjs'
|
|
41
|
+
import {
|
|
42
|
+
tonelliShanksBI
|
|
43
|
+
} from './src/tonelli-shanks.mjs'
|
|
44
|
+
|
|
45
|
+
export * from './src/base64.mjs';
|
|
46
|
+
export * from './src/bijective-numeration.mjs';
|
|
47
|
+
export * from './src/egcd.mjs';
|
|
48
|
+
export * from './src/factors.mjs';
|
|
49
|
+
export * from './src/gcd.mjs';
|
|
50
|
+
export * from './src/get-type.mjs';
|
|
51
|
+
export * from './src/herons-formula.mjs';
|
|
52
|
+
export * from './src/lcm.mjs';
|
|
53
|
+
export * from './src/mod.mjs';
|
|
54
|
+
export * from './src/phi.mjs';
|
|
55
|
+
export * from './src/pow-mod.mjs';
|
|
56
|
+
export * from './src/range-array.mjs';
|
|
57
|
+
export * from './src/square-root.mjs';
|
|
58
|
+
export * from './src/tonelli-shanks.mjs';
|
|
59
|
+
|
|
60
|
+
export default [
|
|
61
|
+
fromBase64, toBase64, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, egcd, factors, factorsBI, gcd, gcdBI, getType, heronsFormula, heronsFormulaBI, lcm, lcmBI, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
|
|
62
|
+
];
|
package/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gkucmierz/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@gkucmierz/utils",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.15.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"husky": "^8.0.1",
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gkucmierz/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Usefull functions for solving programming tasks",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "main.mjs",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jasmine",
|
|
8
|
-
"watch": "nodemon --exec 'npm test'"
|
|
8
|
+
"watch": "nodemon --exec 'npm test'",
|
|
9
|
+
"main": "node scripts/generate_main.mjs"
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
|
|
6
|
+
const MAIN_FILE = './main.mjs';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname([path.dirname(__filename), '/../src/.'].join(''));
|
|
10
|
+
|
|
11
|
+
const files = fs.readdirSync(__dirname);
|
|
12
|
+
|
|
13
|
+
const utilsFiles = files
|
|
14
|
+
.filter(name => name.match(/\.mjs$/))
|
|
15
|
+
.filter(name => name !== 'main.mjs');
|
|
16
|
+
|
|
17
|
+
const allMethods = {};
|
|
18
|
+
const map = new Map();
|
|
19
|
+
|
|
20
|
+
for (const file of utilsFiles) {
|
|
21
|
+
const f = [__dirname, file].join('/');
|
|
22
|
+
const obj = await import(f);
|
|
23
|
+
map.set(file, Object.keys(obj));
|
|
24
|
+
Object.keys(obj).map(key => {
|
|
25
|
+
if (key in allMethods) throw Error('Duplicate method name');
|
|
26
|
+
allMethods[key] = obj[key];
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
fs.writeFileSync(MAIN_FILE, [
|
|
31
|
+
'',
|
|
32
|
+
...[...map].map(([file, methods]) => {
|
|
33
|
+
return `import {\n ${methods.join(', ')}\n} from './src/${file}'`;
|
|
34
|
+
}),
|
|
35
|
+
'',
|
|
36
|
+
...utilsFiles.map(file => `export * from './src/${file}';`),
|
|
37
|
+
'',
|
|
38
|
+
`export default [`,
|
|
39
|
+
` ${Object.keys(allMethods).join(', ')}`,
|
|
40
|
+
`];`,
|
|
41
|
+
'',
|
|
42
|
+
].join('\n'));
|
|
43
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
toBase64,
|
|
4
|
+
fromBase64,
|
|
5
|
+
} from '../src/base64.mjs';
|
|
6
|
+
|
|
7
|
+
describe('base64', () => {
|
|
8
|
+
it('toBase64', () => {
|
|
9
|
+
expect(toBase64('🥚')).toBe('Ptha3Q==');
|
|
10
|
+
expect(toBase64('🐔')).toBe('PdgU3A==');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('fromBase64', () => {
|
|
14
|
+
expect(fromBase64('Ptha3Q==')).toBe('🥚');
|
|
15
|
+
expect(fromBase64('PdgU3A==')).toBe('🐔');
|
|
16
|
+
});
|
|
17
|
+
});
|
package/src/base64.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
export const toBase64 = string => {
|
|
3
|
+
const codeUnits = new Uint16Array(string.length);
|
|
4
|
+
for (let i = 0; i < codeUnits.length; i++) {
|
|
5
|
+
codeUnits[i] = string.charCodeAt(i);
|
|
6
|
+
}
|
|
7
|
+
return btoa(String.fromCharCode(...new Uint8Array(codeUnits.buffer)));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const fromBase64 = encoded => {
|
|
11
|
+
const binary = atob(encoded);
|
|
12
|
+
const bytes = new Uint8Array(binary.length);
|
|
13
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
14
|
+
bytes[i] = binary.charCodeAt(i);
|
|
15
|
+
}
|
|
16
|
+
return String.fromCharCode(...new Uint16Array(bytes.buffer));
|
|
17
|
+
};
|
package/src/main.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
|
|
9
|
-
const files = fs.readdirSync(__dirname);
|
|
10
|
-
|
|
11
|
-
const utilsFiles = files
|
|
12
|
-
.filter(name => name.match(/\.mjs$/))
|
|
13
|
-
.filter(name => name !== 'main.mjs');
|
|
14
|
-
|
|
15
|
-
const methods = {};
|
|
16
|
-
|
|
17
|
-
for (const file of utilsFiles) {
|
|
18
|
-
const obj = await import(`./${file}`);
|
|
19
|
-
Object.keys(obj).map(key => {
|
|
20
|
-
if (key in methods) throw Error('Duplicate method name');
|
|
21
|
-
methods[key] = obj[key];
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default methods;
|