Skip to content

Commit

Permalink
[patch] allow randomString to use the whole alphabet
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Mar 20, 2024
1 parent 7af9bb0 commit a9bd035
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 57 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "augment-vir",
"version": "26.0.0",
"version": "26.0.1",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand Down
6 changes: 3 additions & 3 deletions packages/browser-testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/browser-testing",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -23,8 +23,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/testing": "^26.0.0",
"@augment-vir/common": "^26.0.1",
"@augment-vir/testing": "^26.0.1",
"@open-wc/testing": "^4.0.0",
"@types/mocha": "^10.0.6",
"@web/test-runner-commands": "^0.9.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/browser",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/browser",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -24,12 +24,12 @@
"test:watch": "web-test-runner --color --config configs/web-test-runner.config.mjs --watch"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/common": "^26.0.1",
"html-spec-tags": "^2.2.0",
"run-time-assertions": "^1.0.0"
},
"devDependencies": {
"@augment-vir/browser-testing": "^26.0.0",
"@augment-vir/browser-testing": "^26.0.1",
"@open-wc/testing": "^4.0.0",
"@types/chai": "^4.3.12",
"@types/mocha": "^10.0.6",
Expand Down
6 changes: 3 additions & 3 deletions packages/chai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/chai",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -23,8 +23,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/testing": "^26.0.0",
"@augment-vir/common": "^26.0.1",
"@augment-vir/testing": "^26.0.1",
"type-fest": "^4.12.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/common-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/common-tests",
"version": "26.0.0",
"version": "26.0.1",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common-tests",
"bugs": {
Expand All @@ -22,9 +22,9 @@
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@augment-vir/chai": "^26.0.0",
"@augment-vir/common": "^26.0.0",
"@augment-vir/node-js": "^26.0.0",
"@augment-vir/chai": "^26.0.1",
"@augment-vir/common": "^26.0.1",
"@augment-vir/node-js": "^26.0.1",
"@electrovir/nyc": "^15.1.0-fix0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.12",
Expand Down
12 changes: 12 additions & 0 deletions packages/common-tests/src/tests/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,17 @@ describe(stringifyJson.name, () => {
],
throws: Error,
},
{
it: 'can throw from the error handler',
inputs: [
recursiveObject,
{
handleError() {
throw new Error('better error');
},
},
],
throws: 'better error',
},
]);
});
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/common",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand Down
66 changes: 50 additions & 16 deletions packages/common/src/augments/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ function accessCrypto(): Crypto {

const crypto = accessCrypto();

// can't get this coverage to work
/* c8 ignore start */
/**
* Creates a random integer (decimal points are all cut off) between the given min and max
* (inclusive).
Expand Down Expand Up @@ -70,24 +68,60 @@ export function createUuid() {
return crypto.randomUUID();
}

const validStringCharacters = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
];

/**
* Creates a random string (including letters and numbers) of a given length.
*
* This function uses cryptographically secure randomness.
*/
export function randomString(inputLength: number = 16): string {
const arrayLength = Math.ceil(inputLength / 2);
const uintArray = new Uint8Array(arrayLength);
crypto.getRandomValues(uintArray);
return (
Array.from(uintArray)
.map((value) => value.toString(16).padStart(2, '0'))
.join('')
/**
* Because getRandomValues works with even numbers only, we must then chop off extra
* characters if they exist in the even that inputLength was odd.
*/
.substring(0, inputLength)
);
let stringBuilder = '';
for (let i = 0; i < inputLength; i++) {
const index = randomInteger({
min: 0,
max: validStringCharacters.length - 1,
});
stringBuilder += validStringCharacters[index];
}
return stringBuilder;
}
/* c8 ignore stop */

console.log(randomString());
6 changes: 3 additions & 3 deletions packages/docker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/docker",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/docker",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -22,8 +22,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/node-js": "^26.0.0"
"@augment-vir/common": "^26.0.1",
"@augment-vir/node-js": "^26.0.1"
},
"devDependencies": {
"typescript": "5.3.3"
Expand Down
6 changes: 3 additions & 3 deletions packages/node-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/node-js",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/node-js",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -22,7 +22,7 @@
"test:coverage": "npm test coverage"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/common": "^26.0.1",
"ansi-colors": "^4.1.3",
"axios": "^1.6.8",
"fs-extra": "^11.2.0",
Expand All @@ -31,7 +31,7 @@
"type-fest": "^4.12.0"
},
"devDependencies": {
"@augment-vir/chai": "^26.0.0",
"@augment-vir/chai": "^26.0.1",
"@electrovir/nyc": "^15.1.0-fix0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.12",
Expand Down
6 changes: 3 additions & 3 deletions packages/prisma-node-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/prisma-node-js",
"version": "26.0.0",
"version": "26.0.1",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/prisma-node-js",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -22,8 +22,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/node-js": "^26.0.0"
"@augment-vir/common": "^26.0.1",
"@augment-vir/node-js": "^26.0.1"
},
"devDependencies": {
"istanbul-smart-text-reporter": "^1.1.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/scripts",
"version": "26.0.0",
"version": "26.0.1",
"private": true,
"license": "MIT",
"author": {
Expand All @@ -14,8 +14,8 @@
"verify": "ts-node src/index.ts"
},
"dependencies": {
"@augment-vir/common": "^26.0.0",
"@augment-vir/node-js": "^26.0.0"
"@augment-vir/common": "^26.0.1",
"@augment-vir/node-js": "^26.0.1"
},
"devDependencies": {
"@electrovir/nyc": "^15.1.0-fix0",
Expand Down
Loading

0 comments on commit a9bd035

Please sign in to comment.