randex 0.1.0 → 0.2.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/lib/custom/name.d.ts +5 -1
- package/lib/custom/name.js +24 -2
- package/lib/test/name.test.js +8 -0
- package/lib/test/test-util.d.ts +1 -0
- package/lib/test/test-util.js +3 -0
- package/package.json +9 -3
package/lib/custom/name.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { RandomLength } from "../interfaces";
|
|
2
|
+
export interface RandomNameOptions {
|
|
3
|
+
length: RandomLength;
|
|
4
|
+
}
|
|
5
|
+
export declare function randomName(options?: RandomNameOptions): string;
|
|
2
6
|
export declare function randomFullName(): string;
|
package/lib/custom/name.js
CHANGED
|
@@ -2,8 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.randomFullName = exports.randomName = void 0;
|
|
4
4
|
var basic_1 = require("../basic");
|
|
5
|
-
function
|
|
6
|
-
|
|
5
|
+
function getLength(reservedChars, length, defaultLength) {
|
|
6
|
+
var result = defaultLength;
|
|
7
|
+
if (typeof length === "number" && length > reservedChars) {
|
|
8
|
+
result = length - reservedChars;
|
|
9
|
+
}
|
|
10
|
+
else if (Array.isArray(length)) {
|
|
11
|
+
var min = length[0], max = length[1];
|
|
12
|
+
var dMin = min - reservedChars;
|
|
13
|
+
var dMax = max - reservedChars;
|
|
14
|
+
if (dMin >= 0 && dMax >= 0) {
|
|
15
|
+
if (dMin < dMax) {
|
|
16
|
+
return [dMin, dMax];
|
|
17
|
+
}
|
|
18
|
+
else if (dMin === dMax) {
|
|
19
|
+
return dMin;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
function randomName(options) {
|
|
26
|
+
var length = (options || {}).length;
|
|
27
|
+
var currentLength = getLength(1, length, [1, 9]);
|
|
28
|
+
return (0, basic_1.random)("alphabetUpper", ["alphabetLower", currentLength]);
|
|
7
29
|
}
|
|
8
30
|
exports.randomName = randomName;
|
|
9
31
|
function randomFullName() {
|
package/lib/test/name.test.js
CHANGED
|
@@ -9,4 +9,12 @@ describe("randomName", function () {
|
|
|
9
9
|
expect(test_util_1.TestUtil.isNameValid(value)).toBeTruthy();
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
it("options", function () {
|
|
13
|
+
var value1 = (0, name_1.randomName)({ length: 5 });
|
|
14
|
+
expect(value1.length).toBe(5);
|
|
15
|
+
var value2 = (0, name_1.randomName)({ length: [5, 5] });
|
|
16
|
+
expect(value2.length).toBe(5);
|
|
17
|
+
var value3 = (0, name_1.randomName)({ length: [1, 5] });
|
|
18
|
+
expect(test_util_1.TestUtil.inNumberRange(value3.length, [1, 5])).toBeTruthy();
|
|
19
|
+
});
|
|
12
20
|
});
|
package/lib/test/test-util.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export declare class TestUtil {
|
|
|
12
12
|
static isNameValid(email: string): RegExpMatchArray | null;
|
|
13
13
|
static isFullNameValid(email: string): RegExpMatchArray | null;
|
|
14
14
|
static isFileNameValid(email: string): RegExpMatchArray | null;
|
|
15
|
+
static inNumberRange(value: number, range: [number, number]): boolean;
|
|
15
16
|
}
|
package/lib/test/test-util.js
CHANGED
|
@@ -74,6 +74,9 @@ var TestUtil = /** @class */ (function () {
|
|
|
74
74
|
.toLowerCase()
|
|
75
75
|
.match(/^[a-z0-9_\.]{2,}$/);
|
|
76
76
|
};
|
|
77
|
+
TestUtil.inNumberRange = function (value, range) {
|
|
78
|
+
return value >= range[0] && value <= range[1];
|
|
79
|
+
};
|
|
77
80
|
return TestUtil;
|
|
78
81
|
}());
|
|
79
82
|
exports.TestUtil = TestUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "randex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"test": "jest --config jest.config.js",
|
|
9
9
|
"build": "tsc",
|
|
10
10
|
"lint": "eslint .",
|
|
11
|
-
"lint:fix": "eslint . --fix"
|
|
11
|
+
"lint:fix": "eslint . --fix",
|
|
12
|
+
"v": "npm --no-git-tag-version version minor"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -29,6 +30,11 @@
|
|
|
29
30
|
"reflect-metadata": "^0.2.1"
|
|
30
31
|
},
|
|
31
32
|
"keywords": [
|
|
32
|
-
"random",
|
|
33
|
+
"random",
|
|
34
|
+
"random filename",
|
|
35
|
+
"random email",
|
|
36
|
+
"random username",
|
|
37
|
+
"random full name",
|
|
38
|
+
"random string"
|
|
33
39
|
]
|
|
34
40
|
}
|