Skip to content

Commit

Permalink
Merge pull request #1 from NotNinja/develop
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
neocotic authored Dec 8, 2017
2 parents 87d7b29 + f56d922 commit 03e4dbc
Show file tree
Hide file tree
Showing 27 changed files with 1,179 additions and 33 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extends": "notninja/es8",
"env": {
"node": true
},
"rules": {
"no-bitwise": "off"
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.nyc_output/
coverage/
node_modules/
*.log
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
coverage/
test/
.*
AUTHORS.md
codecov.yml
CONTRIBUTING.md
9 changes: 9 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"check-coverage": true,
"lines": 95,
"statements": 95,
"functions": 95,
"branches": 95,
"include": [ "src/**/*.js" ],
"reporter": [ "lcov" ]
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_js:
- "8"
script:
- npm test
after_success:
- npm run coverage
notifications:
slack:
rooms:
Expand Down
79 changes: 77 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Java's Native-to-ASCII Converter.

[![Build Status](https://img.shields.io/travis/NotNinja/node-native2ascii/develop.svg?style=flat-square)](https://travis-ci.org/NotNinja/node-native2ascii)
[![Coverage](https://img.shields.io/codecov/c/github/NotNinja/node-native2ascii/develop.svg?style=flat-square)](https://codecov.io/gh/NotNinja/node-native2ascii)
[![Dependency Status](https://img.shields.io/david/NotNinja/node-native2ascii.svg?style=flat-square)](https://david-dm.org/NotNinja/node-native2ascii)
[![Dev Dependency Status](https://img.shields.io/david/dev/NotNinja/node-native2ascii.svg?style=flat-square)](https://david-dm.org/NotNinja/node-native2ascii?type=dev)
[![License](https://img.shields.io/npm/l/node-native2ascii.svg?style=flat-square)](https://github.com/NotNinja/node-native2ascii/blob/master/LICENSE.md)
Expand Down Expand Up @@ -42,11 +43,85 @@ $ npm install --global node-native2ascii

## CLI

TODO: Document CLI
Usage: native2ascii [options] [inputfile] [outputfile]


Options:

-e, --encoding <encoding> specify encoding to be used by the conversion procedure
-r, --reverse perform reverse operation
-V, --version output the version number
-h, --help output usage information

Converts a file that is encoded to any character encoding that is
[supported by Node.js](https://nodejs.org/dist/latest-v8.x/docs/api/buffer.html#buffer_buffers_and_character_encodings)
(which can be controlled via the `encoding` command line option and defaults to `utf8`) to a file encoded in ASCII,
using Unicode escapes ("\uxxxx" notation) for all characters that are not part of the ASCII character set.

This command is useful for properties files containing characters not in ISO-8859-1 character sets.

A reverse conversion can be performed by passing the `reverse` command line option.

If the `outputfile` command line argument is omitted, standard output is used for output. If, in addition, the
`inputfile` command line argument is omitted, standard input is used for input.

### Examples

Converts a UTF-8 encoded file into an file encoding in ASCII, Unicode escaping characters not in the ASCII character
set:

``` bash
# Using file command line arguments:
$ native2ascii utf8.properties ascii.properties
# Using STDIN and STDOUT:
$ cat utf8.properties | native2ascii > ascii.properties
```

Converts a ASCII encoded file into a file encoded in UTF-8, unescaping any Unicode escapes:

``` bash
# Using file command line arguments:
$ native2ascii --reverse ascii.properties utf8.properties
# Using STDIN and STDOUT:
$ cat ascii.properties | native2ascii --reverse > utf8.properties
```

## API

TODO: Document API
native2ascii(input[, options])

Converts the specified `input` so that it can be encoded in ASCII by using Unicode escapes ("\uxxxx" notation) for all
characters that are not part of the ASCII character set.

This function is useful for properties files containing characters not in ISO-8859-1 character sets.

A reverse conversion can be performed by enabling the `reverse` option.

### Options

| Option | Description | Default |
| --------- | -------------------------------- | ------- |
| `reverse` | Whether to reverse the operation | `false` |

### Examples

Unicode escape characters not in the ASCII character set so that they can be safely written encoded into ASCII:

``` javascript
const native2ascii = require('native2ascii');

native2ascii('I ♥ native2ascii!');
//=> "I \u2665 native2ascii!"
```

These can be later unescaped by reversing the operation:

``` javascript
const native2ascii = require('native2ascii');

native2ascii('I \u2665 native2ascii!', { reverse: true });
//=> "I ♥ native2ascii!"
```

## Bugs

Expand Down
8 changes: 3 additions & 5 deletions bin/native2ascii
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@

'use strict';

const CLI = require('../src/cli');
const { parse, writeError } = require('../src/cli');

(async() => {
const cli = new CLI();

try {
await cli.parse(process.argv);
await parse(process.argv);
} catch (e) {
cli.error(`native2ascii failed: ${e.stack}`);
writeError(`native2ascii failed: ${e.stack}`);

process.exit(1);
}
Expand Down
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
comment: off
coverage:
precision: 2
range: "95...100"
round: down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@
"url": "https://github.com/NotNinja/node-native2ascii.git"
},
"dependencies": {
"commander": "^2.12.2",
"debug": "^3.1.0",
"get-stdin": "^5.0.1",
"glob": "^7.1.2",
"iconv-lite": "^0.4.19"
"commander": "^2.12.2"
},
"devDependencies": {
"chai": "^4.1.2",
"codecov": "^3.0.0",
"eslint": "^4.12.1",
"eslint-config-notninja": "^0.2.3",
"mocha": "^4.0.1"
"mocha": "^4.0.1",
"nyc": "^11.3.0",
"sinon": "^4.1.3",
"tmp": "0.0.33"
},
"bin": {
"native2ascii": "bin/native2ascii"
},
"main": "src/native2ascii.js",
"scripts": {
"pretest": "eslint \"bin/native2ascii\" \"src/**/*.js\" \"test/**/*.js\""
"coverage": "nyc report && codecov",
"pretest": "eslint \"bin/native2ascii\" \"src/**/*.js\" \"test/**/*.js\"",
"test": "nyc mocha -R list \"test/**/*.spec.js\"",
"posttest": "nyc check-coverage"
},
"engines": {
"node": ">=8"
Expand Down
Loading

0 comments on commit 03e4dbc

Please sign in to comment.