Comparing version 0.0.0 to 0.0.1
{ | ||
"name": "random-id", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Generates a random String with options.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
(function(){ | ||
var randomID = function(len,strength){ | ||
var possibilities = ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "!§$%&/()=?-.,;:_#<>*+^°`´"]; | ||
var randomID = function(len,pattern){ | ||
var possibilities = ["abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "!§$%&/()=?-.,;:_#<>*+^°`´"]; | ||
var chars = ""; | ||
var i = strength ? strength : 1; | ||
while(i--){ | ||
chars+=possibilities[i]; | ||
}; | ||
var pattern = pattern ? pattern : "aA0"; | ||
pattern.split('').forEach(function(a){ | ||
if(!isNaN(parseInt(a))){ | ||
chars += possibilities[2]; | ||
}else if(/[a-z]/.test(a)){ | ||
chars += possibilities[0]; | ||
}else if(/[A-Z]/.test(a)){ | ||
chars += possibilities[1]; | ||
}else{ | ||
chars += possibilities[3]; | ||
} | ||
}); | ||
@@ -11,0 +19,0 @@ var len = len ? len : 30; |
@@ -19,3 +19,3 @@ #randomID | ||
var id = randomID(length, strength); | ||
var id = randomID(length, pattern); | ||
@@ -26,15 +26,27 @@ ##Options | ||
- **strength**: *(Number)* Amount of different characters collections to be used, default: 1 | ||
- 1: [A-Z, a-z] | ||
- 2: [0-9] | ||
- 3: !§$%&/()=?-.,;:_#<>*+^°`´ | ||
- **pattern**: *(String)* Specificies the possible characters to be used to generate the string, eg. `"aA"` would generate a string made out of lowercase and uppercase characters. Defaults to `aA0`; | ||
- any lowercase character: includes a-z | ||
- any uppercase character: includes A-Z | ||
- any number: includes 0-9 | ||
- anything else: includes special characters (!§$%&/()=?-.,;:_#<>*+^°`´) | ||
##Examples | ||
randomID(); //oOskDVlsS002iszDIcrWqdckY8aM8k | ||
randomID(10); //JcWtjGmfNN | ||
randomID(); //oOskDVlsS002iszDIcrWqdckY8aM8k | ||
randomID(10); //JcWtjGmfNN | ||
randomID(20,1); //BInCYJaWjPnEEPcWiAVP | ||
randomID(20,2); //f4BeOaKyfNbVdoxIwO6e | ||
randomID(20,3); //XucMf6*!JO;R$;n<Z;6Y | ||
randomID(20,"a"); //ffeckzhgastisvtzuvcc | ||
randomID(20,"A"); //TZBUJIZNSSSBDSLBXRHI | ||
randomID(20,"aA"); //JENxBtFYMyUuphewMjRd | ||
randomID(20,"0") //32730290429542918140 | ||
randomID(20,"!") //)_§Â%-(§Â-%:(.$??$=^ | ||
randomID(20,"aA0!") //A9!M`kKRu1)MgUN´UhpM | ||
//increasing chances | ||
randomID(20,"aaaaa0") //xujitsji9nxvouydkjkl | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3463
28
51