@recharts/devtools 0.0.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 +39 -0
- package/dist/src/generateMockData.d.ts +6 -0
- package/dist/src/generateMockData.js +17 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +18 -0
- package/dist/src/random.d.ts +16 -0
- package/dist/src/random.js +40 -0
- package/dist/test/generateMockData.spec.d.ts +1 -0
- package/dist/test/generateMockData.spec.js +27 -0
- package/dist/test/random.spec.d.ts +1 -0
- package/dist/test/random.spec.js +30 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @recharts/devtools
|
|
2
|
+
|
|
3
|
+
Shared helper functions and devtools for Recharts projects.
|
|
4
|
+
|
|
5
|
+
Intended for development and debugging purpose only. We won't stop you from using this in prod but also we won't support it. Expect breaking changes in every release.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @recharts/devtools
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { random, generateMockData } from '@recharts/devtools';
|
|
17
|
+
|
|
18
|
+
const gen = random(123); // seeded random generator
|
|
19
|
+
const data = generateMockData(10, 123); // generates 10 mock data points
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
- `npm run build`: Build the package
|
|
25
|
+
- `npm run test`: Run tests with Vitest
|
|
26
|
+
- `npm run lint`: Lint code
|
|
27
|
+
|
|
28
|
+
## Publishing
|
|
29
|
+
|
|
30
|
+
To publish a new version:
|
|
31
|
+
|
|
32
|
+
1. Update the version in `package.json` (e.g., `1.0.1`).
|
|
33
|
+
2. Commit the change.
|
|
34
|
+
3. Create a git tag matching the version:
|
|
35
|
+
```bash
|
|
36
|
+
git tag v1.0.1
|
|
37
|
+
git push origin v1.0.1
|
|
38
|
+
```
|
|
39
|
+
4. The GitHub Action `Publish Package` will automatically publish to NPM.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateMockData = generateMockData;
|
|
4
|
+
const random_1 = require("./random");
|
|
5
|
+
function generateMockData(length, seed) {
|
|
6
|
+
const result = [];
|
|
7
|
+
const gen = (0, random_1.random)(seed);
|
|
8
|
+
for (let i = 0; i < length; i++) {
|
|
9
|
+
result.push({
|
|
10
|
+
label: `Iter: ${i}`,
|
|
11
|
+
x: (0, random_1.between)(gen, 100, 300),
|
|
12
|
+
y: (0, random_1.between)(gen, 400, 800),
|
|
13
|
+
z: (0, random_1.between)(gen, 1000, 2000),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./random"), exports);
|
|
18
|
+
__exportStar(require("./generateMockData"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a random number generator.
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: this number generator is based on LCG and
|
|
5
|
+
* IS NOT SAFE for anything security related!
|
|
6
|
+
*
|
|
7
|
+
* It is only really good for random mock data and visualisation and maybe colors.
|
|
8
|
+
*
|
|
9
|
+
* From wikipedia: https://en.wikipedia.org/wiki/Linear_congruential_generator
|
|
10
|
+
* > LCGs are not intended, and must not be used, for cryptographic applications
|
|
11
|
+
*
|
|
12
|
+
* @param {number} seed use this for deterministic random generators in tests or storybooks
|
|
13
|
+
* @return {Function} generator
|
|
14
|
+
*/
|
|
15
|
+
export declare function random(seed: number): Generator<number>;
|
|
16
|
+
export declare function between(rng: Generator<number, number, unknown>, min: number, max: number): number;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.random = random;
|
|
4
|
+
exports.between = between;
|
|
5
|
+
/**
|
|
6
|
+
* Returns a random number generator.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: this number generator is based on LCG and
|
|
9
|
+
* IS NOT SAFE for anything security related!
|
|
10
|
+
*
|
|
11
|
+
* It is only really good for random mock data and visualisation and maybe colors.
|
|
12
|
+
*
|
|
13
|
+
* From wikipedia: https://en.wikipedia.org/wiki/Linear_congruential_generator
|
|
14
|
+
* > LCGs are not intended, and must not be used, for cryptographic applications
|
|
15
|
+
*
|
|
16
|
+
* @param {number} seed use this for deterministic random generators in tests or storybooks
|
|
17
|
+
* @return {Function} generator
|
|
18
|
+
*/
|
|
19
|
+
function* random(seed) {
|
|
20
|
+
// LCG good enough for our purposes https://en.wikipedia.org/wiki/Linear_congruential_generator
|
|
21
|
+
const m = 2 ** 16 + 1;
|
|
22
|
+
const a = 75;
|
|
23
|
+
const c = 74;
|
|
24
|
+
let x = seed;
|
|
25
|
+
// let's make Math.random() seeds a bit more random
|
|
26
|
+
if (x > 0 && x < 1) {
|
|
27
|
+
x = Math.round(x * 1000);
|
|
28
|
+
}
|
|
29
|
+
while (x < 0) {
|
|
30
|
+
x += m;
|
|
31
|
+
}
|
|
32
|
+
while (true) {
|
|
33
|
+
x = (a * x + c) % m;
|
|
34
|
+
yield Math.round(x);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function between(rng, min, max) {
|
|
38
|
+
const val = rng.next().value;
|
|
39
|
+
return (val % (max - min)) + min;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const generateMockData_1 = require("../src/generateMockData");
|
|
4
|
+
describe('generateMockData', () => {
|
|
5
|
+
test('should generate data with correct length', () => {
|
|
6
|
+
const data = (0, generateMockData_1.generateMockData)(10, 123);
|
|
7
|
+
expect(data).toHaveLength(10);
|
|
8
|
+
});
|
|
9
|
+
test('should be deterministic with same seed', () => {
|
|
10
|
+
const data1 = (0, generateMockData_1.generateMockData)(5, 456);
|
|
11
|
+
const data2 = (0, generateMockData_1.generateMockData)(5, 456);
|
|
12
|
+
expect(data1).toEqual(data2);
|
|
13
|
+
});
|
|
14
|
+
test('should generate different data with different seeds', () => {
|
|
15
|
+
const data1 = (0, generateMockData_1.generateMockData)(5, 456);
|
|
16
|
+
const data2 = (0, generateMockData_1.generateMockData)(5, 789);
|
|
17
|
+
expect(data1).not.toEqual(data2);
|
|
18
|
+
});
|
|
19
|
+
test('should have expected structure', () => {
|
|
20
|
+
const data = (0, generateMockData_1.generateMockData)(1, 100);
|
|
21
|
+
const item = data[0];
|
|
22
|
+
expect(item).toHaveProperty('label');
|
|
23
|
+
expect(item).toHaveProperty('x');
|
|
24
|
+
expect(item).toHaveProperty('y');
|
|
25
|
+
expect(item).toHaveProperty('z');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const random_1 = require("../src/random");
|
|
4
|
+
describe('random', () => {
|
|
5
|
+
test.each([
|
|
6
|
+
[0.1, 7574, 43828, 10324, 53467, 12342, 8206, 25691, 26326, 8414, 41291],
|
|
7
|
+
[0.2, 15074, 16495, 57533, 55144, 7043, 4003, 38151, 43308, 36861, 12095],
|
|
8
|
+
[0.3, 22574, 54699, 39205, 56821, 1744, 65337, 50611, 60290, 65308, 48436],
|
|
9
|
+
[0, 74, 5624, 28652, 51790, 17641, 12409, 13231, 9344, 45504, 4950],
|
|
10
|
+
[-5, 65236, 43036, 16461, 54983, 60505, 15896, 12608, 28156, 14590, 45732],
|
|
11
|
+
])('should provide pseudorandom numbers for seed %d', (seed, ...numbers) => {
|
|
12
|
+
const gen = (0, random_1.random)(seed);
|
|
13
|
+
numbers.forEach(n => {
|
|
14
|
+
expect(gen.next().value).toBe(n);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe('between', () => {
|
|
19
|
+
test.each([
|
|
20
|
+
[100, 5, 10, 5],
|
|
21
|
+
[100, 5, 17, 9],
|
|
22
|
+
[101, 5, 17, 10],
|
|
23
|
+
])('should take a generator %d and boundaries <%d, %d> and return %d', (value, min, max, expected) => {
|
|
24
|
+
function* gen() {
|
|
25
|
+
yield value;
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
expect((0, random_1.between)(gen(), min, max)).toBe(expected);
|
|
29
|
+
});
|
|
30
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@recharts/devtools",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"description": "Devtools and helper functions for Recharts",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"test": "vitest run",
|
|
16
|
+
"lint": "eslint src test --ext .ts",
|
|
17
|
+
"format": "prettier --write \"{src,test}/**/*.ts\""
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"recharts",
|
|
21
|
+
"devtools",
|
|
22
|
+
"charts"
|
|
23
|
+
],
|
|
24
|
+
"author": "Recharts Group",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
29
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
30
|
+
"eslint": "^8.0.0",
|
|
31
|
+
"prettier": "^3.0.0",
|
|
32
|
+
"typescript": "^5.0.0",
|
|
33
|
+
"vitest": "^1.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|