-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cuong Duy Nguyen
authored
Nov 27, 2019
1 parent
8ede94f
commit 9332acb
Showing
5 changed files
with
8 additions
and
100 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,3 @@ | ||
/** | ||
* Create a random string with length equals 4. | ||
*/ | ||
function s4(): string { | ||
return Math.round(new Date().getTime() * Math.random()) | ||
.toString(16) | ||
.substr(0, 4); | ||
} | ||
|
||
/** | ||
* Create a random number between 0 and (length - 1). | ||
* @param length Length of chaining numbers. | ||
*/ | ||
function ramdomNumber(length: number): number { | ||
return Math.floor(Math.random() * length); | ||
} | ||
|
||
/** | ||
* Create a default Id with length equals 24. | ||
*/ | ||
function defaultId(): string { | ||
const charCodes = ['-', '_', '@', '#', '$', '%', '^', '&', '*']; | ||
const { length } = charCodes; | ||
return ( | ||
s4() + | ||
charCodes[ramdomNumber(length)] + | ||
s4() + | ||
charCodes[ramdomNumber(length)] + | ||
s4() + | ||
charCodes[ramdomNumber(length)] + | ||
s4() + | ||
charCodes[ramdomNumber(length)] + | ||
s4() | ||
); | ||
} | ||
|
||
/** | ||
* Create a lovely Id with thinid. | ||
* @param length Length of Id. | ||
*/ | ||
export function thinid(length?: number): string { | ||
if (!length || length <= 0) { | ||
return defaultId(); | ||
} | ||
|
||
const defaultLength = defaultId().length; | ||
const x = length % defaultLength; | ||
const y = Math.floor(length / defaultLength); | ||
let result = defaultId().substr(0, x); | ||
for (let i = 0; i < y; i++) { | ||
result += defaultId(); | ||
} | ||
return result; | ||
export function giin(): string { | ||
return 'giin'; | ||
} |