Skip to content

Commit

Permalink
Merge branch 'master' into fix_sublanguages_highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
segayuu authored Aug 21, 2019
2 parents b15b518 + 95f791a commit 5e0deb9
Show file tree
Hide file tree
Showing 39 changed files with 961 additions and 531 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ node_modules/
tmp/
*.log
.idea/
coverage/
.nyc_output/
highlight_alias.json
9 changes: 0 additions & 9 deletions .npmignore

This file was deleted.

8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ cache:
- node_modules

node_js:
- "6"
- "8"
- "10"
- "node"

script:
# For older versions of npm (ie. the one bundled with Node 6), we need to manually run `prepare`
# to build the project. You can still install and consume the package without any issue.
- if [[ "$TRAVIS_NODE_VERSION" == "6" ]]; then npm run prepare; fi
- npm run eslint
- npm run test-cov

after_script:
- npm install coveralls
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- nyc report --reporter=text-lcov | coveralls
3 changes: 0 additions & 3 deletions CHANGELOG.md

This file was deleted.

19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 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://coveralls.io/repos/hexojs/hexo-util/badge.svg?branch=master&service=github)](https://coveralls.io/github/hexojs/hexo-util?branch=master) [![dependencies Status](https://david-dm.org/hexojs/hexo-util/status.svg)](https://david-dm.org/hexojs/hexo-util) [![devDependencies Status](https://david-dm.org/hexojs/hexo-util/dev-status.svg)](https://david-dm.org/hexojs/hexo-util?type=dev)
[![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)](https://www.npmjs.com/package/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)
[![dependencies Status](https://david-dm.org/hexojs/hexo-util/status.svg)](https://david-dm.org/hexojs/hexo-util)
[![devDependencies Status](https://david-dm.org/hexojs/hexo-util/dev-status.svg)](https://david-dm.org/hexojs/hexo-util?type=dev)

Utilities for [Hexo].

Expand Down Expand Up @@ -67,6 +71,7 @@ hash('123456');
```

### HashStream()
**\[deprecated\]** use `createSha1Hash()`.

Generates SHA1 hash with a transform stream.

Expand All @@ -80,6 +85,18 @@ fs.createReadStream('/path/to/file')
});
```

### createSha1Hash()
return SHA1 hash object.
This is the same as calling `createHash('utf8')` in the node.js native module crypto.
``` js
const sha1 = createSha1Hash();
fs.createReadStream('/path/to/file')
.pipe(sha1)
.on('finish', () => {
console.log(sha1.read());
});
```

### highlight(str, [options])

Syntax highlighting for a code block.
Expand Down
36 changes: 36 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Fix line endings in Windows. (runs before repo cloning)
init:
- git config --global core.autocrlf input

# Test against these versions of Node.js.
environment:
matrix:
- nodejs_version: "8"
- nodejs_version: "10"
- nodejs_version: "12"

matrix:
fast_finish: true

# Install scripts. (runs after repo cloning)
install:
- ps: Install-Product node $env:nodejs_version
- npm install -g npm
- npm install

cache:
- node_modules -> package.json

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# Run tests
- npm test

# Don't actually build.
build: off

# Set build version format here instead of in the admin panel.
version: "{build}"
4 changes: 2 additions & 2 deletions lib/cache_stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Transform = require('stream').Transform;
const { Transform } = require('stream');

function CacheStream() {
Transform.call(this);
Expand All @@ -11,7 +11,7 @@ function CacheStream() {
require('util').inherits(CacheStream, Transform);

CacheStream.prototype._transform = function(chunk, enc, callback) {
var buf = chunk instanceof Buffer ? chunk : Buffer.from(chunk, enc);
const buf = chunk instanceof Buffer ? chunk : Buffer.from(chunk, enc);

this._cache.push(buf);
this.push(buf);
Expand Down
48 changes: 26 additions & 22 deletions lib/camel_case_keys.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

var camelCase = require('camel-case');

var rPrefixUnderscore = /^(_+)/;
const camelCase = require('camel-case');

function getter(key) {
return function() {
Expand All @@ -16,31 +14,37 @@ function setter(key) {
};
}

function toCamelCase(str) {
let prefixLength = -1;

while (str[++prefixLength] === '_');

if (!prefixLength) {
return camelCase(str);
}
return str.substring(0, prefixLength) + camelCase(str.substring(prefixLength));
}

function camelCaseKeys(obj) {
if (typeof obj !== 'object') throw new TypeError('obj must be an object!');

var keys = Object.keys(obj);
var result = {};
const keys = Object.keys(obj);
const { length } = keys;
const result = {};

for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i];
var value = obj[key];
var match = key.match(rPrefixUnderscore);
var newKey;
for (let i = 0; i < length; i++) {
const oldKey = keys[i];
const newKey = toCamelCase(oldKey);

if (match) {
var underscore = match[1];
newKey = underscore + camelCase(key.substring(underscore.length));
} else {
newKey = camelCase(key);
}
result[newKey] = obj[oldKey];

if (newKey === key) {
result[key] = value;
} else {
result[newKey] = value;
result.__defineGetter__(key, getter(newKey));
result.__defineSetter__(key, setter(newKey));
if (newKey !== oldKey) {
Object.defineProperty(result, oldKey, {
get: getter(newKey),
set: setter(newKey),
configurable: true,
enumerable: true
});
}
}

Expand Down
Loading

0 comments on commit 5e0deb9

Please sign in to comment.