Skip to content

Commit

Permalink
Simplify & clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Jul 30, 2021
1 parent 54f3a1c commit cb6cc7a
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 293 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
indent_style = tab
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[{README.md,*.yml,*.d.ts}]
indent_style = space
indent_size = 2
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: run-checks

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
# Include all major maintenance + active LTS + current Node.js versions.
# https://github.com/nodejs/Release#release-schedule
node: [12, 14, 16]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm test
8 changes: 7 additions & 1 deletion .github/workflows/publish-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ name: publish-on-tag
on:
push:
tags:
- '*'
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Publish
env:
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
Expand Down
93 changes: 0 additions & 93 deletions Gruntfile.js

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# iso-8859-8-i [![iso-8859-8-i on npm](https://img.shields.io/npm/v/iso-8859-8-i)](https://www.npmjs.com/package/iso-8859-8-i)
# iso-8859-8-i [![Build status](https://github.com/mathiasbynens/iso-8859-8-i/workflows/run-checks/badge.svg)](https://github.com/mathiasbynens/iso-8859-8-i/actions?query=workflow%3Arun-checks) [![iso-8859-8-i on npm](https://img.shields.io/npm/v/iso-8859-8-i)](https://www.npmjs.com/package/iso-8859-8-i)

_iso-8859-8-i_ is a robust JavaScript implementation of [the iso-8859-8-i character encoding as defined by the Encoding Standard](https://encoding.spec.whatwg.org/#iso-8859-8-i).

Expand Down
5 changes: 1 addition & 4 deletions data/index.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Any copyright is dedicated to the Public Domain.
# https://creativecommons.org/publicdomain/zero/1.0/
#
# For details on index index-iso-8859-8.txt see the Encoding Standard
# https://encoding.spec.whatwg.org/
#
# Identifier: 7657a9ca3fa875990da960d3f812eea28dcd0ae6ed55a18d5394303c86f5484b
# Date: 2016-01-20
# Date: 2018-01-06

0 0x0080 € (<control>)
1 0x0081  (<control>)
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
"cover": "istanbul cover --report html --verbose --dir coverage tests/tests.js"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-shell": "^1.1.2",
"grunt-template": "^0.2.3",
"istanbul": "^0.4.2",
"jsesc": "^2.1.0"
"jsesc": "^3.0.2",
"lodash.template": "^4.5.0"
}
}
20 changes: 10 additions & 10 deletions scripts/export-data.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var fs = require('fs');
var jsesc = require('jsesc');
const fs = require('fs');
const jsesc = require('jsesc');

function readJSON(path) {
return JSON.parse(fs.readFileSync(path, 'utf-8'));
}

module.exports = {
'labels': jsesc(readJSON('data/labels.json'), {
'compact': false,
'indentLevel': 2
labels: jsesc(readJSON('data/labels.json'), {
compact: false,
indentLevel: 2,
}),
'encoded': jsesc(readJSON('data/encoded.json'), { 'wrap': true }),
'decoded': jsesc(readJSON('data/decoded.json'), { 'wrap': true }),
'indexByCodePoint': jsesc(readJSON('data/index-by-code-point.json')),
'indexByPointer': jsesc(readJSON('data/index-by-pointer.json')),
'version': readJSON('package.json').version
encoded: jsesc(readJSON('data/encoded.json'), { wrap: true }),
decoded: jsesc(readJSON('data/decoded.json'), { wrap: true }),
indexByCodePoint: jsesc(readJSON('data/index-by-code-point.json')),
indexByPointer: jsesc(readJSON('data/index-by-pointer.json')),
version: readJSON('package.json').version
};
60 changes: 38 additions & 22 deletions scripts/transform-data.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
var fs = require('fs');
var jsesc = require('jsesc');
require('string.fromcodepoint');
const fs = require('fs');
const jsesc = require('jsesc');
const template = require('lodash.template');

function format(object) {
return jsesc(object, {
'json': true,
'compact': false
json: true,
compact: false,
}) + '\n';
}

function parse(source) {
var indexByCodePoint = {};
var indexByPointer = {};
var decoded = '';
var encoded = '';
const indexByCodePoint = {};
const indexByPointer = {};
let decoded = '';
let encoded = '';
var lines = source.split('\n');
lines.forEach(function(line) {
var data = line.trim().split('\t');
for (const line of lines) {
const data = line.trim().split('\t');
if (data.length != 3) {
return;
continue;
}
var pointer = Number(data[0]);
var codePoint = Number(data[1]);
var symbol = String.fromCodePoint(codePoint);
const pointer = Number(data[0]);
const codePoint = Number(data[1]);
const symbol = String.fromCodePoint(codePoint);
decoded += symbol;
encoded += String.fromCodePoint(pointer + 0x80);
indexByCodePoint[codePoint] = pointer;
indexByPointer[pointer] = symbol;
});
}
return {
'decoded': decoded,
'encoded': encoded,
'indexByCodePoint': indexByCodePoint,
'indexByPointer': indexByPointer
decoded: decoded,
encoded: encoded,
indexByCodePoint: indexByCodePoint,
indexByPointer: indexByPointer
};
}

var source = fs.readFileSync('./data/index.txt', 'utf-8');
var result = parse(source);
const source = fs.readFileSync('./data/index.txt', 'utf-8');
const result = parse(source);
fs.writeFileSync(
'./data/index-by-code-point.json',
format(result.indexByCodePoint)
Expand All @@ -54,3 +54,19 @@ fs.writeFileSync(
'./data/encoded.json',
format(result.encoded)
);

// tests/tests.src.js → tests/tests.js
const TEST_TEMPLATE = fs.readFileSync('./tests/tests.src.js', 'utf8');
const createTest = template(TEST_TEMPLATE, {
interpolate: /<\%=([\s\S]+?)%\>/g,
});
const testCode = createTest(require('./export-data.js'));
fs.writeFileSync('./tests/tests.js', testCode);

// src/iso-8859-8-i.src.js -> iso-8859-8-i.js
const LIB_TEMPLATE = fs.readFileSync('./src/iso-8859-8-i.src.js', 'utf8');
const createLib = template(LIB_TEMPLATE, {
interpolate: /<\%=([\s\S]+?)%\>/g,
});
const libCode = createLib(require('./export-data.js'));
fs.writeFileSync('./iso-8859-8-i.js', libCode);
6 changes: 3 additions & 3 deletions src/iso-8859-8-i.js → src/iso-8859-8-i.src.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! https://mths.be/iso-8859-8-i v<%= version %> by @mathias | MIT license */
;(function(root) {
;(function() {

var object = {};
var hasOwnProperty = object.hasOwnProperty;
Expand Down Expand Up @@ -100,9 +100,9 @@
encode: encode,
decode: decode,
labels: <%= labels %>,
version: '<%= version %>'
version: '<%= version %>',
};

module.exports = iso88598i;

}(this));
}());
Loading

0 comments on commit cb6cc7a

Please sign in to comment.