hexo-util
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -8,2 +8,3 @@ var hljs = require('highlight.js'); | ||
module.exports = function(str, options){ | ||
if (typeof str !== 'string') throw new TypeError('str must be a string!'); | ||
options = options || {}; | ||
@@ -10,0 +11,0 @@ |
module.exports = function(tag, attrs, text){ | ||
if (!tag) throw new TypeError('tag is required!'); | ||
var result = '<' + tag; | ||
@@ -3,0 +5,0 @@ |
@@ -1,10 +0,12 @@ | ||
var inflection = require('inflection'); | ||
exports.escape = require('./escape'); | ||
exports.format = require('./format'); | ||
exports.escapeDiacritic = require('./escape_diacritic'); | ||
exports.escapeHTML = require('./escape_html'); | ||
exports.escapeRegExp = require('./escape_regexp'); | ||
exports.highlight = require('./highlight'); | ||
exports.htmlTag = exports.html_tag = require('./html_tag'); | ||
exports.htmlTag = require('./html_tag'); | ||
exports.Pattern = require('./pattern'); | ||
exports.Permalink = require('./permalink'); | ||
exports.inflector = inflection; | ||
exports.titlecase = inflection.titleize; | ||
exports.slugize = require('./slugize'); | ||
exports.spawn = require('./spawn'); | ||
exports.stripHTML = require('./strip_html'); | ||
exports.truncate = require('./truncate'); | ||
exports.wordWrap = require('./word_wrap'); |
@@ -1,2 +0,2 @@ | ||
var escape = require('./escape'); | ||
var escapeRegExp = require('./escape_regexp'); | ||
@@ -32,3 +32,3 @@ var rParam = /([:\*])([\w\?]*)?/g; | ||
var regex = escape.regex(rule) | ||
var regex = escapeRegExp(rule) | ||
.replace(/\\([\*\?])/g, '$1') | ||
@@ -35,0 +35,0 @@ .replace(rParam, function(match, operator, name){ |
@@ -1,2 +0,2 @@ | ||
var escape = require('./escape'); | ||
var escapeRegExp = require('./escape_regexp'); | ||
@@ -6,2 +6,3 @@ var rParam = /:(\w+)/g; | ||
function Permalink(rule, options){ | ||
if (!rule) throw new TypeError('rule is required!'); | ||
options = options || {}; | ||
@@ -12,3 +13,3 @@ | ||
var regex = escape.regex(rule) | ||
var regex = escapeRegExp(rule) | ||
.replace(rParam, function(match, name){ | ||
@@ -15,0 +16,0 @@ params.push(name); |
{ | ||
"name": "hexo-util", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Utilities for Hexo.", | ||
@@ -15,9 +15,3 @@ "main": "lib/index", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/hexojs/util.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/hexojs/util/issues" | ||
}, | ||
"repository": "hexojs/util", | ||
"homepage": "http://hexo.io/", | ||
@@ -44,5 +38,5 @@ "keywords": [ | ||
"dependencies": { | ||
"highlight.js": "^8.4.0", | ||
"inflection": "^1.5.3" | ||
"bluebird": "^2.6.2", | ||
"highlight.js": "^8.4.0" | ||
} | ||
} |
170
README.md
@@ -19,80 +19,14 @@ # util | ||
### escape.filename(str, [transform]) | ||
### escapeRegex(str) | ||
Escapes special characters in a filename. Use `transform` argument to transform the string into lower case (`1`) or upper case (`2`). | ||
### escpae.path(str, [transform]) | ||
Escapes special characters in a path. Use `transform` argument to convert the string into lower case (`1`) or upper case (`2`). | ||
### escape.regex(str) | ||
Escapes special characters in a regular expression. | ||
### escape.diacritic(str) | ||
### escapeDiacritic(str) | ||
Escapes diacritic characters in a string. | ||
### escape.html(str) | ||
### escapeHTML(str) | ||
Escapes HTML entities in a string. | ||
### format.stripHTML(str) | ||
Removes HTML tags in a string. | ||
### format.trim(str) | ||
Removes prefixing spaces and trailing spaces in a string. | ||
### format.titlecase(str) | ||
Converts a string into title case. | ||
### format.wordWrap(str, [options]) | ||
Wraps the string no longer than line width. This method breaks on the first whitespace character that does not exceed line width. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`width` | Line width | 80 | ||
``` js | ||
format.wordWrap('Once upon a time') | ||
// Once upon a time | ||
format.wordWrap('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding a successor to the throne turned out to be more trouble than anyone could have imagined...') | ||
// Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined... | ||
format.wordWrap('Once upon a time', {width: 8}) | ||
// Once\nupon a\ntime | ||
format.wordWrap('Once upon a time', {width: 1}) | ||
// Once\nupon\na\ntime | ||
``` | ||
### format.truncate(str, [options]) | ||
Truncates a given text after a given `length` if text is longer than `length`. The last characters will be replaced with the `omission` option for a total length not exceeding `length`. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`length` | Max length of the string | 30 | ||
`omission` | Omission text | ... | ||
`separator` | truncate text at a natural break | | ||
``` js | ||
format.truncate('Once upon a time in a world far far away') | ||
// "Once upon a time in a world..." | ||
format.truncate('Once upon a time in a world far far away', {length: 17}) | ||
// "Once upon a ti..." | ||
format.truncate('Once upon a time in a world far far away', {length: 17, separator: ' '}) | ||
// "Once upon a..." | ||
format.truncate('And they found that many people were sleeping better.', {length: 25, omission: '... (continued)'}) | ||
// "And they f... (continued)" | ||
``` | ||
### highlight(str, [options]) | ||
@@ -151,7 +85,7 @@ | ||
var permalink = new Permalink(':year/:month/:day/:title', { | ||
segments: { | ||
year: /(\d{4})/, | ||
month: /(\d{2})/, | ||
day: /(\d{2})/ | ||
} | ||
segments: { | ||
year: /(\d{4})/, | ||
month: /(\d{2})/, | ||
day: /(\d{2})/ | ||
} | ||
}); | ||
@@ -169,2 +103,90 @@ | ||
### slugize(str, [options]) | ||
Transforms a string into a clean URL-friendly string. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`separator` | Separator | - | ||
`transform` | Transform the string into lower case (`1`) or upper case (`2`) | | ||
``` js | ||
slugize('Hello World') = 'Hello-World' | ||
slugize('Hellô Wòrld') = 'Hello-World' | ||
slugize('Hello World', {separator: '_'}) = 'Hello_World' | ||
slugize('Hello World', {transform: 1}) = 'hello-world' | ||
slugize('Hello World', {transform: 2}) = 'HELLO-WORLD' | ||
``` | ||
### spawn(command, [args], [options]) | ||
Launches a new process with the given `command`. This method returns a promise. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`cwd` | Current working directory of the child process | | ||
`env` | Environment key-value pairs | | ||
`stdio` | Child's stdio configuration | | ||
`detached` | The child will be a process group leader | | ||
`uid` | Sets the user identity of the process | | ||
`gid` | Sets the group identity of the process | | ||
`verbose` | Display messages on the console | false | ||
`encoding` | Sets the encoding of the output string | utf8 | ||
``` js | ||
spawn('cat', 'test.txt').then(function(content){ | ||
console.log(content); | ||
}); | ||
``` | ||
### stripHTML(str) | ||
Removes HTML tags in a string. | ||
### wordWrap(str, [options]) | ||
Wraps the string no longer than line width. This method breaks on the first whitespace character that does not exceed line width. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`width` | Line width | 80 | ||
``` js | ||
wordWrap('Once upon a time') | ||
// Once upon a time | ||
wordWrap('Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding a successor to the throne turned out to be more trouble than anyone could have imagined...') | ||
// Once upon a time, in a kingdom called Far Far Away, a king fell ill, and finding\na successor to the throne turned out to be more trouble than anyone could have\nimagined... | ||
wordWrap('Once upon a time', {width: 8}) | ||
// Once\nupon a\ntime | ||
wordWrap('Once upon a time', {width: 1}) | ||
// Once\nupon\na\ntime | ||
``` | ||
### truncate(str, [options]) | ||
Truncates a given text after a given `length` if text is longer than `length`. The last characters will be replaced with the `omission` option for a total length not exceeding `length`. | ||
Option | Description | Default | ||
--- | --- | --- | ||
`length` | Max length of the string | 30 | ||
`omission` | Omission text | ... | ||
`separator` | truncate text at a natural break | | ||
``` js | ||
truncate('Once upon a time in a world far far away') | ||
// "Once upon a time in a world..." | ||
truncate('Once upon a time in a world far far away', {length: 17}) | ||
// "Once upon a ti..." | ||
truncate('Once upon a time in a world far far away', {length: 17, separator: ' '}) | ||
// "Once upon a..." | ||
truncate('And they found that many people were sleeping better.', {length: 25, omission: '... (continued)'}) | ||
// "And they f... (continued)" | ||
``` | ||
## License | ||
@@ -171,0 +193,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
25429
17
410
193
1
1
2
+ Addedbluebird@^2.6.2
+ Addedbluebird@2.11.0(transitive)
- Removedinflection@^1.5.3
- Removedinflection@1.13.4(transitive)