hexo-util
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -102,3 +102,3 @@ 'use strict'; | ||
module.exports = function(str) { | ||
function escapeDiacritic(str) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -110,2 +110,4 @@ | ||
}); | ||
}; | ||
} | ||
module.exports = escapeDiacritic; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
module.exports = function(str) { | ||
function escapeHTML(str) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -20,2 +20,4 @@ | ||
}); | ||
}; | ||
} | ||
module.exports = escapeHTML; |
'use strict'; | ||
module.exports = function(str) { | ||
function escapeRegExp(str) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -8,2 +8,4 @@ | ||
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); | ||
}; | ||
} | ||
module.exports = escapeRegExp; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
module.exports = function(str, options) { | ||
function highlightUtil(str, options) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -56,3 +56,3 @@ options = options || {}; | ||
return result; | ||
}; | ||
} | ||
@@ -130,1 +130,3 @@ function encodePlainString(str) { | ||
} | ||
module.exports = highlightUtil; |
'use strict'; | ||
module.exports = function(tag, attrs, text) { | ||
function htmlTag(tag, attrs, text) { | ||
if (!tag) throw new TypeError('tag is required!'); | ||
@@ -15,2 +15,4 @@ | ||
return result; | ||
}; | ||
} | ||
module.exports = htmlTag; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(str, options) { | ||
function slugize(str, options) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -36,2 +36,4 @@ options = options || {}; | ||
} | ||
}; | ||
} | ||
module.exports = slugize; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = function(command, args, options) { | ||
function promiseSpawn(command, args, options) { | ||
if (!command) throw new TypeError('command is required!'); | ||
@@ -46,4 +46,20 @@ | ||
}); | ||
task.on('error', reject); | ||
// Listen to exit events if neither stdout and stderr exist (inherit stdio) | ||
if (!task.stdout && !task.stderr) { | ||
task.on('exit', function(code) { | ||
if (code) { | ||
var e = new Error('Spawn failed'); | ||
e.code = code; | ||
return reject(e); | ||
} | ||
resolve(); | ||
}); | ||
} | ||
}); | ||
}; | ||
} | ||
@@ -57,1 +73,3 @@ function getCache(stream, encoding) { | ||
} | ||
module.exports = promiseSpawn; |
@@ -6,5 +6,7 @@ 'use strict'; | ||
module.exports = function(str) { | ||
function stripHTML(str) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
return str.replace(rStrip, '').trim(); | ||
}; | ||
} | ||
module.exports = stripHTML; |
'use strict'; | ||
module.exports = function(str, options) { | ||
function truncate(str, options) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -33,2 +33,4 @@ options = options || {}; | ||
} | ||
}; | ||
} | ||
module.exports = truncate; |
'use strict'; | ||
// https://github.com/rails/rails/blob/v4.2.0/actionview/lib/action_view/helpers/text_helper.rb#L240 | ||
module.exports = function(str, options) { | ||
function wordWrap(str, options) { | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
@@ -22,2 +22,5 @@ options = options || {}; | ||
return lines.join('\n'); | ||
}; | ||
} | ||
module.exports = wordWrap; | ||
{ | ||
"name": "hexo-util", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Utilities for Hexo.", | ||
@@ -36,2 +36,3 @@ "main": "lib/index", | ||
"bluebird": "^3.0.6", | ||
"camel-case": "^1.2.0", | ||
"highlight.js": "^9.0.0", | ||
@@ -38,0 +39,0 @@ "html-entities": "^1.2.0" |
@@ -37,2 +37,13 @@ # hexo-util | ||
### camelCaseKeys(obj, options) | ||
Convert object keys to camelCase. Original keys will be converted to getter/setter and sync to the camelCase keys. | ||
``` js | ||
camelCaseKeys({ | ||
foo_bar: 'test' | ||
}); | ||
// { fooBar: 'test', foo_bar: 'test' } | ||
``` | ||
### escapeRegex(str) | ||
@@ -173,4 +184,4 @@ | ||
`gid` | Sets the group identity of the process | | ||
`verbose` | Display messages on the console | false | ||
`encoding` | Sets the encoding of the output string | utf8 | ||
`verbose` | Display messages on the console | `false` | ||
`encoding` | Sets the encoding of the output string | `utf8` | ||
@@ -177,0 +188,0 @@ ``` js |
37064
25
605
247
4
+ Addedcamel-case@^1.2.0
+ Addedcamel-case@1.2.2(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedsentence-case@1.1.3(transitive)
+ Addedupper-case@1.1.3(transitive)