Socket
Socket
Sign inDemoInstall

hexo-util

Package Overview
Dependencies
2
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

3

lib/escape.js

@@ -174,3 +174,2 @@ var rFilenameEscape = /[\s~`!@#\$%\^&\*\(\)\-_\+=\[\]\{\}\|\\;:"'<>,\.\?\/]/g;

exports.diacritic = escapeDiacritic;
exports.html = escapeHTML;
exports.yaml = require('hexo-front-matter').escape;
exports.html = escapeHTML;

@@ -19,3 +19,3 @@ // https://github.com/azer/strip/blob/master/index.js#L5

var width = options.line_width || 80;
var width = options.width || 80;
var regex = new RegExp('(.{1,' + width + '})(\\s+|$)', 'g');

@@ -66,3 +66,3 @@ var lines = str.split('\n');

exports.stripHTML = exports.strip_html = stripHTML;
exports.stripHTML = exports.stripHtml = exports.strip_html = stripHTML;
exports.trim = trim;

@@ -69,0 +69,0 @@ exports.titlecase = require('inflection').titleize;

@@ -12,3 +12,3 @@ var hljs = require('highlight.js');

var wrap = options.hasOwnProperty('wrap') ? options.wrap : true;
var firstLine = options.hasOwnProperty('first_line') ? +options.first_line : 1;
var firstLine = options.hasOwnProperty('firstLine') ? +options.firstLine : 1;
var lang = options.lang;

@@ -15,0 +15,0 @@ var caption = options.caption;

@@ -9,4 +9,3 @@ var inflection = require('inflection');

exports.Permalink = require('./permalink');
exports.yfm = require('hexo-front-matter');
exports.inflector = inflection;
exports.titlecase = inflection.titleize;
{
"name": "hexo-util",
"version": "0.0.1",
"version": "0.0.2",
"description": "Utilities for Hexo.",

@@ -43,3 +43,2 @@ "main": "lib/index",

"dependencies": {
"hexo-front-matter": "0.0.4",
"highlight.js": "^8.4.0",

@@ -46,0 +45,0 @@ "inflection": "^1.5.3"

@@ -10,3 +10,3 @@ # util

``` bash
$ npm install hexo-util
$ npm install hexo-util --save
```

@@ -20,2 +20,150 @@

### escape.filename(str, [transform])
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)
Escapes diacritic characters in a string.
### escape.html(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])
Syntax highlighting for a code block.
Option | Description | Default
--- | --- | ---
`gutter` | Whether to show line numbers | true
`wrap` | Whether to wrap the code block | true
`first_line` | First line number | 1
`lang` | Language (Auto detect if not defined) |
`caption` | Caption |
`tab`| Replace tabs |
### htmlTag(tag, attrs, text)
Creates a html tag.
``` js
htmlTag('img', {src: 'example.png'})
// <img src="example.png">
htmlTag('a', {href: 'http://hexo.io/'}, 'Hexo')
// <a href="http://hexo.io/">Hexo</a>
```
### Pattern(rule)
Parses the string and tests if the string matches the rule. `rule` can be a string, a regular expression or a function.
``` js
var pattern = new Pattern('posts/:id');
pattern.match('posts/89');
// {0: 'posts/89', 1: '89', id: '89'}
```
``` js
var pattern = new Pattern('posts/*path');
pattern.match('posts/2013/hello-world');
// {0: 'posts/2013/hello-world', 1: '2013/hello-world', path: '2013/hello-world'}
```
### Permalink(rule, [options])
Parses a permalink.
Option | Description
--- | ---
`segments` | Customize the rule of a segment in the permalink
``` js
var permalink = new Permalink(':year/:month/:day/:title', {
segments: {
year: /(\d{4})/,
month: /(\d{2})/,
day: /(\d{2})/
}
});
permalink.parse('2014/01/31/test');
// {year: '2014', month: '01', day: '31', title: 'test'}
permalink.test('2014/01/31/test');
// true
permalink.stringify({year: '2014', month: '01', day: '31', title: 'test'})
// 2014/01/31/test
```
## License

@@ -22,0 +170,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc