@0x6b/textlint-rule-normalize-whitespaces
Advanced tools
Comparing version 1.0.2 to 1.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _SPACE_CHARACTERS = require("./SPACE_CHARACTERS"); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var _execall = _interopRequireDefault(require("execall")); | ||
var execall = require("execall"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var spaceCharacterPattern = new RegExp(require("regenerate")(_SPACE_CHARACTERS.SPACE_CHARACTERS.map(SPACE_CHARACTER => SPACE_CHARACTER.code)), "g"); | ||
var spaceCharacterPattern = /[\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]/g; | ||
var unicodeEscape = function unicodeEscape(str) { | ||
return str.replace(/./g, function (c) { | ||
return "\\u" + ("000" + c.charCodeAt(0).toString(16)).substr(-4); | ||
}); | ||
var escapeUnicode = str => str.replace(/./g, c => "\\u".concat("000".concat(c.charCodeAt(0).toString(16)).substr(-4))); | ||
var getName = char => { | ||
var matchChar = _SPACE_CHARACTERS.SPACE_CHARACTERS.find(SPACE_CHARACTER => SPACE_CHARACTER.code === char); | ||
return !matchChar ? "" : matchChar.name; | ||
}; | ||
var getName = function getName(char) { | ||
var matchChar = _SPACE_CHARACTERS.SPACE_CHARACTERS.find(function (SPACE_CHARACTER) { | ||
return SPACE_CHARACTER.code === char; | ||
}); | ||
return !matchChar ? "" : matchChar.name; | ||
}; | ||
var reporter = function reporter(_ref) { | ||
var Syntax = _ref.Syntax, | ||
RuleError = _ref.RuleError, | ||
getSource = _ref.getSource, | ||
fixer = _ref.fixer, | ||
report = _ref.report; | ||
return _defineProperty({}, Syntax.Str, function (node) { | ||
execall(spaceCharacterPattern, getSource(node)).forEach(function (_ref2) { | ||
var index = _ref2.index, | ||
match = _ref2.match; | ||
var reporter = (_ref) => { | ||
var { | ||
Syntax, | ||
RuleError, | ||
getSource, | ||
fixer, | ||
report | ||
} = _ref; | ||
return { | ||
[Syntax.Str](node) { | ||
(0, _execall.default)(spaceCharacterPattern, getSource(node)).forEach((_ref2) => { | ||
var { | ||
index, | ||
match | ||
} = _ref2; | ||
report(node, new RuleError("Found exotic space character(".concat(getName(match), " ").concat(escapeUnicode(match), ")"), { | ||
index, | ||
fix: fixer.replaceTextRange([index, index + 1], " ") | ||
})); | ||
}); | ||
} | ||
report(node, new RuleError("Found exotic space character(" + getName(match) + " " + unicodeEscape(match) + ")", { | ||
index: index, | ||
fix: fixer.replaceTextRange([index, index + 1], " ") | ||
})); | ||
}); | ||
}); | ||
}; | ||
}; | ||
module.exports = { | ||
linter: reporter, | ||
fixer: reporter | ||
var _default = { | ||
linter: reporter, | ||
fixer: reporter | ||
}; | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var SPACE_CHARACTERS = [{ code: "\xA0", name: "NO-BREAK SPACE" }, { code: "\u1680", name: "OGHAM SPACE MARK" }, { code: "\u180E", name: "MONGOLIAN VOWEL SEPARATOR" }, { code: "\u2000", name: "EN QUAD" }, { code: "\u2001", name: "EM QUAD" }, { code: "\u2002", name: "EN SPACE" }, { code: "\u2003", name: "EM SPACE" }, { code: "\u2004", name: "THREE-PER-EM SPACE" }, { code: "\u2005", name: "FOUR-PER-EM SPACE" }, { code: "\u2006", name: "SIX-PER-EM SPACE" }, { code: "\u2007", name: "FIGURE SPACE" }, { code: "\u2008", name: "PUNCTUATION SPACE" }, { code: "\u2009", name: "THIN SPACE" }, { code: "\u200A", name: "HAIR SPACE" }, { code: "\u202F", name: "NARROW NON-BREAKING SPACE" }, { code: "\u205F", name: "MEDIUM MATHEMATICAL SPACE" }, { code: "\u3000", name: "IDEOGRAPHIC SPACE" }]; | ||
var ZERO_WIDTH_SPACE_CHARACTERS = [{ code: "\u200B", name: "ZERO WIDTH SPACE" }, { code: "\uFEFF", name: "ZERO WIDTH NO-BREAK SPACE" }]; | ||
exports.ZERO_WIDTH_SPACE_CHARACTERS = exports.SPACE_CHARACTERS = void 0; | ||
var SPACE_CHARACTERS = [{ | ||
code: "\u00a0", | ||
name: "NO-BREAK SPACE" | ||
}, { | ||
code: "\u1680", | ||
name: "OGHAM SPACE MARK" | ||
}, { | ||
code: "\u180e", | ||
name: "MONGOLIAN VOWEL SEPARATOR" | ||
}, { | ||
code: "\u2000", | ||
name: "EN QUAD" | ||
}, { | ||
code: "\u2001", | ||
name: "EM QUAD" | ||
}, { | ||
code: "\u2002", | ||
name: "EN SPACE" | ||
}, { | ||
code: "\u2003", | ||
name: "EM SPACE" | ||
}, { | ||
code: "\u2004", | ||
name: "THREE-PER-EM SPACE" | ||
}, { | ||
code: "\u2005", | ||
name: "FOUR-PER-EM SPACE" | ||
}, { | ||
code: "\u2006", | ||
name: "SIX-PER-EM SPACE" | ||
}, { | ||
code: "\u2007", | ||
name: "FIGURE SPACE" | ||
}, { | ||
code: "\u2008", | ||
name: "PUNCTUATION SPACE" | ||
}, { | ||
code: "\u2009", | ||
name: "THIN SPACE" | ||
}, { | ||
code: "\u200a", | ||
name: "HAIR SPACE" | ||
}, { | ||
code: "\u202f", | ||
name: "NARROW NON-BREAKING SPACE" | ||
}, { | ||
code: "\u205f", | ||
name: "MEDIUM MATHEMATICAL SPACE" | ||
}, { | ||
code: "\u3000", | ||
name: "IDEOGRAPHIC SPACE" | ||
}]; | ||
exports.SPACE_CHARACTERS = SPACE_CHARACTERS; | ||
var ZERO_WIDTH_SPACE_CHARACTERS = [{ | ||
code: "\u200b", | ||
name: "ZERO WIDTH SPACE" | ||
}, { | ||
code: "\ufeff", | ||
name: "ZERO WIDTH NO-BREAK SPACE" | ||
}]; | ||
exports.ZERO_WIDTH_SPACE_CHARACTERS = ZERO_WIDTH_SPACE_CHARACTERS; | ||
//# sourceMappingURL=SPACE_CHARACTERS.js.map |
{ | ||
"name": "@0x6b/textlint-rule-normalize-whitespaces", | ||
"version": "1.1.0", | ||
"description": "textlint rule which normalizes whitespaces in the document.", | ||
"keywords": [ | ||
"textlintrule" | ||
], | ||
"homepage": "https://github.com/0x6b/textlint-rule-normalize-whitespaces", | ||
"bugs": { | ||
"url": "https://github.com/0x6b/textlint-rule-normalize-whitespaces/issues" | ||
}, | ||
"license": "MIT", | ||
"author": "0x6b", | ||
"license": "MIT", | ||
"description": "textlint rule which normalizes whitespaces in the document.", | ||
"version": "1.0.2", | ||
"keywords": ["textlintrule"], | ||
"files": [ | ||
"lib/", | ||
"src/" | ||
], | ||
"main": "lib/index.js", | ||
@@ -12,3 +22,2 @@ "directories": { | ||
}, | ||
"files": ["lib/", "src/"], | ||
"repository": { | ||
@@ -18,23 +27,36 @@ "type": "git", | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/0x6b/textlint-rule-normalize-whitespaces/issues" | ||
}, | ||
"homepage": "https://github.com/0x6b/textlint-rule-normalize-whitespaces", | ||
"scripts": { | ||
"build": "textlint-scripts build", | ||
"test": "textlint-scripts test", | ||
"prettier": "prettier --write \"**/*.js\"", | ||
"precommit": "lint-staged", | ||
"postcommit": "git reset", | ||
"prepublish": "npm run --if-present build" | ||
"prepublish": "yarn build", | ||
"test": "textlint-scripts test", | ||
"prettier": "prettier --write \"**/*.{js,ts,json}\"", | ||
"watch": "textlint-scripts build --watch" | ||
}, | ||
"dependencies": { | ||
"execall": "^1.0.0" | ||
"execall": "^2.0.0", | ||
"regenerate": "^1.3.3" | ||
}, | ||
"devDependencies": { | ||
"@textlint/types": "^1.2.0", | ||
"@types/node": "^12.6.2", | ||
"husky": "^0.14.3", | ||
"jest": "^22.1.4", | ||
"lint-staged": "^6.0.0", | ||
"prettier": "^1.10.2", | ||
"textlint-scripts": "^1.2.4" | ||
"textlint-scripts": "^3.0.0-beta.1", | ||
"ts-node": "^8.3.0", | ||
"typescript": "^3.5.3" | ||
}, | ||
"engines": { | ||
"node": ">= 6" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx,css}": [ | ||
"git stash --keep-index", | ||
"prettier --write", | ||
"git stash pop" | ||
] | ||
}, | ||
"prettier": { | ||
@@ -44,5 +66,10 @@ "printWidth": 120, | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx,css}": ["prettier --write", "git add"] | ||
"jest": { | ||
"displayName": "textlint-rule-normalize-whitespaces", | ||
"collectCoverage": true, | ||
"verbose": true, | ||
"testMatch": [ | ||
"<rootDir>/test/**/*.js" | ||
] | ||
} | ||
} |
@@ -34,2 +34,4 @@ # textlint-rule-normalize-whitespaces | ||
This module requires Node.js >= 6. | ||
## Usage | ||
@@ -36,0 +38,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14832
163
81
2
9
1
+ Addedregenerate@^1.3.3
+ Addedclone-regexp@2.2.0(transitive)
+ Addedexecall@2.0.0(transitive)
+ Addedis-regexp@2.1.0(transitive)
+ Addedregenerate@1.4.2(transitive)
- Removedclone-regexp@1.0.1(transitive)
- Removedexecall@1.0.0(transitive)
- Removedis-regexp@1.0.0(transitive)
- Removedis-supported-regexp-flag@1.0.1(transitive)
Updatedexecall@^2.0.0