Socket
Socket
Sign inDemoInstall

hexo-util

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-util - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

.eslintignore

8

lib/escape_diacritic.js

@@ -94,6 +94,6 @@ 'use strict';

for (var i = 0; i < defaultDiacriticsRemovalap.length; i++){
for (var i = 0; i < defaultDiacriticsRemovalap.length; i++) {
var letters = defaultDiacriticsRemovalap[i].letters.split('');
for (var j = 0; j < letters.length ; j++){
for (var j = 0; j < letters.length; j++) {
diacriticsMap[letters[j]] = defaultDiacriticsRemovalap[i].base;

@@ -103,9 +103,9 @@ }

module.exports = function(str){
module.exports = function(str) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');
// http://stackoverflow.com/a/18391901
return str.replace(/[^\u0000-\u007E]/g, function(a){
return str.replace(/[^\u0000-\u007E]/g, function(a) {
return diacriticsMap[a] || a;
});
};

@@ -12,9 +12,9 @@ 'use strict';

module.exports = function(str){
module.exports = function(str) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');
// http://stackoverflow.com/a/12034334
return str.replace(/[&<>"'\/]/g, function(a){
return str.replace(/[&<>"'\/]/g, function(a) {
return htmlEntityMap[a];
});
};
'use strict';
module.exports = function(str){
module.exports = function(str) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');

@@ -5,0 +5,0 @@

'use strict';
var ent = require('ent');
var Entities = require('html-entities').XmlEntities;
var entities = new Entities();
var hljs;
module.exports = function(str, options){
module.exports = function(str, options) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');

@@ -27,3 +28,3 @@ options = options || {};

for (var i = 0, len = lines.length; i < len; i++){
for (var i = 0, len = lines.length; i < len; i++) {
line = lines[i];

@@ -38,3 +39,3 @@ if (tab) line = replaceTabs(line, tab);

if (caption){
if (caption) {
result += '<figcaption>' + caption + '</figcaption>';

@@ -45,3 +46,3 @@ }

if (gutter){
if (gutter) {
result += '<td class="gutter"><pre>' + numbers + '</pre></td>';

@@ -56,3 +57,3 @@ }

function initHighlight(){
function initHighlight() {
hljs = require('highlight.js');

@@ -65,7 +66,11 @@

function replaceTabs(str, tab){
return str.replace(/^\t+/, function(match){
function encodePlainString(str) {
return entities.encode(str);
}
function replaceTabs(str, tab) {
return str.replace(/^\t+/, function(match) {
var result = '';
for (var i = 0, len = match.length; i < len; i++){
for (var i = 0, len = match.length; i < len; i++) {
result += tab;

@@ -78,5 +83,5 @@ }

function highlight(str, options){
function highlight(str, options) {
var lang = options.lang;
var autoDetect = options.hasOwnProperty('autoDetect') ? options.autoDetect : true;
var autoDetect = options.hasOwnProperty('autoDetect') ? options.autoDetect : false;

@@ -86,28 +91,30 @@ if (!lang) {

return hljs.highlightAuto(str);
} else {
lang = 'plain';
}
lang = 'plain';
}
var result = {value: ent.encode(str)};
lang = lang.toLowerCase();
var result = {
value: encodePlainString(str),
language: lang.toLowerCase()
};
if (lang === 'plain'){
result.language = lang;
if (result.language === 'plain') {
return result;
}
if (!hljs.getLanguage(lang)){
if (!hljs.getLanguage(result.language)) {
result.language = 'plain';
return result;
}
return tryHighlight(str, lang) || result;
return tryHighlight(str, result.language) || result;
}
function tryHighlight(str, lang){
function tryHighlight(str, lang) {
try {
return hljs.highlight(lang, str);
} catch (err){
} catch (err) {
return;
}
}
'use strict';
module.exports = function(tag, attrs, text){
module.exports = function(tag, attrs, text) {
if (!tag) throw new TypeError('tag is required!');

@@ -8,3 +8,3 @@

for (var i in attrs){
for (var i in attrs) {
if (attrs[i]) result += ' ' + i + '="' + attrs[i] + '"';

@@ -11,0 +11,0 @@ }

@@ -7,10 +7,10 @@ 'use strict';

function Pattern(rule){
if (rule instanceof Pattern){
function Pattern(rule) {
if (rule instanceof Pattern) {
return rule;
} else if (typeof rule === 'function'){
} else if (typeof rule === 'function') {
this.match = rule;
} else if (rule instanceof RegExp){
} else if (rule instanceof RegExp) {
this.match = regexFilter(rule);
} else if (typeof rule === 'string'){
} else if (typeof rule === 'string') {
this.match = stringFilter(rule);

@@ -22,8 +22,8 @@ } else {

Pattern.prototype.test = function(str){
Pattern.prototype.test = function(str) {
return Boolean(this.match(str));
};
function regexFilter(rule){
return function(str){
function regexFilter(rule) {
return function(str) {
return str.match(rule);

@@ -33,3 +33,3 @@ };

function stringFilter(rule){
function stringFilter(rule) {
var params = [];

@@ -39,7 +39,6 @@

.replace(/\\([\*\?])/g, '$1')
.replace(rParam, function(match, operator, name){
.replace(rParam, function(match, operator, name) {
var str = '';
var optional = false;
if (operator === '*'){
if (operator === '*') {
str = '(.*)?';

@@ -50,6 +49,5 @@ } else {

if (name){
if (name[name.length - 1] === '?'){
if (name) {
if (name[name.length - 1] === '?') {
name = name.slice(0, name.length - 1);
optional = true;
str += '?';

@@ -64,3 +62,3 @@ }

return function(str){
return function(str) {
var match = str.match(regex);

@@ -72,3 +70,3 @@ if (!match) return;

for (var i = 0, len = match.length; i < len; i++){
for (var i = 0, len = match.length; i < len; i++) {
name = params[i - 1];

@@ -75,0 +73,0 @@ result[i] = match[i];

@@ -7,3 +7,3 @@ 'use strict';

function Permalink(rule, options){
function Permalink(rule, options) {
if (!rule) throw new TypeError('rule is required!');

@@ -16,16 +16,16 @@ options = options || {};

var regex = escapeRegExp(rule)
.replace(rParam, function(match, name){
.replace(rParam, function(match, name) {
params.push(name);
if (segments.hasOwnProperty(name)){
if (segments.hasOwnProperty(name)) {
var segment = segments[name];
if (segment instanceof RegExp){
if (segment instanceof RegExp) {
return segment.source;
} else {
return segment;
}
} else {
return '(.+?)';
return segment;
}
return '(.+?)';
});

@@ -38,7 +38,7 @@

Permalink.prototype.test = function(str){
Permalink.prototype.test = function(str) {
return this.regex.test(str);
};
Permalink.prototype.parse = function(str){
Permalink.prototype.parse = function(str) {
var match = str.match(this.regex);

@@ -50,3 +50,3 @@ var params = this.params;

for (var i = 1, len = match.length; i < len; i++){
for (var i = 1, len = match.length; i < len; i++) {
result[params[i - 1]] = match[i];

@@ -58,4 +58,4 @@ }

Permalink.prototype.stringify = function(data){
return this.rule.replace(rParam, function(match, name){
Permalink.prototype.stringify = function(data) {
return this.rule.replace(rParam, function(match, name) {
return data[name];

@@ -62,0 +62,0 @@ });

@@ -8,3 +8,3 @@ 'use strict';

module.exports = function(str, options){
module.exports = function(str, options) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');

@@ -11,0 +11,0 @@ options = options || {};

@@ -6,6 +6,6 @@ 'use strict';

module.exports = function(command, args, options){
module.exports = function(command, args, options) {
if (!command) throw new TypeError('command is required!');
if (!options && args && !Array.isArray(args)){
if (!options && args && !Array.isArray(args)) {
options = args;

@@ -18,3 +18,3 @@ args = [];

return new Promise(function(resolve, reject){
return new Promise(function(resolve, reject) {
var task = spawn(command, args, options);

@@ -28,3 +28,3 @@ var verbose = options.verbose;

task.stdout.on('data', function(data){
task.stdout.on('data', function(data) {
stdout.push(data);

@@ -36,3 +36,3 @@ stdoutLength += data.length;

task.stderr.on('data', function(data){
task.stderr.on('data', function(data) {
stderr.push(data);

@@ -44,4 +44,4 @@ stderrLength += data.length;

task.on('close', function(code){
if (code){
task.on('close', function(code) {
if (code) {
var e = new Error(concatBuffer(stderr, stderrLength, encoding));

@@ -58,3 +58,3 @@ e.code = code;

function concatBuffer(buffer, length, encoding){
function concatBuffer(buffer, length, encoding) {
var data = Buffer.concat(buffer, length);

@@ -61,0 +61,0 @@ if (!encoding) return data;

@@ -6,5 +6,5 @@ 'use strict';

module.exports = function(str){
module.exports = function(str) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');
return str.replace(rStrip, '').trim();
};
'use strict';
module.exports = function(str, options){
module.exports = function(str, options) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');

@@ -12,3 +12,3 @@ options = options || {};

if (separator){
if (separator) {
var words = str.split(separator);

@@ -19,6 +19,6 @@ var word = '';

for (var i = 0, len = words.length; i < len; i++){
for (var i = 0, len = words.length; i < len; i++) {
word = words[i];
if (resultLength + word.length + omissionLength < length){
if (resultLength + word.length + omissionLength < length) {
result += word + separator;

@@ -25,0 +25,0 @@ resultLength = result.length;

'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){
module.exports = function(str, options) {
if (typeof str !== 'string') throw new TypeError('str must be a string!');

@@ -13,6 +13,6 @@ options = options || {};

for (var i = 0, len = lines.length; i < len; i++){
for (var i = 0, len = lines.length; i < len; i++) {
line = lines[i];
if (line.length > width){
if (line.length > width) {
lines[i] = line.replace(regex, '$1\n').trim();

@@ -19,0 +19,0 @@ }

{
"name": "hexo-util",
"version": "0.1.7",
"version": "0.2.0",
"description": "Utilities for Hexo.",
"main": "lib/index",
"scripts": {
"test": "gulp test"
"eslint": "eslint .",
"jscs": "jscs .",
"test": "mocha test/index.js",
"test-cov": "istanbul cover --print both _mocha -- test/index.js"
},

@@ -25,19 +28,13 @@ "directories": {

"devDependencies": {
"chai": "^1.9.1",
"coveralls": "^2.11.2",
"gulp": "^3.8.9",
"gulp-bench": "^1.1.0",
"gulp-istanbul": "^0.5.0",
"gulp-jshint": "^1.8.6",
"gulp-load-plugins": "^0.8.0",
"gulp-mocha": "^2.0.0",
"jshint-stylish": "^1.0.0",
"mocha": "^2.0.1",
"rimraf": "^2.2.8"
"chai": "^3.4.0",
"eslint": "^1.8.0",
"istanbul": "^0.4.0",
"jscs": "^2.5.0",
"mocha": "^2.3.3"
},
"dependencies": {
"bluebird": "^2.6.2",
"ent": "^2.2.0",
"highlight.js": "^8.6.0"
"bluebird": "^3.0.5",
"highlight.js": "^8.9.1",
"html-entities": "^1.2.0"
}
}
# hexo-util
[![Build Status](https://travis-ci.org/hexojs/hexo-util.svg?branch=master)](https://travis-ci.org/hexojs/hexo-util) [![NPM version](https://badge.fury.io/js/hexo-util.svg)](http://badge.fury.io/js/hexo-util) [![Coverage Status](https://img.shields.io/coveralls/hexojs/hexo-util.svg)](https://coveralls.io/r/hexojs/hexo-util?branch=master)
[![Build Status](https://travis-ci.org/hexojs/hexo-util.svg?branch=master)](https://travis-ci.org/hexojs/hexo-util) [![NPM version](https://badge.fury.io/js/hexo-util.svg)](http://badge.fury.io/js/hexo-util) [![Coverage Status](https://coveralls.io/repos/hexojs/hexo-util/badge.svg?branch=master&service=github)](https://coveralls.io/github/hexojs/hexo-util?branch=master)

@@ -39,7 +39,7 @@ Utilities for [Hexo].

`wrap` | Whether to wrap the code block | true
`first_line` | First line number | 1
`firstLine` | First line number | 1
`lang` | Language |
`caption` | Caption |
`tab`| Replace tabs |
`autoDetect` | Detect language automatically | true
`autoDetect` | Detect language automatically | false

@@ -46,0 +46,0 @@ ### htmlTag(tag, attrs, text)

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc