unicode-search 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -6
- package/package.json +14 -14
- package/unicode-search.bundle.js +87 -20
- package/unicode-search.js +0 -27
package/README.md
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/unicode-search)
|
|
2
|
+
[](https://github.com/Lucas-C/unicode-search/actions/workflows/build.yml?query=branch%3Amaster)
|
|
3
|
+
[](https://snyk.io/test/github/lucas-c/unicode-search)
|
|
4
|
+
|
|
1
5
|
# unicode-search
|
|
2
6
|
|
|
3
7
|
Command-line interface to search UTF8 characters by name from a JSON cache, without requiring an Internet connection.
|
|
4
8
|
|
|
9
|
+
https://www.npmjs.com/package/unicode-search
|
|
10
|
+
|
|
5
11
|
Inspired by https://github.com/eversport/node-unicodetable
|
|
6
12
|
|
|
13
|
+
Online, I would recommend to use this tag-based searched: http://graphemica.com/characters/tags/
|
|
7
14
|
|
|
8
|
-
## Installation
|
|
9
15
|
|
|
16
|
+
## Installation
|
|
10
17
|
```
|
|
11
|
-
|
|
18
|
+
npm install -g unicode-search
|
|
12
19
|
```
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
You can also directly invoke `unicode-search` using `npx`:
|
|
15
22
|
|
|
16
23
|
```
|
|
17
|
-
|
|
24
|
+
npx unicode-search --help
|
|
18
25
|
```
|
|
19
26
|
|
|
20
27
|
|
|
21
28
|
## Usage
|
|
22
29
|
|
|
23
30
|
```
|
|
24
|
-
unicode-search -
|
|
31
|
+
unicode-search -b Emoticons -k name,string "check mark"
|
|
32
|
+
```
|
|
33
|
+
```
|
|
34
|
+
unicode-search -b Emoticons -k name,string > all_emoticons.txt
|
|
25
35
|
```
|
|
26
36
|
|
|
27
37
|
### Options
|
|
@@ -41,7 +51,14 @@ The following is for your quick reference (may not be the latest version):
|
|
|
41
51
|
Options:
|
|
42
52
|
|
|
43
53
|
-V, --version output the version number
|
|
54
|
+
-b, --block [name] Filter by block name, e.g. "Emoticon"
|
|
44
55
|
-c, --category [name] Filter by category name, e.g. "So"
|
|
56
|
+
-k, --keys [keys] Output only the selected field(s), e.g. "name,string"
|
|
45
57
|
-h, --help output usage information
|
|
46
|
-
|
|
47
58
|
```
|
|
59
|
+
|
|
60
|
+
# Release checklist
|
|
61
|
+
1. `version=1.X.Y`
|
|
62
|
+
1. `sed -i "s/\"version\": \"1.\+\"/\"version\": \"$version\"/" package.json`
|
|
63
|
+
1. `npm pack --dry-run && npm publish` to upload on [npmjs.com](https://www.npmjs.com/package/unicode-search)
|
|
64
|
+
1. `git commit -am "New release: $version" && git push && git tag $version && git push --tags`
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unicode-search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Command-line interface to search unicode characters by keywords",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "git+ssh://git@github.com/Lucas-C/unicode-search.git"
|
|
8
|
+
},
|
|
7
9
|
"author": "Lucas Cimon <lucas.cimon@gmail.com>",
|
|
8
10
|
"bin": {
|
|
9
|
-
"unicode-search": "
|
|
11
|
+
"unicode-search": "unicode-search.bundle.js"
|
|
10
12
|
},
|
|
11
13
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"unicode-search": "node unicode-search.bundle.js"
|
|
14
|
+
"test": "standard --fix",
|
|
15
|
+
"prepublish": "npm run transpile && npm run generateDistJsons",
|
|
16
|
+
"transpile": "babel ./generateDistJsons.js --out-file ./generateDistJsons.bundle.js && babel ./unicode-search.js --out-file ./unicode-search.bundle.js",
|
|
17
|
+
"generateDistJsons": "npm run download && node generateDistJsons.bundle.js",
|
|
18
|
+
"download": "wget \"https://unicode.org/Public/10.0.0/ucd/UnicodeData.txt\" -O UnicodeData.txt && wget \"https://unicode.org/Public/10.0.0/ucd/Blocks.txt\" -O Blocks.txt"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"commander": "
|
|
21
|
+
"commander": "^14.0.3"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"babel
|
|
24
|
-
"babel
|
|
24
|
+
"@babel/cli": "^7.28.6",
|
|
25
|
+
"@babel/preset-env": "^7.29.0",
|
|
25
26
|
"bufferstream": "^0.6.2",
|
|
26
|
-
"standard": "^
|
|
27
|
+
"standard": "^17.1.2"
|
|
27
28
|
},
|
|
28
29
|
"files": [
|
|
29
|
-
"unicode-search.js",
|
|
30
30
|
"unicode-search.bundle.js",
|
|
31
31
|
"UnicodeData.json"
|
|
32
32
|
],
|
package/unicode-search.bundle.js
CHANGED
|
@@ -1,26 +1,93 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
"use strict";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
5
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
|
+
var commander = require('commander');
|
|
8
|
+
var pkg = require('./package.json');
|
|
9
|
+
var PRETTY_CATEGORY = {
|
|
10
|
+
Cc: 'Other, Control',
|
|
11
|
+
Cf: 'Other, Format',
|
|
12
|
+
Cn: 'Other, Not Assigned',
|
|
13
|
+
Co: 'Other, Private Use',
|
|
14
|
+
Cs: 'Other, Surrogate',
|
|
15
|
+
LC: 'Letter, Cased',
|
|
16
|
+
Ll: 'Letter, Lowercase',
|
|
17
|
+
Lm: 'Letter, Modifier',
|
|
18
|
+
Lo: 'Letter, Other',
|
|
19
|
+
Lt: 'Letter, Titlecase',
|
|
20
|
+
Lu: 'Letter, Uppercase',
|
|
21
|
+
Mc: 'Mark, Spacing Combining',
|
|
22
|
+
Me: 'Mark, Enclosing',
|
|
23
|
+
Mn: 'Mark, Nonspacing',
|
|
24
|
+
Nd: 'Number, Decimal Digit',
|
|
25
|
+
Nl: 'Number, Letter',
|
|
26
|
+
No: 'Number, Other',
|
|
27
|
+
Pc: 'Punctuation, Connector',
|
|
28
|
+
Pd: 'Punctuation, Dash',
|
|
29
|
+
Pe: 'Punctuation, Close',
|
|
30
|
+
Pf: 'Punctuation, Final quote',
|
|
31
|
+
Pi: 'Punctuation, Initial quote',
|
|
32
|
+
Po: 'Punctuation, Other',
|
|
33
|
+
Ps: 'Punctuation, Open',
|
|
34
|
+
Sc: 'Symbol, Currency',
|
|
35
|
+
Sk: 'Symbol, Modifier',
|
|
36
|
+
Sm: 'Symbol, Math',
|
|
37
|
+
So: 'Symbol, Other',
|
|
38
|
+
Zl: 'Separator, Line',
|
|
39
|
+
Zp: 'Separator, Paragraph',
|
|
40
|
+
Zs: 'Separator, Space'
|
|
41
|
+
};
|
|
42
|
+
commander.version(pkg.version).option('-b, --block [name]', 'Filter by block name, e.g. "Emoticon"').option('-c, --category [name]', 'Filter by category name, e.g. "So"').option('-k, --keys [keys]', 'Output only the selected field(s), e.g. "name,string"').parse(process.argv);
|
|
43
|
+
var block = commander.block,
|
|
44
|
+
category = commander.category,
|
|
45
|
+
keys = commander.keys;
|
|
46
|
+
var uppercaseKeyword = (commander.args[0] || '').toUpperCase();
|
|
47
|
+
var unicodeData = require('./UnicodeData.json');
|
|
48
|
+
var blocks = require('./Blocks.json');
|
|
49
|
+
var findBlockName = function findBlockName(codepoint) {
|
|
50
|
+
// yes, dichotomic search would be faster
|
|
51
|
+
// but we have only 260 entries
|
|
52
|
+
codepoint = codepoint.padStart(6, '0');
|
|
53
|
+
var index = -1;
|
|
54
|
+
var _iterator = _createForOfIteratorHelper(blocks),
|
|
55
|
+
_step;
|
|
56
|
+
try {
|
|
57
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
58
|
+
var _block = _step.value;
|
|
59
|
+
if (_block.rangeStart > codepoint) break;
|
|
60
|
+
index++;
|
|
20
61
|
}
|
|
21
|
-
|
|
22
|
-
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_iterator.e(err);
|
|
64
|
+
} finally {
|
|
65
|
+
_iterator.f();
|
|
66
|
+
}
|
|
67
|
+
return blocks[index].blockName;
|
|
68
|
+
};
|
|
69
|
+
for (var _i = 0, _Object$values = Object.values(unicodeData); _i < _Object$values.length; _i++) {
|
|
70
|
+
var uChar = _Object$values[_i];
|
|
71
|
+
if (category && uChar.category !== category) continue;
|
|
72
|
+
if (uppercaseKeyword && uChar.name.indexOf(uppercaseKeyword) < 0) continue;
|
|
73
|
+
uChar.block = findBlockName(uChar.value);
|
|
74
|
+
if (block && uChar.block.toLowerCase() !== block.toLowerCase()) continue;
|
|
75
|
+
uChar.categoryHumanReadble = PRETTY_CATEGORY[uChar.category];
|
|
76
|
+
uChar.string = String.fromCodePoint('0x' + uChar.value);
|
|
77
|
+
if (keys) {
|
|
78
|
+
var _iterator2 = _createForOfIteratorHelper(keys.split(',')),
|
|
79
|
+
_step2;
|
|
80
|
+
try {
|
|
81
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
82
|
+
var key = _step2.value;
|
|
83
|
+
console.log(uChar[key]);
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
_iterator2.e(err);
|
|
87
|
+
} finally {
|
|
88
|
+
_iterator2.f();
|
|
23
89
|
}
|
|
90
|
+
} else {
|
|
24
91
|
console.log(uChar);
|
|
25
|
-
|
|
92
|
+
}
|
|
26
93
|
}
|
package/unicode-search.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import "core-js/modules/es7.object.values";
|
|
3
|
-
|
|
4
|
-
const commander = require('commander')
|
|
5
|
-
const pkg = require('./package.json')
|
|
6
|
-
|
|
7
|
-
commander
|
|
8
|
-
.version(pkg.version)
|
|
9
|
-
.option('-c, --category [name]', 'Filter by category name, e.g. "So"')
|
|
10
|
-
.parse(process.argv)
|
|
11
|
-
|
|
12
|
-
let { category } = commander
|
|
13
|
-
|
|
14
|
-
const uppercaseKeyword = process.argv.pop().toUpperCase()
|
|
15
|
-
|
|
16
|
-
const unicodeData = require('./UnicodeData.json')
|
|
17
|
-
|
|
18
|
-
for (let uChar of Object.values(unicodeData)) {
|
|
19
|
-
if (category && uChar.category != category) {
|
|
20
|
-
continue
|
|
21
|
-
}
|
|
22
|
-
if (uChar.name.indexOf(uppercaseKeyword) < 0) {
|
|
23
|
-
continue
|
|
24
|
-
}
|
|
25
|
-
console.log(uChar)
|
|
26
|
-
console.log(String.fromCharCode(parseInt(uChar.value, 16)))
|
|
27
|
-
}
|