Skip to content

chore: replace unorm with String.prototype.normalize #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ via [Unicodeの特殊な文字 “結合文字列” | ものかの](http://tama
単独で存在できる゜`\u309b`と゛`\u309c`は置換することでnormalizeする。

- [String.prototype.normalize() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
- [walling/unorm: JavaScript Unicode 8.0 Normalization - NFC, NFD, NFKC, NFKD.](https://github.com/walling/unorm)
- [UTF-8にもいろいろある - ザリガニが見ていた...。](http://d.hatena.ne.jp/zariganitosh/20131124/utf8_nfd_nfc_bom)
- [[JavaScript]\uXXXX形式にunicodeエスケープする関数 / LiosK-free Blog](http://liosk.blog103.fc2.com/blog-entry-67.html)
- [unoh.github.com by unoh](http://unoh.github.io/2007/09/04/unicode-on-mac.html)
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
"devDependencies": {
"@textlint/types": "^13.0.2",
"@types/node": "^18.11.18",
"@types/unorm": "^1.3.28",
"textlint-scripts": "^13.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"dependencies": {
"match-index": "^1.0.3",
"textlint-rule-helper": "^2.3.0",
"unorm": "^1.4.1"
"textlint-rule-helper": "^2.3.0"
}
}
3 changes: 1 addition & 2 deletions src/textlint-rule-no-nfd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { matchCaptureGroupAll } from "match-index"
import { RuleHelper } from "textlint-rule-helper";
import { TextlintRuleReporter } from "@textlint/types";
import unorm from "unorm";

const reporter: TextlintRuleReporter = function (context) {
const { Syntax, RuleError, report, fixer, getSource, locator } = context;
Expand All @@ -21,7 +20,7 @@ const reporter: TextlintRuleReporter = function (context) {
// \u309b\u309c => \u309a\u3099
const dakutenChars = text.slice(index - 1, index + 1);
const nfdlized = dakutenChars.replace("\u309B", "\u3099").replace("\u309C", "\u309A");
const expectedText = unorm.nfc(nfdlized);
const expectedText = nfdlized.normalize('NFC');
const ruleError = new RuleError(`Disallow to use NFD(well-known as UTF8-MAC 濁点): "${dakutenChars}" => "${expectedText}"`, {
padding: locator.at(index),
fix: fixer.replaceTextRange([index - 1, index + 1], expectedText)
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1160,11 +1160,6 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==

"@types/unorm@^1.3.28":
version "1.3.28"
resolved "https://registry.yarnpkg.com/@types/unorm/-/unorm-1.3.28.tgz#580141162f2fd221faae2b2d68da6c839402c375"
integrity sha512-l3uh18vcvkQ964HSK7Tx0YbhxN/Hj+k1w3nLT08n770lngqVKljmF7Ht4e7elFbx6L2WYse97whtpJOo8MHtxQ==

"@ungap/[email protected]":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"
Expand Down Expand Up @@ -3029,11 +3024,6 @@ unist-util-visit@^2.0.3:
unist-util-is "^4.0.0"
unist-util-visit-parents "^3.0.0"

unorm@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/unorm/-/unorm-1.6.0.tgz#029b289661fba714f1a9af439eb51d9b16c205af"
integrity sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA==

update-browserslist-db@^1.0.9:
version "1.0.10"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz#0f54b876545726f17d00cd9a2561e6dade943ff3"
Expand Down