diff --git a/.eslintrc.json b/.eslintrc.json index 8e31a03..0d632bc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,10 +10,6 @@ "plugin:lodash/recommended", "plugin:node/recommended"], "rules": { - "indent": [ - "error", - 4 - ], "linebreak-style": [ "error", "unix" diff --git a/examples/onefishspecfish.js b/examples/onefishspecfish.js index c234250..b96489c 100644 --- a/examples/onefishspecfish.js +++ b/examples/onefishspecfish.js @@ -3,6 +3,7 @@ // Blog by Carin Meier const _ = require('lodash'); +const debug = require('debug')('onefishspecfish'); const s = require('../lib/spec'); const stest = require('../lib/test'); @@ -32,7 +33,7 @@ s.def('::first-line', s.and(s.cat('n1', '::fish-number', 'n2', '::fish-number', isOneBigger, ({c1, c2}) => c1 !== c2)); -console.log(s.isValid('::first-line', [1, 2, 'Red', 'Blue'])); +debug(s.isValid('::first-line', [1, 2, 'Red', 'Blue'])); s.conform('::first-line', [1, 2, 'Red', 'Blue']); @@ -60,7 +61,7 @@ function fishLine(n1, n2, c1, c2) { return _([fishNumbers[n1], fishNumbers[n2], c1, c2]).map(x => x + ' Fish.').join(' '); } -console.log(fishLine(1, 2, 'Red', 'Blue')); +debug(fishLine(1, 2, 'Red', 'Blue')); s.fdef(fishLine, { args: '::first-line', diff --git a/examples/pwdgen.js b/examples/pwdgen.js index 1f5f61d..a2619be 100644 --- a/examples/pwdgen.js +++ b/examples/pwdgen.js @@ -2,7 +2,8 @@ // of http://upgradingdave.com/blog/posts/2016-06-21-random-pwd-with-spec.html // by Dave Paroulek -const _ = require('lodash'); +const {size: count, range, intersection} = require('lodash'); +const debug = require('debug')('pwdgen'); const testcheck = require('testcheck'); const s = require('../lib/spec'); @@ -12,60 +13,60 @@ const {isString} = s.utils; // Small helper routines to implement Clojure' char and count functions const toChar = i => String.fromCharCode(i); -const count = _.size; +// const count = _.size; s.def('::two-lowers', s.and(isString, s => s.match(/.*[a-z]+.*[a-z]+.*/))); -// console.log(s.isValid('::two-lowers', '1234')); -// console.log(s.isValid('::two-lowers', '12b34a')); +// debug(s.isValid('::two-lowers', '1234')); +// debug(s.isValid('::two-lowers', '12b34a')); -console.log(gen.generate(s.gen('::two-lowers'))); +debug(gen.generate(s.gen('::two-lowers'))); // Clojure: (def char-lower? (into #{} (map char (range 97 122)))) -const isCharLower = _.range(97, 122).map(toChar); +const isCharLower = range(97, 122).map(toChar); s.def('::two-lowers', - s.and(isString, s => 2 <= count(_.intersection(isCharLower, [...s])))); + s.and(isString, s => 2 <= count(intersection(isCharLower, [...s])))); -console.log(gen.generate(s.gen('::two-lowers'))); +debug(gen.generate(s.gen('::two-lowers'))); -const isCharUpper = _.range(65, 91).map(toChar); +const isCharUpper = range(65, 91).map(toChar); s.def('::two-uppers', - s.and(isString, s => 2 <= count(_.intersection(isCharUpper, [...s])))); + s.and(isString, s => 2 <= count(intersection(isCharUpper, [...s])))); -console.log(s.isValid('::two-uppers', 'AB')); +debug(s.isValid('::two-uppers', 'AB')); -console.log(gen.generate(s.gen('::two-uppers'))); +debug(gen.generate(s.gen('::two-uppers'))); -const isCharDigit = _.range(48, 58).map(toChar); +const isCharDigit = range(48, 58).map(toChar); s.def('::two-digits', - s.and(isString, s => 2 <= count(_.intersection(isCharDigit, [...s])))); + s.and(isString, s => 2 <= count(intersection(isCharDigit, [...s])))); s.isValid('::two-digits', '12'); // => true -console.log(gen.generate(s.gen('::two-digits'))); +debug(gen.generate(s.gen('::two-digits'))); const isCharSymbol = ['!', '$', '^', '&']; s.def('::two-symbols', - s.and(isString, s => 2 <= count(_.intersection(isCharSymbol, [...s])))); + s.and(isString, s => 2 <= count(intersection(isCharSymbol, [...s])))); s.isValid('::two-symbols', '$!'); // => true -console.log(gen.generate(s.gen('::two-symbols'))); +debug(gen.generate(s.gen('::two-symbols'))); // TODO: original article creates a more complicated custom generator here. const genTwoSymbols = () => testcheck.gen.asciiString; s.def('::two-symbols', s.withGen( - s.and(isString, s => 2 <= count(_.intersection(isCharSymbol, [...s]))), + s.and(isString, s => 2 <= count(intersection(isCharSymbol, [...s]))), genTwoSymbols)); -console.log(gen.generate(s.gen('::two-symbols'))); +debug(gen.generate(s.gen('::two-symbols'))); s.def('::10-to-15-chars', s.and(isString, x => s.isIntInRange(10, 16, x.length))); @@ -76,4 +77,4 @@ s.def('::password', '::two-symbols', '::10-to-15-chars')); -console.log(s.isValid('::password', 'abCD12$!34')); // => true +debug(s.isValid('::password', 'abCD12$!34')); // => true