diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c9c91f9 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +f-ck.js +f-ck.min.js diff --git a/index.js b/index.js index 5b7b7cc..c23d8fc 100644 --- a/index.js +++ b/index.js @@ -1,39 +1,41 @@ -'use strict'; +'use strict' -var repeat = require('repeat-string'); +var repeat = require('repeat-string') -module.exports = vowel; +module.exports = vowel -vowel.vowel = vowel; -vowel.inner = inner; -vowel.grawlix = grawlix; +vowel.vowel = vowel +vowel.inner = inner +vowel.grawlix = grawlix -var floor = Math.floor; +var floor = Math.floor -var DEFAULT = '*'; -var GRAWLIX = '@#$%!&?'; -var VOWELS = /[aeiouy]/g; +var defaultCharacter = '*' +var grawlixPattern = '@#$%!&?' +var vowels = /[aeiouy]/g /* `butt` > `b*tt` */ function vowel(value, character) { - return value.replace(VOWELS, character || DEFAULT); + return value.replace(vowels, character || defaultCharacter) } /* `butt` > `b**t` */ function inner(value, character) { if (value.length <= 2) { - return value; + return value } - return value.charAt(0) + - repeat(character || DEFAULT, value.length - 2) + - value.charAt(value.length - 1); + return ( + value.charAt(0) + + repeat(character || defaultCharacter, value.length - 2) + + value.charAt(value.length - 1) + ) } /* `butt` > `@#$%` */ function grawlix(value, pattern) { - var chars = pattern || GRAWLIX; - var length = typeof value === 'number' ? value : value.length; - var count = chars.length; - return repeat(chars, floor(length / count)) + chars.slice(0, length % count); + var chars = pattern || grawlixPattern + var length = typeof value === 'number' ? value : value.length + var count = chars.length + return repeat(chars, floor(length / count)) + chars.slice(0, length % count) } diff --git a/package.json b/package.json index 2814234..c6e7432 100644 --- a/package.json +++ b/package.json @@ -31,20 +31,20 @@ "browserify": "^16.0.0", "esmangle": "^1.0.0", "nyc": "^11.0.0", + "prettier": "^1.12.1", "remark-cli": "^5.0.0", "remark-preset-wooorm": "^4.0.0", "tape": "^4.0.0", "xo": "^0.20.0" }, "scripts": { - "build-md": "remark . -qfo", + "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", "build-bundle": "browserify index.js --bare -s fck > f-ck.js", "build-mangle": "esmangle f-ck.js > f-ck.min.js", - "build": "npm run build-md && npm run build-bundle && npm run build-mangle", - "lint": "xo", - "test-api": "node test.js", + "build": "npm run build-bundle && npm run build-mangle", + "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run build && npm run lint && npm run test-coverage" + "test": "npm run format && npm run build && npm run test-coverage" }, "nyc": { "check-coverage": true, @@ -52,8 +52,16 @@ "functions": 100, "branches": 100 }, + "prettier": { + "tabWidth": 2, + "useTabs": false, + "singleQuote": true, + "bracketSpacing": false, + "semi": false, + "trailingComma": "none" + }, "xo": { - "space": true, + "prettier": true, "esnext": false, "rules": { "no-var": "off", diff --git a/readme.md b/readme.md index b2821ae..c5b1b82 100644 --- a/readme.md +++ b/readme.md @@ -15,15 +15,15 @@ npm install f-ck ## Usage ```js -var fck = require('f-ck'); +var fck = require('f-ck') -console.log(fck('butt')); //=> 'b*tt' -console.log(fck.vowel('butt')); //=> 'b*tt' -console.log(fck.inner('butt')); //=> 'b**t' -console.log(fck.grawlix('butt')); //=> '@#$%' -console.log(fck.grawlix(7)); //=> '@#$%!&?' +console.log(fck('butt')) // => 'b*tt' +console.log(fck.vowel('butt')) // => 'b*tt' +console.log(fck.inner('butt')) // => 'b**t' +console.log(fck.grawlix('butt')) // => '@#$%' +console.log(fck.grawlix(7)) // => '@#$%!&?' -console.log(fck('butt', '-')); //=> 'b-tt' +console.log(fck('butt', '-')) // => 'b-tt' ``` ## API diff --git a/test.js b/test.js index cd91231..badb69d 100644 --- a/test.js +++ b/test.js @@ -1,41 +1,41 @@ -'use strict'; +'use strict' -var test = require('tape'); -var fck = require('.'); +var test = require('tape') +var fck = require('.') -test('fck', function (t) { - t.test('.vowel', function (st) { - st.equal(fck.vowel('butt'), 'b*tt'); - st.equal(fck.vowel('butt', '-'), 'b-tt'); - st.end(); - }); +test('fck', function(t) { + t.test('.vowel', function(st) { + st.equal(fck.vowel('butt'), 'b*tt') + st.equal(fck.vowel('butt', '-'), 'b-tt') + st.end() + }) - t.test('.inner', function (st) { - st.equal(fck.inner('butt'), 'b**t'); - st.equal(fck.inner('butt', '-'), 'b--t'); - st.equal(fck.inner('but'), 'b*t'); - st.equal(fck.inner('bu'), 'bu'); - st.equal(fck.inner('b'), 'b'); - st.equal(fck.inner(''), ''); - st.end(); - }); + t.test('.inner', function(st) { + st.equal(fck.inner('butt'), 'b**t') + st.equal(fck.inner('butt', '-'), 'b--t') + st.equal(fck.inner('but'), 'b*t') + st.equal(fck.inner('bu'), 'bu') + st.equal(fck.inner('b'), 'b') + st.equal(fck.inner(''), '') + st.end() + }) - t.test('.grawlix', function (st) { - st.equal(fck.grawlix('butt'), '@#$%'); - st.equal(fck.grawlix(4), '@#$%'); - st.equal(fck.grawlix('buttb'), '@#$%!'); - st.equal(fck.grawlix('buttbu'), '@#$%!&'); - st.equal(fck.grawlix('buttbut'), '@#$%!&?'); - st.equal(fck.grawlix('buttbutt'), '@#$%!&?@'); - st.equal(fck.grawlix('buttbuttb'), '@#$%!&?@#'); - st.equal(fck.grawlix('but'), '@#$'); - st.equal(fck.grawlix('bu'), '@#'); - st.equal(fck.grawlix('b'), '@'); - st.equal(fck.grawlix(''), ''); - st.equal(fck.grawlix('butt', '*'), '****'); - st.equal(fck.grawlix('butt', '123'), '1231'); - st.end(); - }); + t.test('.grawlix', function(st) { + st.equal(fck.grawlix('butt'), '@#$%') + st.equal(fck.grawlix(4), '@#$%') + st.equal(fck.grawlix('buttb'), '@#$%!') + st.equal(fck.grawlix('buttbu'), '@#$%!&') + st.equal(fck.grawlix('buttbut'), '@#$%!&?') + st.equal(fck.grawlix('buttbutt'), '@#$%!&?@') + st.equal(fck.grawlix('buttbuttb'), '@#$%!&?@#') + st.equal(fck.grawlix('but'), '@#$') + st.equal(fck.grawlix('bu'), '@#') + st.equal(fck.grawlix('b'), '@') + st.equal(fck.grawlix(''), '') + st.equal(fck.grawlix('butt', '*'), '****') + st.equal(fck.grawlix('butt', '123'), '1231') + st.end() + }) - t.end(); -}); + t.end() +})