Skip to content

Commit

Permalink
test: use npm scripts instead of Makefile (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jan 26, 2017
1 parent 77fb038 commit 5ba8a49
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 305 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/fixtures
examples/**/app/public
logs
run
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-egg"
}
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
lib-cov
coverage.html
coverage
*.seed
*.log
*.csv
Expand All @@ -13,4 +12,4 @@ logs
results

node_modules
npm-debug.log
npm-debug.log
4 changes: 0 additions & 4 deletions .jshintignore

This file was deleted.

95 changes: 0 additions & 95 deletions .jshintrc

This file was deleted.

13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
sudo: false
language: node_js
node_js:
- '0.10'
- '0.11'
script: make test-coveralls
- '4'
- '6'
- '7'
install:
- npm i npminstall && npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
4 changes: 1 addition & 3 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Ordered by date of first contribution.
# Auto-generated by 'contributors' on Mon, 20 Jan 2014 01:34:58 GMT.
# https://github.com/xingrz/node-contributors

fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)
kof <oleg008@gmail.com> (https://github.com/kof)
Oleg Slobodskoi <oleg008@gmail.com> (https://github.com/kof)
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
This software is licensed under the MIT License.

Copyright (C) 2012 - 2015 fengmk2 <fengmk2@gmail.com>
Copyright (c) node-modules and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
32 changes: 0 additions & 32 deletions Makefile

This file was deleted.

22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
charset
=======


[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Gittip][gittip-image]][gittip-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/charset.svg?style=flat-square
[npm-url]: https://npmjs.org/package/charset
[travis-image]: https://img.shields.io/travis/node-modules/charset.svg?style=flat-square
[travis-url]: https://travis-ci.org/node-modules/charset
[coveralls-image]: https://img.shields.io/coveralls/node-modules/charset.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/node-modules/charset?branch=master
[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square
[gittip-url]: https://www.gittip.com/fengmk2/
[codecov-image]: https://codecov.io/gh/node-modules/charset/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/node-modules/charset
[david-image]: https://img.shields.io/david/node-modules/charset.svg?style=flat-square
[david-url]: https://david-dm.org/node-modules/charset
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/charset.svg?style=flat-square
[download-url]: https://npmjs.org/package/charset

Expand Down Expand Up @@ -68,9 +61,9 @@ You can combine with [jschardet] to help you detect the finally charset.
This example codes come from [stackoverflow#12326688](http://stackoverflow.com/a/18712021/2496088):

```js
var request = require('request'),
charset = require('charset'),
jschardet = require('jschardet');
var request = require('request');
var charset = require('charset');
var jschardet = require('jschardet');

request({
url: 'http://www.example.com',
Expand All @@ -87,7 +80,6 @@ request({

## License

MIT

[MIT](LICENSE.txt)

[jschardet]: https://github.com/aadsm/jschardet
16 changes: 16 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
environment:
matrix:
- nodejs_version: '4'
- nodejs_version: '6'
- nodejs_version: '7'

install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && node_modules\.bin\npminstall

test_script:
- node --version
- npm --version
- npm run ci

build: off
60 changes: 59 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
module.exports = require('./lib/charset');
'use strict';

const CHARTSET_RE = /(?:charset|encoding)\s*=\s*['"]? *([\w\-]+)/i;

module.exports = charset;

/**
* guest data charset from req.headers, xml, html content-type meta tag
* headers:
* 'content-type': 'text/html;charset=gbk'
* meta tag:
* <meta http-equiv="Content-Type" content="text/html; charset=xxxx"/>
* xml file:
* <?xml version="1.0" encoding="UTF-8"?>
*
* @param {Object} obj `Content-Type` String, or `res.headers`, or `res` Object
* @param {Buffer} [data] content buffer
* @param {Number} [peekSize] max content peek size, default is 512
* @return {String} charset, lower case, e.g.: utf8, gbk, gb2312, ....
* If can\'t guest, return null
* @api public
*/
function charset(obj, data, peekSize) {
let matchs = null;
let end = 0;
if (data) {
peekSize = peekSize || 512;
// https://github.com/node-modules/charset/issues/4
end = data.length > peekSize ? peekSize : data.length;
}
// charset('text/html;charset=gbk')
let contentType = obj;
if (contentType && typeof contentType !== 'string') {
// charset(res.headers)
let headers = obj;
if (obj.headers) {
// charset(res)
headers = obj.headers;
}
contentType = headers['content-type'] || headers['Content-Type'];
}
if (contentType) {
// guest from obj first
matchs = CHARTSET_RE.exec(contentType);
}
if (!matchs && end > 0) {
// guest from content body (html/xml) header
contentType = data.slice(0, end).toString();
matchs = CHARTSET_RE.exec(contentType);
}
let cs = null;
if (matchs) {
cs = matchs[1].toLowerCase();
if (cs === 'utf-8') {
cs = 'utf8';
}
}
return cs;
}
74 changes: 0 additions & 74 deletions lib/charset.js

This file was deleted.

Binary file removed logo.png
Binary file not shown.
Loading

0 comments on commit 5ba8a49

Please # to comment.