Skip to content

Commit

Permalink
Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrijk committed Jul 19, 2018
1 parent 45c9ea3 commit ea1eba7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
"plugin:lodash/recommended",
"plugin:node/recommended"],
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
Expand Down
5 changes: 3 additions & 2 deletions examples/onefishspecfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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']);

Expand Down Expand Up @@ -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',
Expand Down
41 changes: 21 additions & 20 deletions examples/pwdgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)));

Expand All @@ -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

0 comments on commit ea1eba7

Please sign in to comment.