Comparing version 0.1.2 to 0.2.0
{ | ||
"name": "genmo", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Generates models based off of json-schemas", | ||
@@ -19,3 +19,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"lorem-ipsum": "^1.0.3" | ||
"lorem-ipsum": "^1.0.3", | ||
"randexp": "0.4.2" | ||
}, | ||
@@ -22,0 +23,0 @@ "devDependencies": { |
var loremIpsum = require('lorem-ipsum') | ||
var randexp = require('randexp').randexp | ||
module.exports = function (schema) { | ||
return loremIpsum() | ||
var minLength = schema.minLength || 1 | ||
var maxLength = schema.maxLength || minLength + 10 | ||
var pattern = schema.pattern | ||
if (pattern) { | ||
return randexp(pattern) | ||
} else { | ||
var string = loremIpsum({ | ||
count: maxLength | ||
}) | ||
return string.substr(0, Math.floor(Math.random() * maxLength + 1) + minLength ) | ||
} | ||
} |
@@ -11,1 +11,39 @@ var tape = require('tape') | ||
}) | ||
tape('string respects max character limit', function (t) { | ||
var schema = { | ||
type: 'string', | ||
maxLength: 10 | ||
} | ||
var allBelow = true | ||
for (var i = 0; i < 100; i++) { | ||
allBelow = string(schema).length <= schema.maxLength | ||
} | ||
t.equal(allBelow, true) | ||
t.end() | ||
}) | ||
tape('string respects min character limit', function (t) { | ||
var schema = { | ||
type: 'string', | ||
minLength: 5 | ||
} | ||
var allAbove = true | ||
for (var i = 0; i < 100; i++) { | ||
allAbove = string(schema).length > schema.minLength | ||
} | ||
t.equal(allAbove, true) | ||
t.end() | ||
}) | ||
tape('string will generate matches for regular expressions', function (t) { | ||
var regex = '^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$' | ||
var schema = { | ||
type: 'string', | ||
pattern: regex | ||
} | ||
var s = string(schema) | ||
console.log(s) | ||
t.equal(new RegExp(regex).test(s), true) | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
16066
605
2
+ Addedrandexp@0.4.2
+ Addeddiscontinuous-range@1.0.0(transitive)
+ Addedrandexp@0.4.2(transitive)
+ Addedret@0.1.15(transitive)