Skip to content

Commit

Permalink
refactor: Remove is
Browse files Browse the repository at this point in the history
If we expected to receive a barrage of assorted arguments to functions, we might need `is`.

But for Metalsmith, it’s overkill.  People know to pass a string for directories.  People know what a number is.  :P
  • Loading branch information
Zearin committed Jun 5, 2018
1 parent f231064 commit 54dba0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
21 changes: 12 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var assert = require('assert')
var clone = require('clone')
var fs = require('co-fs-extra')
var is = require('is')
var matter = require('gray-matter')
var Mode = require('stat-mode')
var path = require('path')
Expand All @@ -25,7 +24,11 @@ rm = thunkify(rm)
* Helpers
*/

var absolute = function(s) {return path.resolve(s) === s}
var absolute = function(s) {return path.resolve(s) === s}
var isBoolean = function(b) {return typeof b === 'boolean'}
var isNumber = function(n) {return typeof n === 'number' && !Number.isNaN(n)}
var isObject = function(o) {return o !== null && typeof o === 'object'}
var isString = function(s) {return typeof s === 'string'}


/**
Expand Down Expand Up @@ -75,7 +78,7 @@ Metalsmith.prototype.use = function(plugin){

Metalsmith.prototype.directory = function(directory){
if (!arguments.length) return path.resolve(this._directory)
assert(is.string(directory), 'You must pass a directory path string.')
assert(isString(directory), 'You must pass a directory path string.')
this._directory = directory
return this
}
Expand All @@ -89,7 +92,7 @@ Metalsmith.prototype.directory = function(directory){

Metalsmith.prototype.metadata = function(metadata){
if (!arguments.length) return this._metadata
assert(is.object(metadata), 'You must pass a metadata object.')
assert(isObject(metadata), 'You must pass a metadata object.')
this._metadata = clone(metadata)
return this
}
Expand All @@ -103,7 +106,7 @@ Metalsmith.prototype.metadata = function(metadata){

Metalsmith.prototype.source = function(path){
if (!arguments.length) return this.path(this._source)
assert(is.string(path), 'You must pass a source path string.')
assert(isString(path), 'You must pass a source path string.')
this._source = path
return this
}
Expand All @@ -117,7 +120,7 @@ Metalsmith.prototype.source = function(path){

Metalsmith.prototype.destination = function(path){
if (!arguments.length) return this.path(this._destination)
assert(is.string(path), 'You must pass a destination path string.')
assert(isString(path), 'You must pass a destination path string.')
this._destination = path
return this
}
Expand All @@ -131,7 +134,7 @@ Metalsmith.prototype.destination = function(path){

Metalsmith.prototype.concurrency = function(max){
if (!arguments.length) return this._concurrency
assert(is.number(max), 'You must pass a number for concurrency.')
assert(isNumber(max), 'You must pass a number for concurrency.')
this._concurrency = max
return this
}
Expand All @@ -144,7 +147,7 @@ Metalsmith.prototype.concurrency = function(max){
*/
Metalsmith.prototype.clean = function(clean){
if (!arguments.length) return this._clean
assert(is.boolean(clean), 'You must pass a boolean.')
assert(isBoolean(clean), 'You must pass a boolean.')
this._clean = clean
return this
}
Expand All @@ -158,7 +161,7 @@ Metalsmith.prototype.clean = function(clean){

Metalsmith.prototype.frontmatter = function(frontmatter){
if (!arguments.length) return this._frontmatter
assert(is.boolean(frontmatter), 'You must pass a boolean.')
assert(isBoolean(frontmatter), 'You must pass a boolean.')
this._frontmatter = frontmatter
return this
}
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"commander": "^2.6.0",
"gray-matter": "^2.1.0",
"has-generators": "^1.0.1",
"is": "^3.1.0",
"is-utf8": "~0.2.0",
"recursive-readdir": "^2.1.0",
"rimraf": "^2.2.8",
Expand Down

0 comments on commit 54dba0c

Please sign in to comment.