1
0
mirror of https://github.com/S2-/securerandomstring.git synced 2025-08-02 18:30:04 +02:00

Merge branch 'master' of github.com:mrsangrin/secure-random-string

This commit is contained in:
Sandro Ariel Gómez Araya
2017-11-24 12:10:28 -03:00
3 changed files with 73 additions and 5 deletions

69
.jscsrc Normal file
View File

@@ -0,0 +1,69 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"requireSpaceBetweenArguments": true,
"disallowMultipleVarDecl": true,
"requireVarDeclFirst": false,
"requireBlocksOnNewline": false,
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowDanglingUnderscores": false,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"requireSpacesInForStatement": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"disallowKeywords": [
"with",
"continue"
],
"validateIndentation": "\t",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": false,
"disallowNewlineBeforeBlockStatements": true,
"disallowMultipleLineStrings": true,
"requireSpaceBeforeObjectValues": true
}

View File

@@ -16,7 +16,7 @@ function srs(options, cb) {
if (err) { if (err) {
return cb(err); return cb(err);
} }
return cb(null,_finish(buf)); return cb(null, _finish(buf));
}); });
} }
// sync path // sync path
@@ -24,7 +24,7 @@ function srs(options, cb) {
return _finish(crypto.randomBytes(length)); return _finish(crypto.randomBytes(length));
} }
function _finish (buf) { function _finish(buf) {
var string = buf.toString('base64'); var string = buf.toString('base64');
if (alphanumeric === true) { if (alphanumeric === true) {
string = string.replace(/[\W_]+/g,''); string = string.replace(/[\W_]+/g,'');
@@ -34,7 +34,6 @@ function srs(options, cb) {
} }
return string.substr(0, length); return string.substr(0, length);
} }
}; };

View File

@@ -58,8 +58,8 @@ srs({alphanumeric: true}, function(err, sr) {;
}); });
// sync tests // sync tests
test('generate a random string 32 chars long (sync)', srs().length, 32); test('generate a random string 32 chars long (sync)', srs().length, 32);
test('generate a random string 1 chars long (sync)', srs({length:1}).length, 1); test('generate a random string 1 chars long (sync)', srs({length: 1}).length, 1);
test('generate a random string 256 chars long (sync)', srs({length:256}).length, 256); test('generate a random string 256 chars long (sync)', srs({length: 256}).length, 256);
//in 2000 chars there should be at least one substitution //in 2000 chars there should be at least one substitution