Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 29, 2018
1 parent dfe3fff commit d5322e4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
f-ck.js
f-ck.min.js
40 changes: 21 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -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)
}
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,37 @@
"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,
"lines": 100,
"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",
Expand Down
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 36 additions & 36 deletions test.js
Original file line number Diff line number Diff line change
@@ -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()
})

0 comments on commit d5322e4

Please sign in to comment.