Comparing version 0.7.4 to 0.8.0
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// {% x y %}z{% endx %} | ||
@@ -22,2 +20,2 @@ // \{\% ([^ ]+?) [^\%]*?\%\} ([^ ]+?) [^\%]*? | ||
}; | ||
exports.default = parser; | ||
export default parser; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseIngoredCase = void 0; | ||
const ignoredCaseMatcher = /^(?:(?<prefix>.+?)-,)?(?<textStart>.+?)(?:,(?<textEnd>.+?))?(?:,-(?<suffix>.+?))?$/; | ||
const parseIngoredCase = (text) => { | ||
export const parseIngoredCase = (text) => { | ||
const matchResult = text.match(ignoredCaseMatcher); | ||
@@ -17,3 +14,2 @@ if (matchResult) { | ||
}; | ||
exports.parseIngoredCase = parseIngoredCase; | ||
const parser = (data) => { | ||
@@ -24,3 +20,3 @@ const { ignoredByRules, value: raw } = data; | ||
while ((result = matcher.exec(raw)) !== null) { | ||
const ignoredCase = (0, exports.parseIngoredCase)(result[1]); | ||
const ignoredCase = parseIngoredCase(result[1]); | ||
if (ignoredCase) { | ||
@@ -32,2 +28,2 @@ ignoredByRules.push(ignoredCase); | ||
}; | ||
exports.default = parser; | ||
export default parser; |
@@ -1,10 +0,6 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const unified_1 = __importDefault(require("unified")); | ||
const remark_parse_1 = __importDefault(require("remark-parse")); | ||
const remark_frontmatter_1 = __importDefault(require("remark-frontmatter")); | ||
const parser_1 = require("../parser"); | ||
import { unified } from 'unified'; | ||
import markdown from 'remark-parse'; | ||
import gfm from 'remark-gfm'; | ||
import frontmatter from 'remark-frontmatter'; | ||
import { isRawMark, MarkSideType, MarkType } from '../parser'; | ||
const parsePosition = (position) => { | ||
@@ -29,3 +25,2 @@ var _a, _b; | ||
'delete', | ||
'footnote', | ||
'link', | ||
@@ -42,3 +37,3 @@ 'linkReference' | ||
'imageReference', | ||
'footnoteReference', | ||
'footnoteDefinition', | ||
'html' | ||
@@ -102,3 +97,3 @@ ]; | ||
const mark = { | ||
type: parser_1.MarkType.RAW, | ||
type: MarkType.RAW, | ||
// TODO: typeof RawMark.meta | ||
@@ -113,3 +108,3 @@ meta: inline.type, | ||
if (mark.startValue.match(/<code.*>/)) { | ||
const rawMark = Object.assign(Object.assign({}, mark), { code: parser_1.MarkSideType.LEFT }); | ||
const rawMark = Object.assign(Object.assign({}, mark), { code: MarkSideType.LEFT }); | ||
unresolvedCodeMarks.push(rawMark); | ||
@@ -120,3 +115,3 @@ marks.push(rawMark); | ||
else if (mark.startValue.match(/<\/code.*>/)) { | ||
const rawMark = Object.assign(Object.assign({}, mark), { code: parser_1.MarkSideType.RIGHT }); | ||
const rawMark = Object.assign(Object.assign({}, mark), { code: MarkSideType.RIGHT }); | ||
const leftCode = unresolvedCodeMarks.pop(); | ||
@@ -140,3 +135,3 @@ if (leftCode) { | ||
const mark = { | ||
type: parser_1.MarkType.HYPER, | ||
type: MarkType.HYPER, | ||
// TODO: typeof RawMark.meta | ||
@@ -155,7 +150,7 @@ meta: inline.type, | ||
.map((mark) => { | ||
if ((0, parser_1.isRawMark)(mark)) { | ||
if (mark.code === parser_1.MarkSideType.RIGHT) { | ||
if (isRawMark(mark)) { | ||
if (mark.code === MarkSideType.RIGHT) { | ||
return; | ||
} | ||
if (mark.code === parser_1.MarkSideType.LEFT) { | ||
if (mark.code === MarkSideType.LEFT) { | ||
const { rightPair } = mark; | ||
@@ -185,5 +180,6 @@ mark.startValue = str.substring(mark.startIndex + offset, mark.endIndex + offset); | ||
const blockMarks = []; | ||
const tree = (0, unified_1.default)() | ||
.use(remark_parse_1.default) | ||
.use(remark_frontmatter_1.default) | ||
const tree = unified() | ||
.use(markdown) | ||
.use(gfm) | ||
.use(frontmatter) | ||
.parse(modifiedValue); | ||
@@ -209,3 +205,3 @@ // - travel and record all paragraphs/headings/table-cells into blocks | ||
b.hyperMarks.push({ | ||
type: parser_1.MarkType.RAW, | ||
type: MarkType.RAW, | ||
meta, | ||
@@ -225,2 +221,2 @@ startIndex: index - position.start, | ||
}; | ||
exports.default = parser; | ||
export default parser; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// TODO: ::: tips 提示... | ||
@@ -40,2 +38,2 @@ // | ||
}; | ||
exports.default = parser; | ||
export default parser; |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const report_1 = require("./report"); | ||
import { env } from './report'; | ||
/** | ||
@@ -9,3 +7,3 @@ * @param {string} str | ||
*/ | ||
const findIgnoredMarks = (str, ignoredCases = [], logger = report_1.env.defaultLogger) => { | ||
const findIgnoredMarks = (str, ignoredCases = [], logger = env.defaultLogger) => { | ||
const marks = []; | ||
@@ -56,2 +54,2 @@ ignoredCases.forEach(({ prefix, textStart, textEnd, suffix }) => { | ||
}; | ||
exports.default = findIgnoredMarks; | ||
export default findIgnoredMarks; |
@@ -1,10 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readRc = exports.report = exports.runWithConfig = exports.run = void 0; | ||
var run_1 = require("./run"); | ||
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_1.run; } }); | ||
Object.defineProperty(exports, "runWithConfig", { enumerable: true, get: function () { return run_1.runWithConfig; } }); | ||
var report_1 = require("./report"); | ||
Object.defineProperty(exports, "report", { enumerable: true, get: function () { return report_1.report; } }); | ||
var rc_1 = require("./rc"); | ||
Object.defineProperty(exports, "readRc", { enumerable: true, get: function () { return rc_1.readRc; } }); | ||
export { run, runWithConfig } from './run'; | ||
export { report } from './report'; | ||
export { readRc } from './rc'; |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const report_1 = require("./report"); | ||
import { ValidationTarget } from './report'; | ||
const isInRange = (start, end, mark) => { | ||
@@ -10,7 +8,7 @@ return start <= mark.end && end >= mark.start; | ||
ignored: false, | ||
[report_1.ValidationTarget.VALUE]: false, | ||
[report_1.ValidationTarget.SPACE_AFTER]: false, | ||
[report_1.ValidationTarget.START_VALUE]: false, | ||
[report_1.ValidationTarget.END_VALUE]: false, | ||
[report_1.ValidationTarget.INNER_SPACE_BEFORE]: false | ||
[ValidationTarget.VALUE]: false, | ||
[ValidationTarget.SPACE_AFTER]: false, | ||
[ValidationTarget.START_VALUE]: false, | ||
[ValidationTarget.END_VALUE]: false, | ||
[ValidationTarget.INNER_SPACE_BEFORE]: false | ||
}; | ||
@@ -23,12 +21,12 @@ // - group: startValue, innerSpaceBefore, endValue, spaceAfter | ||
if (isInRange(index, index + (startValue || '').length, mark)) { | ||
result[report_1.ValidationTarget.SPACE_AFTER] = result.ignored = true; | ||
result[ValidationTarget.SPACE_AFTER] = result.ignored = true; | ||
} | ||
if (isInRange(index + (startValue || '').length, index + (startValue || '').length + (innerSpaceBefore || '').length, mark)) { | ||
result[report_1.ValidationTarget.INNER_SPACE_BEFORE] = result.ignored = true; | ||
result[ValidationTarget.INNER_SPACE_BEFORE] = result.ignored = true; | ||
} | ||
if (isInRange(endIndex, endIndex + (endValue || '').length, mark)) { | ||
result[report_1.ValidationTarget.END_VALUE] = result.ignored = true; | ||
result[ValidationTarget.END_VALUE] = result.ignored = true; | ||
} | ||
if (isInRange(endIndex + (endValue || '').length, endIndex + (endValue || '').length + (spaceAfter || '').length, mark)) { | ||
result[report_1.ValidationTarget.SPACE_AFTER] = result.ignored = true; | ||
result[ValidationTarget.SPACE_AFTER] = result.ignored = true; | ||
} | ||
@@ -39,6 +37,6 @@ } | ||
if (isInRange(index, index + (value || '').length, mark)) { | ||
result[report_1.ValidationTarget.VALUE] = result.ignored = true; | ||
result[ValidationTarget.VALUE] = result.ignored = true; | ||
} | ||
if (isInRange(index + (value || '').length, index + (value || '').length + (spaceAfter || '').length, mark)) { | ||
result[report_1.ValidationTarget.SPACE_AFTER] = result.ignored = true; | ||
result[ValidationTarget.SPACE_AFTER] = result.ignored = true; | ||
} | ||
@@ -76,15 +74,15 @@ } | ||
} | ||
if (ignoredFlags[report_1.ValidationTarget.START_VALUE]) { | ||
if (ignoredFlags[ValidationTarget.START_VALUE]) { | ||
tokens.ignoredStartValue = tokens.modifiedStartValue; | ||
tokens.modifiedStartValue = tokens.startValue; | ||
} | ||
if (ignoredFlags[report_1.ValidationTarget.INNER_SPACE_BEFORE]) { | ||
if (ignoredFlags[ValidationTarget.INNER_SPACE_BEFORE]) { | ||
tokens.ignoredInnerSpaceBefore = tokens.modifiedInnerSpaceBefore; | ||
tokens.modifiedInnerSpaceBefore = tokens.innerSpaceBefore; | ||
} | ||
if (ignoredFlags[report_1.ValidationTarget.END_VALUE]) { | ||
if (ignoredFlags[ValidationTarget.END_VALUE]) { | ||
tokens.ignoredEndValue = tokens.modifiedEndValue; | ||
tokens.modifiedEndValue = tokens.endValue; | ||
} | ||
if (ignoredFlags[report_1.ValidationTarget.SPACE_AFTER]) { | ||
if (ignoredFlags[ValidationTarget.SPACE_AFTER]) { | ||
tokens.ignoredSpaceAfter = tokens.modifiedSpaceAfter; | ||
@@ -103,7 +101,7 @@ tokens.modifiedSpaceAfter = tokens.spaceAfter; | ||
if (!Array.isArray(token)) { | ||
if (subIgnoredFlags[report_1.ValidationTarget.VALUE]) { | ||
if (subIgnoredFlags[ValidationTarget.VALUE]) { | ||
token.ignoredValue = token.modifiedValue; | ||
token.modifiedValue = token.value; | ||
} | ||
if (subIgnoredFlags[report_1.ValidationTarget.SPACE_AFTER]) { | ||
if (subIgnoredFlags[ValidationTarget.SPACE_AFTER]) { | ||
token.ignoredSpaceAfter = token.modifiedSpaceAfter; | ||
@@ -124,2 +122,2 @@ token.modifiedSpaceAfter = token.spaceAfter; | ||
}; | ||
exports.default = join; | ||
export default join; |
@@ -1,41 +0,12 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.normalizeConfig = exports.normalizeOptions = void 0; | ||
const ignore_1 = __importStar(require("./hypers/ignore")); | ||
const hexo_1 = __importDefault(require("./hypers/hexo")); | ||
const vuepress_1 = __importDefault(require("./hypers/vuepress")); | ||
const md_1 = __importDefault(require("./hypers/md")); | ||
const rules_1 = require("./rules"); | ||
const report_1 = require("./report"); | ||
import ignore, { parseIngoredCase } from './hypers/ignore'; | ||
import hexo from './hypers/hexo'; | ||
import vuepress from './hypers/vuepress'; | ||
import md from './hypers/md'; | ||
import { defaultConfig as defaultRules } from './rules'; | ||
import { env } from './report'; | ||
const hyperParseInfo = [ | ||
{ name: 'ignore', value: ignore_1.default }, | ||
{ name: 'hexo', value: hexo_1.default }, | ||
{ name: 'vuepress', value: vuepress_1.default }, | ||
{ name: 'markdown', value: md_1.default } | ||
{ name: 'ignore', value: ignore }, | ||
{ name: 'hexo', value: hexo }, | ||
{ name: 'vuepress', value: vuepress }, | ||
{ name: 'markdown', value: md } | ||
]; | ||
@@ -91,7 +62,7 @@ const arrToMap = (arr) => arr.reduce((current, { name, value }) => { | ||
}; | ||
const normalizeOptions = (options) => { | ||
export const normalizeOptions = (options) => { | ||
var _a, _b; | ||
const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : report_1.env.defaultLogger; | ||
const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : env.defaultLogger; | ||
const rules = (_b = options.rules) !== null && _b !== void 0 ? _b : {}; | ||
const preset = rules.preset === 'default' ? rules_1.defaultConfig : {}; | ||
const preset = rules.preset === 'default' ? defaultRules : {}; | ||
deprecateOptions(rules, logger); | ||
@@ -113,4 +84,3 @@ let hyperParse; | ||
}; | ||
exports.normalizeOptions = normalizeOptions; | ||
const normalizeConfig = (config, logger = report_1.env.defaultLogger) => { | ||
export const normalizeConfig = (config, logger = env.defaultLogger) => { | ||
const options = { | ||
@@ -125,3 +95,3 @@ logger, | ||
if (config.preset === 'default') { | ||
options.rules = Object.assign({}, rules_1.defaultConfig); | ||
options.rules = Object.assign({}, defaultRules); | ||
hyperParse = hyperParseInfo.map((item) => item.name); | ||
@@ -147,3 +117,3 @@ } | ||
config.caseIgnores.forEach((x) => { | ||
const ignoredCase = (0, ignore_1.parseIngoredCase)(x); | ||
const ignoredCase = parseIngoredCase(x); | ||
if (ignoredCase) { | ||
@@ -159,2 +129,1 @@ options.ignoredCases.push(ignoredCase); | ||
}; | ||
exports.normalizeConfig = normalizeConfig; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkCharType = void 0; | ||
const types_1 = require("./types"); | ||
import { CharType } from './types'; | ||
/** | ||
@@ -19,4 +16,4 @@ * NOTE: | ||
const newCharTypeSet = { | ||
[types_1.CharType.HALFWIDTH_PAUSE_OR_STOP]: ',.;:?!', | ||
[types_1.CharType.FULLWIDTH_PAUSE_OR_STOP]: [ | ||
[CharType.HALFWIDTH_PAUSE_OR_STOP]: ',.;:?!', | ||
[CharType.FULLWIDTH_PAUSE_OR_STOP]: [ | ||
// normal punctuation marks | ||
@@ -27,7 +24,7 @@ ',。、;:?!', | ||
].join(''), | ||
[types_1.CharType.HALFWIDTH_QUOTATION]: '\'"', | ||
[types_1.CharType.FULLWIDTH_QUOTATION]: '‘’“”《》〈〉『』「」【】〖〗', | ||
[types_1.CharType.HALFWIDTH_BRACKET]: '()[]{}', | ||
[types_1.CharType.FULLWIDTH_BRACKET]: '()〔〕[]{}', | ||
[types_1.CharType.HALFWIDTH_OTHER_PUNCTUATION]: [ | ||
[CharType.HALFWIDTH_QUOTATION]: '\'"', | ||
[CharType.FULLWIDTH_QUOTATION]: '‘’“”《》〈〉『』「」【】〖〗', | ||
[CharType.HALFWIDTH_BRACKET]: '()[]{}', | ||
[CharType.FULLWIDTH_BRACKET]: '()〔〕[]{}', | ||
[CharType.HALFWIDTH_OTHER_PUNCTUATION]: [ | ||
// on-keyboard symbols | ||
@@ -38,3 +35,3 @@ '~-+*/\\%=&|"`<>@#$^', | ||
].join(''), | ||
[types_1.CharType.FULLWIDTH_OTHER_PUNCTUATION]: [ | ||
[CharType.FULLWIDTH_OTHER_PUNCTUATION]: [ | ||
// U+2E3A TWO-EM DASH, U+2014 EM DASH | ||
@@ -61,9 +58,9 @@ '—⸺', | ||
*/ | ||
const checkCharType = (char) => { | ||
export const checkCharType = (char) => { | ||
if (char === '') { | ||
return types_1.CharType.EMPTY; | ||
return CharType.EMPTY; | ||
} | ||
// space | ||
if (char.match(/\s/) != null) { | ||
return types_1.CharType.SPACE; | ||
return CharType.SPACE; | ||
} | ||
@@ -78,74 +75,73 @@ // punctuation marks | ||
if (char.match(/[0-9]/) != null) { | ||
return types_1.CharType.WESTERN_LETTER; | ||
return CharType.WESTERN_LETTER; | ||
} | ||
// Basic Latin | ||
if (char.match(/[\u0020-\u007F]/) != null) { | ||
return types_1.CharType.WESTERN_LETTER; | ||
return CharType.WESTERN_LETTER; | ||
} | ||
// Latin-1 Supplement | ||
if (char.match(/[\u00A0-\u00FF]/) != null) { | ||
return types_1.CharType.WESTERN_LETTER; | ||
return CharType.WESTERN_LETTER; | ||
} | ||
// Latin Extended-A | ||
if (char.match(/[\u0100-\u017F]/) != null) { | ||
return types_1.CharType.WESTERN_LETTER; | ||
return CharType.WESTERN_LETTER; | ||
} | ||
// Latin Extended-B | ||
if (char.match(/[\u0180-\u024F]/) != null) { | ||
return types_1.CharType.WESTERN_LETTER; | ||
return CharType.WESTERN_LETTER; | ||
} | ||
// Greek and Coptic | ||
if (char.match(/[\u0370-\u03FF]/) != null) { | ||
return types_1.CharType.WESTERN_LETTER; | ||
return CharType.WESTERN_LETTER; | ||
} | ||
// CJK Unified Ideographs | ||
if (char.match(/[\u4E00-\u9FFF]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Unified Ideographs Extension A | ||
if (char.match(/[\u3400-\u4DBF]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Unified Ideographs Extension B | ||
if (char.match(/[\ud840-\ud868][\udc00-\udfff]|\ud869[\udc00-\uded6]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Unified Ideographs Extension C | ||
if (char.match(/\ud869[\udf00-\udfff]|[\ud86a-\ud86c][\udc00-\udfff]|\ud86d[\udc00-\udf34]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Unified Ideographs Extension D | ||
if (char.match(/\ud86d[\udf40-\udfff]|\ud86e[\udc00-\udc1d]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Compatibility Ideographs | ||
if (char.match(/[\uF900-\uFAFF]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Compatibility Forms | ||
if (char.match(/[\uFE30-\uFE4F]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Radicals Supplement | ||
if (char.match(/[\u2E80-\u2EFF]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// Private Use Area (part) | ||
if (char.match(/[\uE815-\uE864]/) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Unified Ideographs Extension B | ||
if (char.match(/[\u{20000}-\u{2A6DF}]/u) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Compatibility Ideographs Supplement | ||
if (char.match(/[\u{2F800}-\u{2FA1F}]/u) != null) { | ||
return types_1.CharType.CJK_CHAR; | ||
return CharType.CJK_CHAR; | ||
} | ||
// CJK Symbols and Punctuation | ||
if (char.match(/[\u3000-\u303F]/) != null) { | ||
return types_1.CharType.FULLWIDTH_OTHER_PUNCTUATION; | ||
return CharType.FULLWIDTH_OTHER_PUNCTUATION; | ||
} | ||
return types_1.CharType.UNKNOWN; | ||
return CharType.UNKNOWN; | ||
}; | ||
exports.checkCharType = checkCharType; |
@@ -1,25 +0,4 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.travel = exports.toMutableResult = exports.parse = exports.checkCharType = void 0; | ||
__exportStar(require("./types"), exports); | ||
var char_1 = require("./char"); | ||
Object.defineProperty(exports, "checkCharType", { enumerable: true, get: function () { return char_1.checkCharType; } }); | ||
var parse_1 = require("./parse"); | ||
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } }); | ||
Object.defineProperty(exports, "toMutableResult", { enumerable: true, get: function () { return parse_1.toMutableResult; } }); | ||
var travel_1 = require("./travel"); | ||
Object.defineProperty(exports, "travel", { enumerable: true, get: function () { return travel_1.travel; } }); | ||
export * from './types'; | ||
export { checkCharType } from './char'; | ||
export { parse, toMutableResult } from './parse'; | ||
export { travel } from './travel'; |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.QUOTATION_NOT_OPEN = exports.QUOTATION_NOT_CLOSED = exports.BRACKET_NOT_OPEN = exports.BRACKET_NOT_CLOSED = void 0; | ||
exports.BRACKET_NOT_CLOSED = '括号未闭合'; | ||
exports.BRACKET_NOT_OPEN = '括号未匹配'; | ||
exports.QUOTATION_NOT_CLOSED = '引号未闭合'; | ||
exports.QUOTATION_NOT_OPEN = '引号未匹配'; | ||
export const BRACKET_NOT_CLOSED = '括号未闭合'; | ||
export const BRACKET_NOT_OPEN = '括号未匹配'; | ||
export const QUOTATION_NOT_CLOSED = '引号未闭合'; | ||
export const QUOTATION_NOT_OPEN = '引号未匹配'; |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toMutableResult = exports.parse = void 0; | ||
const char_1 = require("./char"); | ||
const types_1 = require("./types"); | ||
const util_1 = require("./util"); | ||
import { checkCharType } from './char'; | ||
import { CharType, isLetterType, isPunctuationType, MarkSideType, MarkType } from './types'; | ||
import { handleLetter, handlePunctuation, appendValue, addRawContent, addHyperToken, finalizeLastToken, getConnectingSpaceLength, getHyperMarkMap, getPreviousToken, initNewStatus, isShorthand, handleErrors } from './util'; | ||
/** | ||
@@ -22,10 +19,10 @@ * Parse a string into several tokens. | ||
*/ | ||
const parse = (str, hyperMarks = []) => { | ||
export const parse = (str, hyperMarks = []) => { | ||
// init status and hyper marks | ||
const status = (0, util_1.initNewStatus)(str, hyperMarks); | ||
const hyperMarkMap = (0, util_1.getHyperMarkMap)(hyperMarks); | ||
const status = initNewStatus(str, hyperMarks); | ||
const hyperMarkMap = getHyperMarkMap(hyperMarks); | ||
// travel every character in the string | ||
for (let i = 0; i < str.length; i++) { | ||
const char = str[i]; | ||
const type = (0, char_1.checkCharType)(char); | ||
const type = checkCharType(char); | ||
const hyperMark = hyperMarkMap[i]; | ||
@@ -39,3 +36,3 @@ // finally get `status.marks` and `status.lastGroup` as the top-level tokens | ||
// end the last unfinished token | ||
(0, util_1.finalizeLastToken)(status, i); | ||
finalizeLastToken(status, i); | ||
// for hyper mark without startValue | ||
@@ -49,4 +46,4 @@ delete hyperMarkMap[i]; | ||
// - end hyper mark: append token, append mark | ||
if (hyperMark.type === types_1.MarkType.RAW) { | ||
(0, util_1.addRawContent)(status, i, str.substring(hyperMark.startIndex, hyperMark.endIndex)); | ||
if (hyperMark.type === MarkType.RAW) { | ||
addRawContent(status, i, str.substring(hyperMark.startIndex, hyperMark.endIndex)); | ||
i = hyperMark.endIndex - 1; | ||
@@ -56,7 +53,7 @@ } | ||
if (i === hyperMark.startIndex) { | ||
(0, util_1.addHyperToken)(status, i, hyperMark, hyperMark.startValue, types_1.MarkSideType.LEFT); | ||
addHyperToken(status, i, hyperMark, hyperMark.startValue, MarkSideType.LEFT); | ||
i += hyperMark.startValue.length - 1; | ||
} | ||
else if (i === hyperMark.endIndex) { | ||
(0, util_1.addHyperToken)(status, i, hyperMark, hyperMark.endValue, types_1.MarkSideType.RIGHT); | ||
addHyperToken(status, i, hyperMark, hyperMark.endValue, MarkSideType.RIGHT); | ||
i += hyperMark.endValue.length - 1; | ||
@@ -66,3 +63,3 @@ } | ||
} | ||
else if (type === types_1.CharType.SPACE) { | ||
else if (type === CharType.SPACE) { | ||
// end the last unfinished token | ||
@@ -73,8 +70,8 @@ // jump to the next non-space char | ||
// - inner space before a group | ||
(0, util_1.finalizeLastToken)(status, i); | ||
finalizeLastToken(status, i); | ||
if (status.lastGroup) { | ||
const spaceLength = (0, util_1.getConnectingSpaceLength)(str, i); | ||
const spaceLength = getConnectingSpaceLength(str, i); | ||
const spaces = str.substring(i, i + spaceLength); | ||
if (status.lastGroup.length) { | ||
const lastToken = (0, util_1.getPreviousToken)(status); | ||
const lastToken = getPreviousToken(status); | ||
if (lastToken) { | ||
@@ -92,21 +89,21 @@ lastToken.spaceAfter = spaces; | ||
} | ||
else if ((0, util_1.isShorthand)(str, status, i, char)) { | ||
(0, util_1.appendValue)(status, char); | ||
else if (isShorthand(str, status, i, char)) { | ||
appendValue(status, char); | ||
} | ||
else if ((0, types_1.isPunctuationType)(type)) { | ||
(0, util_1.handlePunctuation)(i, char, type, status); | ||
else if (isPunctuationType(type)) { | ||
handlePunctuation(i, char, type, status); | ||
} | ||
else if ((0, types_1.isLetterType)(type)) { | ||
(0, util_1.handleLetter)(i, char, type, status); | ||
else if (isLetterType(type)) { | ||
handleLetter(i, char, type, status); | ||
} | ||
else if (type === types_1.CharType.EMPTY) { | ||
else if (type === CharType.EMPTY) { | ||
// Nothing | ||
} | ||
else { | ||
(0, util_1.handleLetter)(i, char, types_1.CharType.WESTERN_LETTER, status); | ||
handleLetter(i, char, CharType.WESTERN_LETTER, status); | ||
} | ||
} | ||
(0, util_1.finalizeLastToken)(status, str.length); | ||
finalizeLastToken(status, str.length); | ||
// handle all the unmatched parsing tokens | ||
(0, util_1.handleErrors)(status); | ||
handleErrors(status); | ||
return { | ||
@@ -119,3 +116,2 @@ tokens: status.tokens, | ||
}; | ||
exports.parse = parse; | ||
const toMutableToken = (token) => { | ||
@@ -149,3 +145,3 @@ if (Array.isArray(token)) { | ||
}; | ||
const toMutableResult = (result, options = {}) => { | ||
export const toMutableResult = (result, options = {}) => { | ||
if (!options.noSinglePair) { | ||
@@ -158,2 +154,1 @@ result.errors.length = 0; | ||
}; | ||
exports.toMutableResult = toMutableResult; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.travel = void 0; | ||
const travel = (group, handler) => { | ||
export const travel = (group, handler) => { | ||
for (let i = 0; i < group.length; i++) { | ||
@@ -9,6 +6,5 @@ const token = group[i]; | ||
if (Array.isArray(token)) { | ||
(0, exports.travel)(token, handler); | ||
travel(token, handler); | ||
} | ||
} | ||
}; | ||
exports.travel = travel; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -12,6 +11,4 @@ * @fileOverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isVisibilityUnknownType = exports.isInvisibleType = exports.isVisibleType = exports.isNonCodeVisibleType = exports.isFullwidthType = exports.isFullwidthPunctuationType = exports.isHalfwidthType = exports.isHalfwidthPunctuationType = exports.isPunctuationType = exports.isSinglePunctuationType = exports.isOtherPunctuationType = exports.isBracketType = exports.isQuotationType = exports.isPauseOrStopType = exports.isLetterType = exports.getFullwidthTokenType = exports.getHalfwidthTokenType = exports.GroupTokenType = exports.HyperTokenType = exports.isRawMark = exports.MarkSideType = exports.MarkType = exports.isFullwidthPair = exports.SHORTHAND_PAIR_SET = exports.SHORTHAND_CHARS = exports.QUOTATION_CHAR_SET = exports.BRACKET_CHAR_SET = exports.CharType = void 0; | ||
// Char | ||
var CharType; | ||
export var CharType; | ||
(function (CharType) { | ||
@@ -46,8 +43,8 @@ CharType["EMPTY"] = "empty"; | ||
CharType["UNKNOWN"] = "unknown"; | ||
})(CharType || (exports.CharType = CharType = {})); | ||
exports.BRACKET_CHAR_SET = { | ||
})(CharType || (CharType = {})); | ||
export const BRACKET_CHAR_SET = { | ||
left: '([{(〔[{', | ||
right: ')]})〕]}' | ||
}; | ||
exports.QUOTATION_CHAR_SET = { | ||
export const QUOTATION_CHAR_SET = { | ||
left: `“‘《〈『「【〖`, | ||
@@ -57,4 +54,4 @@ right: `”’》〉』」】〗`, | ||
}; | ||
exports.SHORTHAND_CHARS = `'’`; | ||
exports.SHORTHAND_PAIR_SET = { | ||
export const SHORTHAND_CHARS = `'’`; | ||
export const SHORTHAND_PAIR_SET = { | ||
[`'`]: `'`, | ||
@@ -64,4 +61,3 @@ [`’`]: `‘` | ||
const FULLWIDTH_PAIRS = `“”‘’()〔〕[]{}《》〈〉「」『』【】〖〗`; | ||
const isFullwidthPair = (str) => FULLWIDTH_PAIRS.indexOf(str) >= 0; | ||
exports.isFullwidthPair = isFullwidthPair; | ||
export const isFullwidthPair = (str) => FULLWIDTH_PAIRS.indexOf(str) >= 0; | ||
// Mark | ||
@@ -72,3 +68,3 @@ /** | ||
*/ | ||
var MarkType; | ||
export var MarkType; | ||
(function (MarkType) { | ||
@@ -90,16 +86,15 @@ /** | ||
MarkType["RAW"] = "raw"; | ||
})(MarkType || (exports.MarkType = MarkType = {})); | ||
var MarkSideType; | ||
})(MarkType || (MarkType = {})); | ||
export var MarkSideType; | ||
(function (MarkSideType) { | ||
MarkSideType["LEFT"] = "left"; | ||
MarkSideType["RIGHT"] = "right"; | ||
})(MarkSideType || (exports.MarkSideType = MarkSideType = {})); | ||
const isRawMark = (mark) => { | ||
})(MarkSideType || (MarkSideType = {})); | ||
export const isRawMark = (mark) => { | ||
return mark.code !== undefined; | ||
}; | ||
exports.isRawMark = isRawMark; | ||
/** | ||
* TODO: paired html tags should be hyper mark | ||
*/ | ||
var HyperTokenType; | ||
export var HyperTokenType; | ||
(function (HyperTokenType) { | ||
@@ -132,8 +127,8 @@ /** | ||
HyperTokenType["INDETERMINATED"] = "indeterminated"; | ||
})(HyperTokenType || (exports.HyperTokenType = HyperTokenType = {})); | ||
var GroupTokenType; | ||
})(HyperTokenType || (HyperTokenType = {})); | ||
export var GroupTokenType; | ||
(function (GroupTokenType) { | ||
GroupTokenType["GROUP"] = "group"; | ||
})(GroupTokenType || (exports.GroupTokenType = GroupTokenType = {})); | ||
const getHalfwidthTokenType = (type) => { | ||
})(GroupTokenType || (GroupTokenType = {})); | ||
export const getHalfwidthTokenType = (type) => { | ||
switch (type) { | ||
@@ -149,4 +144,3 @@ case CharType.CJK_CHAR: | ||
}; | ||
exports.getHalfwidthTokenType = getHalfwidthTokenType; | ||
const getFullwidthTokenType = (type) => { | ||
export const getFullwidthTokenType = (type) => { | ||
switch (type) { | ||
@@ -162,38 +156,30 @@ case CharType.WESTERN_LETTER: | ||
}; | ||
exports.getFullwidthTokenType = getFullwidthTokenType; | ||
const isLetterType = (type) => { | ||
export const isLetterType = (type) => { | ||
return type === CharType.WESTERN_LETTER || type === CharType.CJK_CHAR; | ||
}; | ||
exports.isLetterType = isLetterType; | ||
const isPauseOrStopType = (type) => { | ||
export const isPauseOrStopType = (type) => { | ||
return (type === CharType.HALFWIDTH_PAUSE_OR_STOP || | ||
type === CharType.FULLWIDTH_PAUSE_OR_STOP); | ||
}; | ||
exports.isPauseOrStopType = isPauseOrStopType; | ||
const isQuotationType = (type) => { | ||
export const isQuotationType = (type) => { | ||
return (type === CharType.HALFWIDTH_QUOTATION || | ||
type === CharType.FULLWIDTH_QUOTATION); | ||
}; | ||
exports.isQuotationType = isQuotationType; | ||
const isBracketType = (type) => { | ||
export const isBracketType = (type) => { | ||
return (type === CharType.HALFWIDTH_BRACKET || type === CharType.FULLWIDTH_BRACKET); | ||
}; | ||
exports.isBracketType = isBracketType; | ||
const isOtherPunctuationType = (type) => { | ||
export const isOtherPunctuationType = (type) => { | ||
return (type === CharType.HALFWIDTH_OTHER_PUNCTUATION || | ||
type === CharType.FULLWIDTH_OTHER_PUNCTUATION); | ||
}; | ||
exports.isOtherPunctuationType = isOtherPunctuationType; | ||
const isSinglePunctuationType = (type) => { | ||
return (0, exports.isPauseOrStopType)(type) || (0, exports.isOtherPunctuationType)(type); | ||
export const isSinglePunctuationType = (type) => { | ||
return isPauseOrStopType(type) || isOtherPunctuationType(type); | ||
}; | ||
exports.isSinglePunctuationType = isSinglePunctuationType; | ||
const isPunctuationType = (type) => { | ||
return ((0, exports.isPauseOrStopType)(type) || | ||
(0, exports.isQuotationType)(type) || | ||
(0, exports.isBracketType)(type) || | ||
(0, exports.isOtherPunctuationType)(type)); | ||
export const isPunctuationType = (type) => { | ||
return (isPauseOrStopType(type) || | ||
isQuotationType(type) || | ||
isBracketType(type) || | ||
isOtherPunctuationType(type)); | ||
}; | ||
exports.isPunctuationType = isPunctuationType; | ||
const isHalfwidthPunctuationType = (type) => { | ||
export const isHalfwidthPunctuationType = (type) => { | ||
return (type === CharType.HALFWIDTH_PAUSE_OR_STOP || | ||
@@ -204,8 +190,6 @@ type === CharType.HALFWIDTH_QUOTATION || | ||
}; | ||
exports.isHalfwidthPunctuationType = isHalfwidthPunctuationType; | ||
const isHalfwidthType = (type) => { | ||
return type === CharType.WESTERN_LETTER || (0, exports.isHalfwidthPunctuationType)(type); | ||
export const isHalfwidthType = (type) => { | ||
return type === CharType.WESTERN_LETTER || isHalfwidthPunctuationType(type); | ||
}; | ||
exports.isHalfwidthType = isHalfwidthType; | ||
const isFullwidthPunctuationType = (type) => { | ||
export const isFullwidthPunctuationType = (type) => { | ||
return (type === CharType.FULLWIDTH_PAUSE_OR_STOP || | ||
@@ -216,26 +200,20 @@ type === CharType.FULLWIDTH_QUOTATION || | ||
}; | ||
exports.isFullwidthPunctuationType = isFullwidthPunctuationType; | ||
const isFullwidthType = (type) => { | ||
return type === CharType.CJK_CHAR || (0, exports.isFullwidthPunctuationType)(type); | ||
export const isFullwidthType = (type) => { | ||
return type === CharType.CJK_CHAR || isFullwidthPunctuationType(type); | ||
}; | ||
exports.isFullwidthType = isFullwidthType; | ||
const isNonCodeVisibleType = (type) => { | ||
return ((0, exports.isLetterType)(type) || | ||
(0, exports.isSinglePunctuationType)(type) || | ||
export const isNonCodeVisibleType = (type) => { | ||
return (isLetterType(type) || | ||
isSinglePunctuationType(type) || | ||
type === HyperTokenType.BRACKET_MARK || | ||
type === GroupTokenType.GROUP); | ||
}; | ||
exports.isNonCodeVisibleType = isNonCodeVisibleType; | ||
const isVisibleType = (type) => { | ||
return (0, exports.isNonCodeVisibleType)(type) || type === HyperTokenType.CODE_CONTENT; | ||
export const isVisibleType = (type) => { | ||
return isNonCodeVisibleType(type) || type === HyperTokenType.CODE_CONTENT; | ||
}; | ||
exports.isVisibleType = isVisibleType; | ||
const isInvisibleType = (type) => { | ||
export const isInvisibleType = (type) => { | ||
// OTHERS? | ||
return type === HyperTokenType.HYPER_MARK; | ||
}; | ||
exports.isInvisibleType = isInvisibleType; | ||
const isVisibilityUnknownType = (type) => { | ||
export const isVisibilityUnknownType = (type) => { | ||
return type === HyperTokenType.HYPER_CONTENT; | ||
}; | ||
exports.isVisibilityUnknownType = isVisibilityUnknownType; |
@@ -1,11 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleErrors = exports.getHyperContentType = exports.isShorthand = exports.getHyperMarkMap = exports.getPreviousToken = exports.getConnectingSpaceLength = exports.appendValue = exports.initNewContent = exports.finalizeCurrentGroup = exports.initNewGroup = exports.finalizeCurrentMark = exports.addBracketToken = exports.initNewMark = exports.addRawContent = exports.addHyperToken = exports.finalizeCurrentToken = exports.finalizeLastToken = exports.initNewStatus = exports.handleLetter = exports.handlePunctuation = void 0; | ||
const report_1 = require("../report"); | ||
const char_1 = require("./char"); | ||
const messages_1 = require("./messages"); | ||
const types_1 = require("./types"); | ||
const handlePunctuation = (i, char, type, status) => { | ||
import { ValidationTarget } from '../report'; | ||
import { checkCharType } from './char'; | ||
import { BRACKET_NOT_CLOSED, BRACKET_NOT_OPEN, QUOTATION_NOT_CLOSED, QUOTATION_NOT_OPEN } from './messages'; | ||
import { CharType, SHORTHAND_CHARS, SHORTHAND_PAIR_SET, BRACKET_CHAR_SET, QUOTATION_CHAR_SET, MarkSideType, MarkType, HyperTokenType, GroupTokenType, isBracketType, isQuotationType } from './types'; | ||
export const handlePunctuation = (i, char, type, status) => { | ||
// end the last unfinished token | ||
(0, exports.finalizeLastToken)(status, i); | ||
finalizeLastToken(status, i); | ||
// check the current token type | ||
@@ -18,21 +15,21 @@ // - start of a mark: start an unfinished mark | ||
// - other punctuation: add and end the current token | ||
if ((0, types_1.isBracketType)(type)) { | ||
if (types_1.BRACKET_CHAR_SET.left.indexOf(char) >= 0) { | ||
if (isBracketType(type)) { | ||
if (BRACKET_CHAR_SET.left.indexOf(char) >= 0) { | ||
// push (save) the current unfinished mark if have | ||
(0, exports.initNewMark)(status, i, char); | ||
initNewMark(status, i, char); | ||
// generate a new token and mark it as a mark punctuation by left | ||
// and finish the token | ||
(0, exports.addBracketToken)(status, i, char, types_1.MarkSideType.LEFT); | ||
addBracketToken(status, i, char, MarkSideType.LEFT); | ||
} | ||
else if (types_1.BRACKET_CHAR_SET.right.indexOf(char) >= 0) { | ||
else if (BRACKET_CHAR_SET.right.indexOf(char) >= 0) { | ||
if (!status.lastMark || !status.lastMark.startValue) { | ||
addUnmatchedToken(status, i, char); | ||
addError(status, i, messages_1.BRACKET_NOT_OPEN); | ||
addError(status, i, BRACKET_NOT_OPEN); | ||
} | ||
else { | ||
// generate token as a punctuation | ||
(0, exports.addBracketToken)(status, i, char, types_1.MarkSideType.RIGHT); | ||
addBracketToken(status, i, char, MarkSideType.RIGHT); | ||
// end the last unfinished mark | ||
// and pop the previous one if exists | ||
(0, exports.finalizeCurrentMark)(status, i, char); | ||
finalizeCurrentMark(status, i, char); | ||
} | ||
@@ -42,23 +39,23 @@ } | ||
} | ||
if ((0, types_1.isQuotationType)(type)) { | ||
if (types_1.QUOTATION_CHAR_SET.neutral.indexOf(char) >= 0) { | ||
if (isQuotationType(type)) { | ||
if (QUOTATION_CHAR_SET.neutral.indexOf(char) >= 0) { | ||
// - end the last unfinished group | ||
// - start a new group | ||
if (status.lastGroup && char === status.lastGroup.startValue) { | ||
(0, exports.finalizeCurrentGroup)(status, i, char); | ||
finalizeCurrentGroup(status, i, char); | ||
} | ||
else { | ||
(0, exports.initNewGroup)(status, i, char); | ||
initNewGroup(status, i, char); | ||
} | ||
} | ||
else if (types_1.QUOTATION_CHAR_SET.left.indexOf(char) >= 0) { | ||
(0, exports.initNewGroup)(status, i, char); | ||
else if (QUOTATION_CHAR_SET.left.indexOf(char) >= 0) { | ||
initNewGroup(status, i, char); | ||
} | ||
else if (types_1.QUOTATION_CHAR_SET.right.indexOf(char) >= 0) { | ||
else if (QUOTATION_CHAR_SET.right.indexOf(char) >= 0) { | ||
if (!status.lastGroup || !status.lastGroup.startValue) { | ||
addUnmatchedToken(status, i, char); | ||
addError(status, i, messages_1.QUOTATION_NOT_OPEN); | ||
addError(status, i, QUOTATION_NOT_OPEN); | ||
} | ||
else { | ||
(0, exports.finalizeCurrentGroup)(status, i, char); | ||
finalizeCurrentGroup(status, i, char); | ||
} | ||
@@ -70,4 +67,3 @@ } | ||
}; | ||
exports.handlePunctuation = handlePunctuation; | ||
const handleLetter = (i, char, type, status) => { | ||
export const handleLetter = (i, char, type, status) => { | ||
// check if type changed and last token unfinished | ||
@@ -78,19 +74,18 @@ // - create new token in the current group | ||
if (status.lastToken.type !== type) { | ||
(0, exports.finalizeLastToken)(status, i); | ||
(0, exports.initNewContent)(status, i, char, type); | ||
finalizeLastToken(status, i); | ||
initNewContent(status, i, char, type); | ||
} | ||
else { | ||
(0, exports.appendValue)(status, char); | ||
appendValue(status, char); | ||
} | ||
} | ||
else { | ||
(0, exports.initNewContent)(status, i, char, type); | ||
initNewContent(status, i, char, type); | ||
} | ||
}; | ||
exports.handleLetter = handleLetter; | ||
// status | ||
const initNewStatus = (str, hyperMarks) => { | ||
export const initNewStatus = (str, hyperMarks) => { | ||
const tokens = []; | ||
Object.assign(tokens, { | ||
type: types_1.GroupTokenType.GROUP, | ||
type: GroupTokenType.GROUP, | ||
index: 0, | ||
@@ -117,5 +112,4 @@ spaceAfter: '', | ||
}; | ||
exports.initNewStatus = initNewStatus; | ||
// finalize token | ||
const finalizeLastToken = (status, index) => { | ||
export const finalizeLastToken = (status, index) => { | ||
if (status.lastToken) { | ||
@@ -128,21 +122,19 @@ // the lastToken.index is not the current index anymore | ||
}; | ||
exports.finalizeLastToken = finalizeLastToken; | ||
const finalizeCurrentToken = (status, token) => { | ||
export const finalizeCurrentToken = (status, token) => { | ||
status.lastGroup && status.lastGroup.push(token); | ||
status.lastToken = undefined; | ||
}; | ||
exports.finalizeCurrentToken = finalizeCurrentToken; | ||
// hyper marks | ||
const markTypeToTokenType = (type) => { | ||
switch (type) { | ||
case types_1.MarkType.HYPER: | ||
return types_1.HyperTokenType.HYPER_MARK; | ||
case types_1.MarkType.BRACKETS: | ||
return types_1.HyperTokenType.BRACKET_MARK; | ||
case types_1.MarkType.RAW: | ||
case MarkType.HYPER: | ||
return HyperTokenType.HYPER_MARK; | ||
case MarkType.BRACKETS: | ||
return HyperTokenType.BRACKET_MARK; | ||
case MarkType.RAW: | ||
// technically never since MarkType.RAW should go to addRawContent() | ||
return types_1.HyperTokenType.INDETERMINATED; | ||
return HyperTokenType.INDETERMINATED; | ||
} | ||
}; | ||
const addHyperToken = (status, index, mark, value, markSide) => { | ||
export const addHyperToken = (status, index, mark, value, markSide) => { | ||
const token = { | ||
@@ -157,8 +149,7 @@ type: markTypeToTokenType(mark.type), | ||
}; | ||
(0, exports.finalizeCurrentToken)(status, token); | ||
finalizeCurrentToken(status, token); | ||
}; | ||
exports.addHyperToken = addHyperToken; | ||
const addRawContent = (status, index, value) => { | ||
export const addRawContent = (status, index, value) => { | ||
const token = { | ||
type: (0, exports.getHyperContentType)(value), | ||
type: getHyperContentType(value), | ||
index, | ||
@@ -169,7 +160,6 @@ length: value.length, | ||
}; | ||
(0, exports.finalizeCurrentToken)(status, token); | ||
finalizeCurrentToken(status, token); | ||
}; | ||
exports.addRawContent = addRawContent; | ||
// bracket marks | ||
const initNewMark = (status, index, char, type = types_1.MarkType.BRACKETS) => { | ||
export const initNewMark = (status, index, char, type = MarkType.BRACKETS) => { | ||
if (status.lastMark) { | ||
@@ -189,6 +179,5 @@ status.markStack.push(status.lastMark); | ||
}; | ||
exports.initNewMark = initNewMark; | ||
const addBracketToken = (status, index, char, markSide) => { | ||
export const addBracketToken = (status, index, char, markSide) => { | ||
const token = { | ||
type: types_1.HyperTokenType.BRACKET_MARK, | ||
type: HyperTokenType.BRACKET_MARK, | ||
index, | ||
@@ -201,6 +190,5 @@ length: 1, | ||
}; | ||
(0, exports.finalizeCurrentToken)(status, token); | ||
finalizeCurrentToken(status, token); | ||
}; | ||
exports.addBracketToken = addBracketToken; | ||
const finalizeCurrentMark = (status, index, char) => { | ||
export const finalizeCurrentMark = (status, index, char) => { | ||
if (!status.lastMark) { | ||
@@ -218,3 +206,2 @@ return; | ||
}; | ||
exports.finalizeCurrentMark = finalizeCurrentMark; | ||
// normal punctuation | ||
@@ -229,7 +216,7 @@ const addSinglePunctuationToken = (status, index, char, type) => { | ||
}; | ||
(0, exports.finalizeCurrentToken)(status, token); | ||
finalizeCurrentToken(status, token); | ||
}; | ||
const addUnmatchedToken = (status, i, char) => { | ||
const token = { | ||
type: types_1.HyperTokenType.UNMATCHED, | ||
type: HyperTokenType.UNMATCHED, | ||
index: i, | ||
@@ -240,10 +227,10 @@ length: 1, | ||
}; | ||
(0, exports.finalizeCurrentToken)(status, token); | ||
finalizeCurrentToken(status, token); | ||
}; | ||
// group | ||
const initNewGroup = (status, index, char) => { | ||
export const initNewGroup = (status, index, char) => { | ||
status.lastGroup && status.groupStack.push(status.lastGroup); | ||
const lastGroup = []; | ||
Object.assign(lastGroup, { | ||
type: types_1.GroupTokenType.GROUP, | ||
type: GroupTokenType.GROUP, | ||
index, | ||
@@ -262,4 +249,3 @@ spaceAfter: '', // to be finalized | ||
}; | ||
exports.initNewGroup = initNewGroup; | ||
const finalizeCurrentGroup = (status, index, char) => { | ||
export const finalizeCurrentGroup = (status, index, char) => { | ||
if (status.lastGroup) { | ||
@@ -277,5 +263,4 @@ // index, length, value | ||
}; | ||
exports.finalizeCurrentGroup = finalizeCurrentGroup; | ||
// general content | ||
const initNewContent = (status, index, char, type) => { | ||
export const initNewContent = (status, index, char, type) => { | ||
status.lastToken = { | ||
@@ -289,4 +274,3 @@ type, | ||
}; | ||
exports.initNewContent = initNewContent; | ||
const appendValue = (status, char) => { | ||
export const appendValue = (status, char) => { | ||
if (status.lastToken) { | ||
@@ -297,3 +281,2 @@ status.lastToken.value += char; | ||
}; | ||
exports.appendValue = appendValue; | ||
// others | ||
@@ -303,5 +286,5 @@ /** | ||
*/ | ||
const getConnectingSpaceLength = (str, start) => { | ||
export const getConnectingSpaceLength = (str, start) => { | ||
// not even a space | ||
if ((0, char_1.checkCharType)(str[start]) !== types_1.CharType.SPACE) { | ||
if (checkCharType(str[start]) !== CharType.SPACE) { | ||
return 0; | ||
@@ -312,4 +295,4 @@ } | ||
const char = str[i]; | ||
const type = (0, char_1.checkCharType)(char); | ||
if (type !== types_1.CharType.SPACE) { | ||
const type = checkCharType(char); | ||
if (type !== CharType.SPACE) { | ||
return i - start; | ||
@@ -321,4 +304,3 @@ } | ||
}; | ||
exports.getConnectingSpaceLength = getConnectingSpaceLength; | ||
const getPreviousToken = (status) => { | ||
export const getPreviousToken = (status) => { | ||
if (status.lastGroup) { | ||
@@ -328,8 +310,7 @@ return status.lastGroup[status.lastGroup.length - 1]; | ||
}; | ||
exports.getPreviousToken = getPreviousToken; | ||
const getHyperMarkMap = (hyperMarks) => { | ||
export const getHyperMarkMap = (hyperMarks) => { | ||
const hyperMarkMap = {}; | ||
hyperMarks.forEach((mark) => { | ||
hyperMarkMap[mark.startIndex] = mark; | ||
if (mark.type !== types_1.MarkType.RAW) { | ||
if (mark.type !== MarkType.RAW) { | ||
hyperMarkMap[mark.endIndex] = mark; | ||
@@ -340,8 +321,7 @@ } | ||
}; | ||
exports.getHyperMarkMap = getHyperMarkMap; | ||
const isShorthand = (str, status, index, char) => { | ||
if (types_1.SHORTHAND_CHARS.indexOf(char) < 0) { | ||
export const isShorthand = (str, status, index, char) => { | ||
if (SHORTHAND_CHARS.indexOf(char) < 0) { | ||
return false; | ||
} | ||
if (!status.lastToken || status.lastToken.type !== types_1.CharType.WESTERN_LETTER) { | ||
if (!status.lastToken || status.lastToken.type !== CharType.WESTERN_LETTER) { | ||
return false; | ||
@@ -353,8 +333,8 @@ } | ||
const nextChar = str[index + 1]; | ||
const nextType = (0, char_1.checkCharType)(nextChar); | ||
if (nextType === types_1.CharType.WESTERN_LETTER || nextType === types_1.CharType.SPACE) { | ||
const nextType = checkCharType(nextChar); | ||
if (nextType === CharType.WESTERN_LETTER || nextType === CharType.SPACE) { | ||
if (!status.lastGroup) { | ||
return true; | ||
} | ||
if (status.lastGroup.startValue !== types_1.SHORTHAND_PAIR_SET[char]) { | ||
if (status.lastGroup.startValue !== SHORTHAND_PAIR_SET[char]) { | ||
return true; | ||
@@ -365,20 +345,18 @@ } | ||
}; | ||
exports.isShorthand = isShorthand; | ||
const getHyperContentType = (content) => { | ||
export const getHyperContentType = (content) => { | ||
if (content.match(/\n/)) { | ||
// Usually it's hexo custom containers. | ||
return types_1.HyperTokenType.HYPER_CONTENT; | ||
return HyperTokenType.HYPER_CONTENT; | ||
} | ||
if (content.match(/^<code.*>.*<\/code.*>$/)) { | ||
// Usually it's <code>...</code>. | ||
return types_1.HyperTokenType.CODE_CONTENT; | ||
return HyperTokenType.CODE_CONTENT; | ||
} | ||
if (content.match(/^<.+>$/)) { | ||
// Usually it's other HTML tags. | ||
return types_1.HyperTokenType.HYPER_CONTENT; | ||
return HyperTokenType.HYPER_CONTENT; | ||
} | ||
// Usually it's `...`. | ||
return types_1.HyperTokenType.CODE_CONTENT; | ||
return HyperTokenType.CODE_CONTENT; | ||
}; | ||
exports.getHyperContentType = getHyperContentType; | ||
// error handling | ||
@@ -391,10 +369,10 @@ const addError = (status, index, message) => { | ||
message, | ||
target: report_1.ValidationTarget.VALUE | ||
target: ValidationTarget.VALUE | ||
}); | ||
}; | ||
const handleErrors = (status) => { | ||
export const handleErrors = (status) => { | ||
// record an error if the last mark not fully resolved | ||
const lastMark = status.lastMark; | ||
if (lastMark && lastMark.type === types_1.MarkType.BRACKETS && !lastMark.endValue) { | ||
addError(status, lastMark.startIndex, messages_1.BRACKET_NOT_CLOSED); | ||
if (lastMark && lastMark.type === MarkType.BRACKETS && !lastMark.endValue) { | ||
addError(status, lastMark.startIndex, BRACKET_NOT_CLOSED); | ||
} | ||
@@ -405,3 +383,3 @@ // record an error if `markStack` not fully resolved | ||
if (mark !== lastMark) { | ||
addError(status, mark.startIndex, messages_1.BRACKET_NOT_CLOSED); | ||
addError(status, mark.startIndex, BRACKET_NOT_CLOSED); | ||
} | ||
@@ -413,3 +391,3 @@ }); | ||
if (lastGroup && lastGroup.startValue && !lastGroup.endValue) { | ||
addError(status, lastGroup.startIndex, messages_1.QUOTATION_NOT_CLOSED); | ||
addError(status, lastGroup.startIndex, QUOTATION_NOT_CLOSED); | ||
} | ||
@@ -420,3 +398,3 @@ // record an error if `groupStack` not fully resolved | ||
if (group !== lastGroup && group.startValue && !group.endValue) { | ||
addError(status, group.startIndex, messages_1.QUOTATION_NOT_CLOSED); | ||
addError(status, group.startIndex, QUOTATION_NOT_CLOSED); | ||
} | ||
@@ -426,2 +404,1 @@ }); | ||
}; | ||
exports.handleErrors = handleErrors; |
@@ -1,23 +0,22 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readRc = void 0; | ||
const path_1 = require("path"); | ||
const fs_1 = require("fs"); | ||
const report_1 = require("../report"); | ||
import { resolve } from 'path'; | ||
import fs from 'fs'; | ||
import { env } from '../report'; | ||
// to walk around https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/82 | ||
const { existsSync, readFileSync } = fs || {}; | ||
const DEFAULT_CONFIG_PATH = '.zhlintrc'; | ||
const DEFAULT_FILE_IGNORE_PATH = '.zhlintignore'; | ||
const DEFAULT_CASE_IGNORE_PATH = '.zhlintcaseignore'; | ||
const resolvePath = (dir, config, fileIgnore, caseIgnore, logger = report_1.env.defaultLogger) => { | ||
const resolvePath = (dir, config, fileIgnore, caseIgnore, logger = env.defaultLogger) => { | ||
const result = { | ||
config: undefined, | ||
fileIgnore: undefined, | ||
caseIgnore: undefined, | ||
caseIgnore: undefined | ||
}; | ||
dir = (0, path_1.resolve)(dir !== null && dir !== void 0 ? dir : '.'); | ||
if (!(0, fs_1.existsSync)(dir)) { | ||
dir = resolve(dir !== null && dir !== void 0 ? dir : '.'); | ||
if (!existsSync(dir)) { | ||
logger.log(`"${dir}" does not exist.`); | ||
return result; | ||
} | ||
config = (0, path_1.resolve)(dir, config !== null && config !== void 0 ? config : DEFAULT_CONFIG_PATH); | ||
if ((0, fs_1.existsSync)(config)) { | ||
config = resolve(dir, config !== null && config !== void 0 ? config : DEFAULT_CONFIG_PATH); | ||
if (existsSync(config)) { | ||
result.config = config; | ||
@@ -28,4 +27,4 @@ } | ||
} | ||
fileIgnore = (0, path_1.resolve)(dir, fileIgnore !== null && fileIgnore !== void 0 ? fileIgnore : DEFAULT_FILE_IGNORE_PATH); | ||
if ((0, fs_1.existsSync)(fileIgnore)) { | ||
fileIgnore = resolve(dir, fileIgnore !== null && fileIgnore !== void 0 ? fileIgnore : DEFAULT_FILE_IGNORE_PATH); | ||
if (existsSync(fileIgnore)) { | ||
result.fileIgnore = fileIgnore; | ||
@@ -36,4 +35,4 @@ } | ||
} | ||
caseIgnore = (0, path_1.resolve)(dir, caseIgnore !== null && caseIgnore !== void 0 ? caseIgnore : DEFAULT_CASE_IGNORE_PATH); | ||
if ((0, fs_1.existsSync)(caseIgnore)) { | ||
caseIgnore = resolve(dir, caseIgnore !== null && caseIgnore !== void 0 ? caseIgnore : DEFAULT_CASE_IGNORE_PATH); | ||
if (existsSync(caseIgnore)) { | ||
result.caseIgnore = caseIgnore; | ||
@@ -48,6 +47,6 @@ } | ||
const readJSONSync = (filepath) => { | ||
const output = (0, fs_1.readFileSync)(filepath, { encoding: 'utf8' }); | ||
const output = readFileSync(filepath, { encoding: 'utf8' }); | ||
return JSON.parse(output); | ||
}; | ||
const resolveConfig = (normalizedConfigPath, normalizedFileIgnorePath, normalizedCaseIgnorePath, logger = report_1.env.defaultLogger) => { | ||
const resolveConfig = (normalizedConfigPath, normalizedFileIgnorePath, normalizedCaseIgnorePath, logger = env.defaultLogger) => { | ||
const result = { | ||
@@ -81,3 +80,5 @@ preset: 'default' | ||
try { | ||
const fileIgnores = (0, fs_1.readFileSync)(normalizedFileIgnorePath, { encoding: 'utf8' }); | ||
const fileIgnores = readFileSync(normalizedFileIgnorePath, { | ||
encoding: 'utf8' | ||
}); | ||
fileIgnores | ||
@@ -104,3 +105,5 @@ .split(/\n/) | ||
try { | ||
const caseIgnores = (0, fs_1.readFileSync)(normalizedCaseIgnorePath, { encoding: 'utf8' }); | ||
const caseIgnores = readFileSync(normalizedCaseIgnorePath, { | ||
encoding: 'utf8' | ||
}); | ||
caseIgnores | ||
@@ -127,6 +130,5 @@ .split(/\n/) | ||
}; | ||
const readRc = (dir, config, fileIgnore, caseIgnore, logger = report_1.env.defaultLogger) => { | ||
export const readRc = (dir, config, fileIgnore, caseIgnore, logger = env.defaultLogger) => { | ||
const { config: normalizedConfigPath, fileIgnore: normalizedFileIgnorePath, caseIgnore: normalizedCaseIgnorePath } = resolvePath(dir, config, fileIgnore, caseIgnore, logger); | ||
return resolveConfig(normalizedConfigPath, normalizedFileIgnorePath, normalizedCaseIgnorePath, logger); | ||
}; | ||
exports.readRc = readRc; |
@@ -1,8 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isBlock = void 0; | ||
const isBlock = (piece) => { | ||
export const isBlock = (piece) => { | ||
return !('nonBlock' in piece); | ||
}; | ||
exports.isBlock = isBlock; | ||
const replaceBlocks = (str, blocks) => { | ||
@@ -48,2 +44,2 @@ if (blocks.length === 0) { | ||
}; | ||
exports.default = replaceBlocks; | ||
export default replaceBlocks; |
@@ -1,11 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _a, _b; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.report = exports.reportItem = exports.ValidationTarget = exports.env = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const parser_1 = require("./parser"); | ||
exports.env = { | ||
import chalk from 'chalk'; | ||
import { CharType, checkCharType, isFullwidthPunctuationType, isHalfwidthPunctuationType } from './parser'; | ||
export const env = { | ||
stdout: (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.process) === null || _a === void 0 ? void 0 : _a.stdout, | ||
@@ -20,5 +14,5 @@ stderr: (_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.process) === null || _b === void 0 ? void 0 : _b.stderr, | ||
const { Console: NativeConsole } = require('console'); | ||
exports.env.stdout = fs.createWriteStream('./stdout.log', { encoding: 'utf-8' }); | ||
exports.env.stderr = fs.createWriteStream('./stderr.log', { encoding: 'utf-8' }); | ||
exports.env.defaultLogger = new NativeConsole(exports.env.stdout, exports.env.stderr); | ||
env.stdout = fs.createWriteStream('./stdout.log', { encoding: 'utf-8' }); | ||
env.stderr = fs.createWriteStream('./stderr.log', { encoding: 'utf-8' }); | ||
env.defaultLogger = new NativeConsole(env.stdout, env.stderr); | ||
} | ||
@@ -42,3 +36,3 @@ const getPositionByOffset = (str, offset) => { | ||
}; | ||
var ValidationTarget; | ||
export var ValidationTarget; | ||
(function (ValidationTarget) { | ||
@@ -50,3 +44,3 @@ ValidationTarget["VALUE"] = "value"; | ||
ValidationTarget["INNER_SPACE_BEFORE"] = "innerSpaceBefore"; | ||
})(ValidationTarget || (exports.ValidationTarget = ValidationTarget = {})); | ||
})(ValidationTarget || (ValidationTarget = {})); | ||
const adjustedFullwidthPunctuations = `“”‘’`; | ||
@@ -58,12 +52,12 @@ const generateMarker = (str, index) => { | ||
for (let i = 0; i < prefix.length; i++) { | ||
const charType = (0, parser_1.checkCharType)(prefix[i]); | ||
if (charType === parser_1.CharType.CJK_CHAR || | ||
((0, parser_1.isFullwidthPunctuationType)(charType) && | ||
const charType = checkCharType(prefix[i]); | ||
if (charType === CharType.CJK_CHAR || | ||
(isFullwidthPunctuationType(charType) && | ||
adjustedFullwidthPunctuations.indexOf(prefix[i]) === -1)) { | ||
fullwidthCount++; | ||
} | ||
else if (charType === parser_1.CharType.WESTERN_LETTER || | ||
((0, parser_1.isHalfwidthPunctuationType)(charType) && | ||
else if (charType === CharType.WESTERN_LETTER || | ||
(isHalfwidthPunctuationType(charType) && | ||
adjustedFullwidthPunctuations.indexOf(prefix[i]) !== -1) || | ||
charType === parser_1.CharType.SPACE) { | ||
charType === CharType.SPACE) { | ||
halfwidthCount++; | ||
@@ -74,5 +68,5 @@ } | ||
' '.repeat(fullwidthCount) + | ||
`${chalk_1.default.red('^')}`); | ||
`${chalk.red('^')}`); | ||
}; | ||
const reportItem = (file = '', str, validations, logger = exports.env.defaultLogger) => { | ||
export const reportItem = (file = '', str, validations, logger = env.defaultLogger) => { | ||
validations.forEach(({ index, length, target, message }) => { | ||
@@ -83,4 +77,4 @@ // 0. final index and position | ||
// 1. headline | ||
const fileDisplay = `${chalk_1.default.blue.bgWhite(file)}${file ? ':' : ''}`; | ||
const positionDisplay = `${chalk_1.default.yellow(row)}:${chalk_1.default.yellow(column)}`; | ||
const fileDisplay = `${chalk.blue.bgWhite(file)}${file ? ':' : ''}`; | ||
const positionDisplay = `${chalk.yellow(row)}:${chalk.yellow(column)}`; | ||
const headline = `${fileDisplay}${positionDisplay} - ${message}`; | ||
@@ -101,4 +95,3 @@ // 2. display fragment | ||
}; | ||
exports.reportItem = reportItem; | ||
const report = (resultList, logger = exports.env.defaultLogger) => { | ||
export const report = (resultList, logger = env.defaultLogger) => { | ||
let errorCount = 0; | ||
@@ -110,3 +103,3 @@ const invalidFiles = []; | ||
if (file) { | ||
logger.log(`${chalk_1.default.blue.bgWhite(file)}: disabled`); | ||
logger.log(`${chalk.blue.bgWhite(file)}: disabled`); | ||
} | ||
@@ -121,3 +114,3 @@ else { | ||
.forEach(({ file, origin, validations }) => { | ||
(0, exports.reportItem)(file, origin, validations, logger); | ||
reportItem(file, origin, validations, logger); | ||
errorCount += validations.length; | ||
@@ -140,2 +133,1 @@ if (file && validations.length) { | ||
}; | ||
exports.report = report; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -10,7 +9,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const report_1 = require("../report"); | ||
const util_1 = require("./util"); | ||
import { CharType } from '../parser'; | ||
import { ValidationTarget } from '../report'; | ||
import { findTokenAfter, findTokenBefore, removeValidationOnTarget } from './util'; | ||
const defaultSkippedAbbrs = [ | ||
@@ -33,3 +30,3 @@ 'Mr.', | ||
// find previous token | ||
const tokenBefore = (0, util_1.findTokenBefore)(group, token); | ||
const tokenBefore = findTokenBefore(group, token); | ||
if (tokenBefore && !tokenBefore.spaceAfter) { | ||
@@ -45,3 +42,3 @@ // get the next matching abbr chars by removing the last char and filtering | ||
if (lastMatched.length) { | ||
const tokenBeforeBefore = (0, util_1.findTokenBefore)(group, tokenBefore); | ||
const tokenBeforeBefore = findTokenBefore(group, tokenBefore); | ||
if (tokenBeforeBefore && | ||
@@ -71,5 +68,5 @@ !tokenBeforeBefore.spaceAfter && | ||
// make sure it's the ending dot of the abbr | ||
const tokenAfter = (0, util_1.findTokenAfter)(group, token); | ||
const tokenAfter = findTokenAfter(group, token); | ||
if (tokenAfter && | ||
tokenAfter.type === parser_1.CharType.WESTERN_LETTER && | ||
tokenAfter.type === CharType.WESTERN_LETTER && | ||
!token.spaceAfter) { | ||
@@ -82,9 +79,9 @@ return; | ||
token.modifiedType = token.type; | ||
(0, util_1.removeValidationOnTarget)(token, report_1.ValidationTarget.VALUE); | ||
removeValidationOnTarget(token, ValidationTarget.VALUE); | ||
} | ||
}; | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
skipAbbrs: defaultSkippedAbbrs | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -10,7 +9,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const report_1 = require("../report"); | ||
const util_1 = require("./util"); | ||
import { CharType } from '../parser'; | ||
import { ValidationTarget } from '../report'; | ||
import { findWrappersBetween, findNonCodeVisibleTokenAfter, findTokenAfter, removeValidationOnTarget } from './util'; | ||
const generateHandler = (options) => { | ||
@@ -24,5 +21,5 @@ options; | ||
// skip non-half-width-content tokens | ||
const tokenAfter = (0, util_1.findTokenAfter)(group, token); | ||
const tokenAfter = findTokenAfter(group, token); | ||
if (!tokenAfter || | ||
tokenAfter.type !== parser_1.CharType.WESTERN_LETTER || | ||
tokenAfter.type !== CharType.WESTERN_LETTER || | ||
token.spaceAfter) { | ||
@@ -32,3 +29,3 @@ return; | ||
// skip non-semicolon tokens | ||
const thirdToken = (0, util_1.findTokenAfter)(group, tokenAfter); | ||
const thirdToken = findTokenAfter(group, tokenAfter); | ||
if (!thirdToken || thirdToken.value !== ';' || tokenAfter.spaceAfter) { | ||
@@ -41,4 +38,4 @@ return; | ||
token.modifiedSpaceAfter = token.spaceAfter; | ||
(0, util_1.removeValidationOnTarget)(token, report_1.ValidationTarget.VALUE); | ||
(0, util_1.removeValidationOnTarget)(token, report_1.ValidationTarget.SPACE_AFTER); | ||
removeValidationOnTarget(token, ValidationTarget.VALUE); | ||
removeValidationOnTarget(token, ValidationTarget.SPACE_AFTER); | ||
// revert half-width content | ||
@@ -48,15 +45,15 @@ tokenAfter.modifiedValue = tokenAfter.value; | ||
tokenAfter.modifiedSpaceAfter = tokenAfter.spaceAfter; | ||
(0, util_1.removeValidationOnTarget)(tokenAfter, report_1.ValidationTarget.VALUE); | ||
(0, util_1.removeValidationOnTarget)(tokenAfter, report_1.ValidationTarget.SPACE_AFTER); | ||
removeValidationOnTarget(tokenAfter, ValidationTarget.VALUE); | ||
removeValidationOnTarget(tokenAfter, ValidationTarget.SPACE_AFTER); | ||
// revert ; | ||
thirdToken.modifiedValue = thirdToken.value; | ||
thirdToken.modifiedType = thirdToken.type; | ||
(0, util_1.removeValidationOnTarget)(thirdToken, report_1.ValidationTarget.VALUE); | ||
(0, util_1.removeValidationOnTarget)(thirdToken, report_1.ValidationTarget.SPACE_AFTER); | ||
const nextToken = (0, util_1.findNonCodeVisibleTokenAfter)(group, thirdToken); | ||
removeValidationOnTarget(thirdToken, ValidationTarget.VALUE); | ||
removeValidationOnTarget(thirdToken, ValidationTarget.SPACE_AFTER); | ||
const nextToken = findNonCodeVisibleTokenAfter(group, thirdToken); | ||
if (nextToken) { | ||
const { spaceHost } = (0, util_1.findWrappersBetween)(group, thirdToken, nextToken); | ||
const { spaceHost } = findWrappersBetween(group, thirdToken, nextToken); | ||
if (spaceHost) { | ||
spaceHost.modifiedSpaceAfter = spaceHost.spaceAfter; | ||
(0, util_1.removeValidationOnTarget)(spaceHost, report_1.ValidationTarget.SPACE_AFTER); | ||
removeValidationOnTarget(spaceHost, ValidationTarget.SPACE_AFTER); | ||
} | ||
@@ -66,3 +63,3 @@ } | ||
}; | ||
exports.defaultConfig = {}; | ||
exports.default = generateHandler; | ||
export const defaultConfig = {}; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -8,6 +7,4 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const report_1 = require("../report"); | ||
const util_1 = require("./util"); | ||
import { ValidationTarget } from '../report'; | ||
import { removeValidationOnTarget } from './util'; | ||
const generateHandler = (options) => { | ||
@@ -18,3 +15,3 @@ // do nothing | ||
if (token.spaceAfter && token.spaceAfter.match(/\n/)) { | ||
(0, util_1.removeValidationOnTarget)(token, report_1.ValidationTarget.SPACE_AFTER); | ||
removeValidationOnTarget(token, ValidationTarget.SPACE_AFTER); | ||
token.modifiedSpaceAfter = token.spaceAfter; | ||
@@ -24,3 +21,3 @@ } | ||
}; | ||
exports.defaultConfig = {}; | ||
exports.default = generateHandler; | ||
export const defaultConfig = {}; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -11,13 +10,11 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const report_1 = require("../report"); | ||
const util_1 = require("./util"); | ||
import { GroupTokenType, isFullwidthType } from '../parser'; | ||
import { ValidationTarget } from '../report'; | ||
import { removeValidationOnTarget } from './util'; | ||
const findNonWestern = (group) => { | ||
return group.some(token => { | ||
if (token.type === parser_1.GroupTokenType.GROUP) { | ||
return group.some((token) => { | ||
if (token.type === GroupTokenType.GROUP) { | ||
return findNonWestern(token); | ||
} | ||
if ((0, parser_1.isFullwidthType)(token.type)) { | ||
if (isFullwidthType(token.type)) { | ||
if (token.value.match(/[‘’“”]/)) { | ||
@@ -31,5 +28,5 @@ return false; | ||
const resetValidation = (group) => { | ||
group.forEach(token => { | ||
for (const target in report_1.ValidationTarget) { | ||
(0, util_1.removeValidationOnTarget)(token, target); | ||
group.forEach((token) => { | ||
for (const target in ValidationTarget) { | ||
removeValidationOnTarget(token, target); | ||
} | ||
@@ -39,3 +36,3 @@ token.modifiedSpaceAfter = token.spaceAfter; | ||
token.modifiedValue = token.value; | ||
if (token.type === parser_1.GroupTokenType.GROUP) { | ||
if (token.type === GroupTokenType.GROUP) { | ||
token.modifiedInnerSpaceBefore = token.innerSpaceBefore; | ||
@@ -60,5 +57,5 @@ resetValidation(token); | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
skipPureWestern: true | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -8,7 +7,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const report_1 = require("../report"); | ||
const util_1 = require("./util"); | ||
import { CharType, checkCharType } from '../parser'; | ||
import { ValidationTarget } from '../report'; | ||
import { findWrappersBetween, findNonCodeVisibleTokenAfter, findNonCodeVisibleTokenBefore, removeValidationOnTarget } from './util'; | ||
const defaultSkippedZhUnits = `年月日天号时分秒`; | ||
@@ -19,3 +16,3 @@ const generateHandler = (options) => { | ||
.split('') | ||
.filter((x) => (0, parser_1.checkCharType)(x) === parser_1.CharType.CJK_CHAR) | ||
.filter((x) => checkCharType(x) === CharType.CJK_CHAR) | ||
.join(''); | ||
@@ -25,5 +22,5 @@ const unitMatcher = new RegExp(`^[${matcherStr}]`); | ||
// make sure the value is a number | ||
if (token.type === parser_1.CharType.WESTERN_LETTER && token.value.match(/^\d+$/)) { | ||
if (token.type === CharType.WESTERN_LETTER && token.value.match(/^\d+$/)) { | ||
// make sure the value after is a Chinese unit | ||
const tokenAfter = (0, util_1.findNonCodeVisibleTokenAfter)(group, token); | ||
const tokenAfter = findNonCodeVisibleTokenAfter(group, token); | ||
if (Array.isArray(tokenAfter)) | ||
@@ -33,3 +30,3 @@ return; | ||
// make sure there is no space between originally | ||
const { spaceHost: spaceHostAfter, tokens: tokenSeqAfter } = (0, util_1.findWrappersBetween)(group, token, tokenAfter); | ||
const { spaceHost: spaceHostAfter, tokens: tokenSeqAfter } = findWrappersBetween(group, token, tokenAfter); | ||
const hasSpaceAfterOriginally = tokenSeqAfter.some((x) => x.spaceAfter); | ||
@@ -40,6 +37,6 @@ if (hasSpaceAfterOriginally) { | ||
// if any token before | ||
const tokenBefore = (0, util_1.findNonCodeVisibleTokenBefore)(group, token); | ||
const tokenBefore = findNonCodeVisibleTokenBefore(group, token); | ||
if (tokenBefore) { | ||
// make sure there is no space between originally | ||
const { spaceHost: spaceHostBefore, tokens: tokenSeqBefore } = (0, util_1.findWrappersBetween)(group, tokenBefore, token); | ||
const { spaceHost: spaceHostBefore, tokens: tokenSeqBefore } = findWrappersBetween(group, tokenBefore, token); | ||
const hasSpaceBeforeOriginally = tokenSeqBefore.some((x) => x.spaceAfter); | ||
@@ -52,3 +49,3 @@ if (hasSpaceBeforeOriginally) { | ||
spaceHostBefore.modifiedSpaceAfter = ''; | ||
(0, util_1.removeValidationOnTarget)(spaceHostBefore, report_1.ValidationTarget.SPACE_AFTER); | ||
removeValidationOnTarget(spaceHostBefore, ValidationTarget.SPACE_AFTER); | ||
} | ||
@@ -59,3 +56,3 @@ } | ||
spaceHostAfter.modifiedSpaceAfter = ''; | ||
(0, util_1.removeValidationOnTarget)(spaceHostAfter, report_1.ValidationTarget.SPACE_AFTER); | ||
removeValidationOnTarget(spaceHostAfter, ValidationTarget.SPACE_AFTER); | ||
} | ||
@@ -66,5 +63,5 @@ } | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
skipZhUnits: defaultSkippedZhUnits | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,40 +0,34 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const space_trim_1 = __importDefault(require("./space-trim")); | ||
const punctuation_width_1 = __importDefault(require("./punctuation-width")); | ||
const punctuation_unification_1 = __importDefault(require("./punctuation-unification")); | ||
const case_abbrs_1 = __importDefault(require("./case-abbrs")); | ||
const space_hyper_mark_1 = __importDefault(require("./space-hyper-mark")); | ||
const space_code_1 = __importDefault(require("./space-code")); | ||
const space_letter_1 = __importDefault(require("./space-letter")); | ||
const space_punctuation_1 = __importDefault(require("./space-punctuation")); | ||
const space_quotation_1 = __importDefault(require("./space-quotation")); | ||
const space_bracket_1 = __importDefault(require("./space-bracket")); | ||
const case_linebreak_1 = __importDefault(require("./case-linebreak")); | ||
const case_zh_units_1 = __importDefault(require("./case-zh-units")); | ||
const case_html_entity_1 = __importDefault(require("./case-html-entity")); | ||
const case_pure_western_1 = __importDefault(require("./case-pure-western")); | ||
import genSpaceTrimGenerateHandler from './space-trim'; | ||
import genPunctuationWidthHandler from './punctuation-width'; | ||
import genPunctuationUnificationHandler from './punctuation-unification'; | ||
import genAbbrsHandler from './case-abbrs'; | ||
import genSpaceOfHyperMarkHandler from './space-hyper-mark'; | ||
import genSpaceOfCodeHandler from './space-code'; | ||
import genSpaceOfLetterHandler from './space-letter'; | ||
import genSpaceOfPunctuationHandler from './space-punctuation'; | ||
import genSpaceOfQuotationHandler from './space-quotation'; | ||
import genSpaceOfBracketHandler from './space-bracket'; | ||
import genLinebreakHandler from './case-linebreak'; | ||
import genZhUnitsHandler from './case-zh-units'; | ||
import genHtmlEntityHandler from './case-html-entity'; | ||
import genSkipPureWesternHandler from './case-pure-western'; | ||
const generateHandlers = (options) => { | ||
return [ | ||
(0, space_trim_1.default)(options), | ||
(0, punctuation_width_1.default)(options), | ||
(0, punctuation_unification_1.default)(options), | ||
(0, case_abbrs_1.default)(options), | ||
(0, space_hyper_mark_1.default)(options), | ||
(0, space_code_1.default)(options), | ||
(0, space_letter_1.default)(options), | ||
(0, space_punctuation_1.default)(options), | ||
(0, space_quotation_1.default)(options), | ||
(0, space_bracket_1.default)(options), | ||
(0, case_linebreak_1.default)(options), | ||
(0, case_zh_units_1.default)(options), | ||
(0, case_html_entity_1.default)(options), | ||
(0, case_pure_western_1.default)(options), | ||
genSpaceTrimGenerateHandler(options), | ||
genPunctuationWidthHandler(options), | ||
genPunctuationUnificationHandler(options), | ||
genAbbrsHandler(options), | ||
genSpaceOfHyperMarkHandler(options), | ||
genSpaceOfCodeHandler(options), | ||
genSpaceOfLetterHandler(options), | ||
genSpaceOfPunctuationHandler(options), | ||
genSpaceOfQuotationHandler(options), | ||
genSpaceOfBracketHandler(options), | ||
genLinebreakHandler(options), | ||
genZhUnitsHandler(options), | ||
genHtmlEntityHandler(options), | ||
genSkipPureWesternHandler(options) | ||
]; | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
noSinglePair: true, | ||
@@ -73,4 +67,4 @@ halfwidthPunctuation: `()[]{}`, | ||
], | ||
skipPureWestern: true, | ||
skipPureWestern: true | ||
}; | ||
exports.default = generateHandlers; | ||
export default generateHandlers; |
@@ -1,26 +0,23 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TRIM_SPACE = exports.QUOTATION_SPACE_OUTSIDE = exports.QUOTATION_NOSPACE_OUTSIDE = exports.QUOTATION_NOSPACE_INSIDE = exports.CONTENT_NOSPACE_MIXED_WIDTH = exports.CONTENT_SPACE_MIXED_WIDTH = exports.CONTENT_NOSPACE_FULL_WIDTH = exports.CONTENT_SPACE_HALF_WIDTH = exports.BRACKET_SPACE_OUTSIDE = exports.BRACKET_NOSPACE_OUTSIDE = exports.BRACKET_NOSPACE_INSIDE = exports.PUNCTUATION_SPACE_AFTER = exports.PUNCTUATION_NOSPACE_AFTER = exports.PUNCTUATION_NOSPACE_BEFORE = exports.PUNCTUATION_HALF_WIDTH = exports.PUNCTUATION_FULL_WIDTH = exports.PUNCTUATION_UNIFICATION_SIMPLIFIED = exports.PUNCTUATION_UNIFICATION_TRADITIONAL = exports.PUNCTUATION_UNIFICATION = exports.MARKDOWN_NOSPACE_INSIDE = exports.MARKDOWN_SPACE_OUTSIDE = exports.CODE_NOSPACE_OUTSIDE = exports.CODE_SPACE_OUTSIDE = void 0; | ||
exports.CODE_SPACE_OUTSIDE = '此处内联代码的外部需要一个空格'; | ||
exports.CODE_NOSPACE_OUTSIDE = '此处内联代码的外部不需要空格'; | ||
exports.MARKDOWN_SPACE_OUTSIDE = '此处 Markdown 标记的空格需要在外部'; | ||
exports.MARKDOWN_NOSPACE_INSIDE = '此处 Markdown 标记的内部不需要空格'; | ||
exports.PUNCTUATION_UNIFICATION = '此处字符需要统一'; | ||
exports.PUNCTUATION_UNIFICATION_TRADITIONAL = '此处标点符号需要统一到繁体'; | ||
exports.PUNCTUATION_UNIFICATION_SIMPLIFIED = '此处标点符号需要统一到简体'; | ||
exports.PUNCTUATION_FULL_WIDTH = '此处标点符号需要使用全角'; | ||
exports.PUNCTUATION_HALF_WIDTH = '此处标点符号需要使用半角'; | ||
exports.PUNCTUATION_NOSPACE_BEFORE = '此处标点符号前不需要空格'; | ||
exports.PUNCTUATION_NOSPACE_AFTER = '此处标点符号后不需要空格'; | ||
exports.PUNCTUATION_SPACE_AFTER = '此处标点符号后需要一个空格'; | ||
exports.BRACKET_NOSPACE_INSIDE = '此处括号的内部不需要空格'; | ||
exports.BRACKET_NOSPACE_OUTSIDE = '此处括号的外部不需要空格'; | ||
exports.BRACKET_SPACE_OUTSIDE = '此处括号的外部需要一个空格'; | ||
exports.CONTENT_SPACE_HALF_WIDTH = '此处半角内容之间需要一个空格'; | ||
exports.CONTENT_NOSPACE_FULL_WIDTH = '此处全角内容之间不需要空格'; | ||
exports.CONTENT_SPACE_MIXED_WIDTH = '此处中英文内容之间需要一个空格'; | ||
exports.CONTENT_NOSPACE_MIXED_WIDTH = '此处中英文内容之间需要一个空格'; | ||
exports.QUOTATION_NOSPACE_INSIDE = '此处引号的内部不需要空格'; | ||
exports.QUOTATION_NOSPACE_OUTSIDE = '此处引号的外部不需要空格'; | ||
exports.QUOTATION_SPACE_OUTSIDE = '此处引号的外部需要一个空格'; | ||
exports.TRIM_SPACE = '此处需要去除外部空格'; | ||
export const CODE_SPACE_OUTSIDE = '此处内联代码的外部需要一个空格'; | ||
export const CODE_NOSPACE_OUTSIDE = '此处内联代码的外部不需要空格'; | ||
export const MARKDOWN_SPACE_OUTSIDE = '此处 Markdown 标记的空格需要在外部'; | ||
export const MARKDOWN_NOSPACE_INSIDE = '此处 Markdown 标记的内部不需要空格'; | ||
export const PUNCTUATION_UNIFICATION = '此处字符需要统一'; | ||
export const PUNCTUATION_UNIFICATION_TRADITIONAL = '此处标点符号需要统一到繁体'; | ||
export const PUNCTUATION_UNIFICATION_SIMPLIFIED = '此处标点符号需要统一到简体'; | ||
export const PUNCTUATION_FULL_WIDTH = '此处标点符号需要使用全角'; | ||
export const PUNCTUATION_HALF_WIDTH = '此处标点符号需要使用半角'; | ||
export const PUNCTUATION_NOSPACE_BEFORE = '此处标点符号前不需要空格'; | ||
export const PUNCTUATION_NOSPACE_AFTER = '此处标点符号后不需要空格'; | ||
export const PUNCTUATION_SPACE_AFTER = '此处标点符号后需要一个空格'; | ||
export const BRACKET_NOSPACE_INSIDE = '此处括号的内部不需要空格'; | ||
export const BRACKET_NOSPACE_OUTSIDE = '此处括号的外部不需要空格'; | ||
export const BRACKET_SPACE_OUTSIDE = '此处括号的外部需要一个空格'; | ||
export const CONTENT_SPACE_HALF_WIDTH = '此处半角内容之间需要一个空格'; | ||
export const CONTENT_NOSPACE_FULL_WIDTH = '此处全角内容之间不需要空格'; | ||
export const CONTENT_SPACE_MIXED_WIDTH = '此处中英文内容之间需要一个空格'; | ||
export const CONTENT_NOSPACE_MIXED_WIDTH = '此处中英文内容之间需要一个空格'; | ||
export const QUOTATION_NOSPACE_INSIDE = '此处引号的内部不需要空格'; | ||
export const QUOTATION_NOSPACE_OUTSIDE = '此处引号的外部不需要空格'; | ||
export const QUOTATION_SPACE_OUTSIDE = '此处引号的外部需要一个空格'; | ||
export const TRIM_SPACE = '此处需要去除外部空格'; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -11,7 +10,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const messages_1 = require("./messages"); | ||
const util_1 = require("./util"); | ||
import { GroupTokenType } from '../parser'; | ||
import { PUNCTUATION_UNIFICATION } from './messages'; | ||
import { checkEndValue, checkStartValue, checkValue } from './util'; | ||
const defaultUnifiedMap = { | ||
@@ -90,8 +87,8 @@ // U+2047 DOUBLE QUESTION MARK, U+203C DOUBLE EXCLAMATION MARK | ||
const handlerPunctuationUnified = (token) => { | ||
if (token.type === parser_1.GroupTokenType.GROUP) { | ||
if (token.type === GroupTokenType.GROUP) { | ||
if (charMap[token.modifiedStartValue]) { | ||
(0, util_1.checkStartValue)(token, charMap[token.modifiedStartValue], messages_1.PUNCTUATION_UNIFICATION); | ||
checkStartValue(token, charMap[token.modifiedStartValue], PUNCTUATION_UNIFICATION); | ||
} | ||
if (charMap[token.modifiedEndValue]) { | ||
(0, util_1.checkEndValue)(token, charMap[token.modifiedEndValue], messages_1.PUNCTUATION_UNIFICATION); | ||
checkEndValue(token, charMap[token.modifiedEndValue], PUNCTUATION_UNIFICATION); | ||
} | ||
@@ -102,3 +99,3 @@ return; | ||
if (charMap[token.modifiedValue]) { | ||
(0, util_1.checkValue)(token, charMap[token.modifiedValue], undefined, messages_1.PUNCTUATION_UNIFICATION); | ||
checkValue(token, charMap[token.modifiedValue], undefined, PUNCTUATION_UNIFICATION); | ||
} | ||
@@ -109,5 +106,5 @@ } | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
unifiedPunctuation: 'simplified' | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -16,7 +15,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const messages_1 = require("./messages"); | ||
const util_1 = require("./util"); | ||
import { GroupTokenType, HyperTokenType, isSinglePunctuationType, getFullwidthTokenType, getHalfwidthTokenType } from '../parser'; | ||
import { PUNCTUATION_FULL_WIDTH, PUNCTUATION_HALF_WIDTH } from './messages'; | ||
import { checkValue, checkEndValue, checkStartValue, isHalfwidthPunctuationWithoutSpaceAround, isSuccessiveHalfwidthPunctuation } from './util'; | ||
const widthPairList = [ | ||
@@ -45,3 +42,3 @@ [`,`, `,`], | ||
if (adjusted.indexOf(token.modifiedValue) >= 0) { | ||
token.modifiedType = (0, parser_1.getHalfwidthTokenType)(token.type); | ||
token.modifiedType = getHalfwidthTokenType(token.type); | ||
} | ||
@@ -85,13 +82,13 @@ }; | ||
// skip non-punctuation/quotation/bracket situations | ||
if (!(0, parser_1.isSinglePunctuationType)(token.type) && | ||
token.type !== parser_1.HyperTokenType.BRACKET_MARK && | ||
token.type !== parser_1.GroupTokenType.GROUP) { | ||
if (!isSinglePunctuationType(token.type) && | ||
token.type !== HyperTokenType.BRACKET_MARK && | ||
token.type !== GroupTokenType.GROUP) { | ||
return; | ||
} | ||
// skip halfwidth punctuations between halfwidth content without space | ||
if ((0, util_1.isHalfwidthPunctuationWithoutSpaceAround)(group, token)) { | ||
if (isHalfwidthPunctuationWithoutSpaceAround(group, token)) { | ||
return; | ||
} | ||
// skip successive multiple half-width punctuations | ||
if ((0, util_1.isSuccessiveHalfwidthPunctuation)(group, token)) { | ||
if (isSuccessiveHalfwidthPunctuation(group, token)) { | ||
return; | ||
@@ -101,11 +98,11 @@ } | ||
// 2. brackets in the alter width map | ||
if ((0, parser_1.isSinglePunctuationType)(token.type) || | ||
token.type === parser_1.HyperTokenType.BRACKET_MARK) { | ||
if (isSinglePunctuationType(token.type) || | ||
token.type === HyperTokenType.BRACKET_MARK) { | ||
const value = token.modifiedValue; | ||
if (fullwidthMap[value]) { | ||
(0, util_1.checkValue)(token, fullwidthMap[value], (0, parser_1.getFullwidthTokenType)(token.type), messages_1.PUNCTUATION_FULL_WIDTH); | ||
checkValue(token, fullwidthMap[value], getFullwidthTokenType(token.type), PUNCTUATION_FULL_WIDTH); | ||
checkAdjusted(token, adjusted); | ||
} | ||
else if (halfwidthMap[value]) { | ||
(0, util_1.checkValue)(token, halfwidthMap[value], (0, parser_1.getHalfwidthTokenType)(token.type), messages_1.PUNCTUATION_HALF_WIDTH); | ||
checkValue(token, halfwidthMap[value], getHalfwidthTokenType(token.type), PUNCTUATION_HALF_WIDTH); | ||
} | ||
@@ -118,12 +115,12 @@ return; | ||
if (fullwidthPairMap[startValue]) { | ||
(0, util_1.checkStartValue)(token, fullwidthPairMap[startValue][0], messages_1.PUNCTUATION_FULL_WIDTH); | ||
checkStartValue(token, fullwidthPairMap[startValue][0], PUNCTUATION_FULL_WIDTH); | ||
} | ||
else if (halfwidthMap[startValue]) { | ||
(0, util_1.checkStartValue)(token, halfwidthMap[startValue][0], messages_1.PUNCTUATION_HALF_WIDTH); | ||
checkStartValue(token, halfwidthMap[startValue][0], PUNCTUATION_HALF_WIDTH); | ||
} | ||
if (fullwidthPairMap[endValue]) { | ||
(0, util_1.checkEndValue)(token, fullwidthPairMap[endValue][1], messages_1.PUNCTUATION_FULL_WIDTH); | ||
checkEndValue(token, fullwidthPairMap[endValue][1], PUNCTUATION_FULL_WIDTH); | ||
} | ||
else if (halfwidthMap[endValue]) { | ||
(0, util_1.checkEndValue)(token, halfwidthMap[endValue][1], messages_1.PUNCTUATION_HALF_WIDTH); | ||
checkEndValue(token, halfwidthMap[endValue][1], PUNCTUATION_HALF_WIDTH); | ||
} | ||
@@ -133,3 +130,3 @@ }; | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
halfwidthPunctuation: defaultHalfwidthOption, | ||
@@ -139,2 +136,2 @@ fullwidthPunctuation: defaultFullwidthOption, | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -25,9 +24,7 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const util_1 = require("./util"); | ||
const messages_1 = require("./messages"); | ||
import { CharType, GroupTokenType, isLetterType, isFullwidthPair, MarkSideType, HyperTokenType } from '../parser'; | ||
import { checkSpaceAfter, findVisibleTokenAfter, findVisibleTokenBefore, findWrappersBetween, findTokenAfter, findTokenBefore } from './util'; | ||
import { BRACKET_NOSPACE_INSIDE, BRACKET_NOSPACE_OUTSIDE, BRACKET_SPACE_OUTSIDE } from './messages'; | ||
const isFullWidth = (char, adjusted) => { | ||
return (0, parser_1.isFullwidthPair)(char) && adjusted.indexOf(char) === -1; | ||
return isFullwidthPair(char) && adjusted.indexOf(char) === -1; | ||
}; | ||
@@ -38,3 +35,3 @@ const shouldSkip = (before, beforeTokenSeq, token, afterTokenSeq, after) => { | ||
} | ||
if ((0, parser_1.isFullwidthPair)(token.value) || (0, parser_1.isFullwidthPair)(token.modifiedValue)) { | ||
if (isFullwidthPair(token.value) || isFullwidthPair(token.modifiedValue)) { | ||
return false; | ||
@@ -49,3 +46,3 @@ } | ||
// ^ | ||
(before.type === parser_1.CharType.WESTERN_LETTER || | ||
(before.type === CharType.WESTERN_LETTER || | ||
// x() | ||
@@ -56,3 +53,3 @@ // ^ | ||
// ^ | ||
(after.type === parser_1.CharType.WESTERN_LETTER || | ||
(after.type === CharType.WESTERN_LETTER || | ||
// ()x | ||
@@ -69,3 +66,3 @@ // ^ | ||
// skip non-bracket tokens | ||
if (token.type !== parser_1.HyperTokenType.BRACKET_MARK) { | ||
if (token.type !== HyperTokenType.BRACKET_MARK) { | ||
return; | ||
@@ -75,7 +72,7 @@ } | ||
if (noInsideBracketOption) { | ||
if (token.markSide === parser_1.MarkSideType.LEFT) { | ||
if (token.markSide === MarkSideType.LEFT) { | ||
// no space after | ||
const tokenAfter = (0, util_1.findTokenAfter)(group, token); | ||
const tokenAfter = findTokenAfter(group, token); | ||
if (tokenAfter) { | ||
(0, util_1.checkSpaceAfter)(token, '', messages_1.BRACKET_NOSPACE_INSIDE); | ||
checkSpaceAfter(token, '', BRACKET_NOSPACE_INSIDE); | ||
} | ||
@@ -85,7 +82,7 @@ } | ||
// no space before | ||
const tokenBefore = (0, util_1.findTokenBefore)(group, token); | ||
const tokenBefore = findTokenBefore(group, token); | ||
if (tokenBefore && | ||
// dedupe | ||
tokenBefore.markSide !== parser_1.MarkSideType.LEFT) { | ||
(0, util_1.checkSpaceAfter)(tokenBefore, '', messages_1.BRACKET_NOSPACE_INSIDE); | ||
tokenBefore.markSide !== MarkSideType.LEFT) { | ||
checkSpaceAfter(tokenBefore, '', BRACKET_NOSPACE_INSIDE); | ||
} | ||
@@ -96,6 +93,6 @@ } | ||
// or empty brackets beside half-width content without spaces | ||
const contentTokenBefore = (0, util_1.findVisibleTokenBefore)(group, token); | ||
const contentTokenAfter = (0, util_1.findVisibleTokenAfter)(group, token); | ||
const { spaceHost: beforeSpaceHost, tokens: beforeTokenSeq } = (0, util_1.findWrappersBetween)(group, contentTokenBefore, token); | ||
const { spaceHost: afterSpaceHost, tokens: afterTokenSeq } = (0, util_1.findWrappersBetween)(group, token, contentTokenAfter); | ||
const contentTokenBefore = findVisibleTokenBefore(group, token); | ||
const contentTokenAfter = findVisibleTokenAfter(group, token); | ||
const { spaceHost: beforeSpaceHost, tokens: beforeTokenSeq } = findWrappersBetween(group, contentTokenBefore, token); | ||
const { spaceHost: afterSpaceHost, tokens: afterTokenSeq } = findWrappersBetween(group, token, contentTokenAfter); | ||
if (shouldSkip(contentTokenBefore, beforeTokenSeq, token, afterTokenSeq, contentTokenAfter)) { | ||
@@ -110,4 +107,4 @@ return; | ||
if (contentTokenAfter) { | ||
if (token.markSide === parser_1.MarkSideType.RIGHT && | ||
contentTokenAfter.markSide === parser_1.MarkSideType.LEFT) { | ||
if (token.markSide === MarkSideType.RIGHT && | ||
contentTokenAfter.markSide === MarkSideType.LEFT) { | ||
if (afterSpaceHost) { | ||
@@ -120,3 +117,3 @@ const hasFullWidth = fullWidth || | ||
if (noSpaceOutsideFullBracketOption) { | ||
(0, util_1.checkSpaceAfter)(token, '', messages_1.BRACKET_NOSPACE_OUTSIDE); | ||
checkSpaceAfter(token, '', BRACKET_NOSPACE_OUTSIDE); | ||
} | ||
@@ -130,5 +127,5 @@ } | ||
const message = spaceOutsideHalfBracketOption | ||
? messages_1.BRACKET_SPACE_OUTSIDE | ||
: messages_1.BRACKET_NOSPACE_OUTSIDE; | ||
(0, util_1.checkSpaceAfter)(token, spaceAfter, message); | ||
? BRACKET_SPACE_OUTSIDE | ||
: BRACKET_NOSPACE_OUTSIDE; | ||
checkSpaceAfter(token, spaceAfter, message); | ||
} | ||
@@ -142,7 +139,7 @@ } | ||
// 2.3 right-racket x content/left-quotation/code | ||
if (token.markSide === parser_1.MarkSideType.LEFT) { | ||
if (token.markSide === MarkSideType.LEFT) { | ||
if (contentTokenBefore && | ||
((0, parser_1.isLetterType)(contentTokenBefore.type) || | ||
contentTokenBefore.type === parser_1.GroupTokenType.GROUP || | ||
contentTokenBefore.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
(isLetterType(contentTokenBefore.type) || | ||
contentTokenBefore.type === GroupTokenType.GROUP || | ||
contentTokenBefore.type === HyperTokenType.CODE_CONTENT)) { | ||
if (beforeSpaceHost) { | ||
@@ -152,6 +149,6 @@ // 2.2.1 content/right-quotation/code x left-full-bracket | ||
if (fullWidth || | ||
(contentTokenBefore.type === parser_1.GroupTokenType.GROUP && | ||
(contentTokenBefore.type === GroupTokenType.GROUP && | ||
isFullWidth(contentTokenBefore.modifiedEndValue, adjustedFullWidthOption))) { | ||
if (noSpaceOutsideFullBracketOption) { | ||
(0, util_1.checkSpaceAfter)(beforeSpaceHost, '', messages_1.BRACKET_NOSPACE_OUTSIDE); | ||
checkSpaceAfter(beforeSpaceHost, '', BRACKET_NOSPACE_OUTSIDE); | ||
} | ||
@@ -163,5 +160,5 @@ } | ||
const message = spaceOutsideHalfBracketOption | ||
? messages_1.BRACKET_SPACE_OUTSIDE | ||
: messages_1.BRACKET_NOSPACE_OUTSIDE; | ||
(0, util_1.checkSpaceAfter)(beforeSpaceHost, spaceAfter, message); | ||
? BRACKET_SPACE_OUTSIDE | ||
: BRACKET_NOSPACE_OUTSIDE; | ||
checkSpaceAfter(beforeSpaceHost, spaceAfter, message); | ||
} | ||
@@ -174,5 +171,5 @@ } | ||
if (contentTokenAfter && | ||
((0, parser_1.isLetterType)(contentTokenAfter.type) || | ||
contentTokenAfter.type === parser_1.GroupTokenType.GROUP || | ||
contentTokenAfter.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
(isLetterType(contentTokenAfter.type) || | ||
contentTokenAfter.type === GroupTokenType.GROUP || | ||
contentTokenAfter.type === HyperTokenType.CODE_CONTENT)) { | ||
if (afterSpaceHost) { | ||
@@ -182,6 +179,6 @@ // 2.3.1 right-full-bracket x content/left-quotation/code | ||
if (fullWidth || | ||
(contentTokenAfter.type === parser_1.GroupTokenType.GROUP && | ||
(contentTokenAfter.type === GroupTokenType.GROUP && | ||
isFullWidth(contentTokenAfter.modifiedStartValue, adjustedFullWidthOption))) { | ||
if (noSpaceOutsideFullBracketOption) { | ||
(0, util_1.checkSpaceAfter)(afterSpaceHost, '', messages_1.BRACKET_NOSPACE_OUTSIDE); | ||
checkSpaceAfter(afterSpaceHost, '', BRACKET_NOSPACE_OUTSIDE); | ||
} | ||
@@ -193,5 +190,5 @@ } | ||
const message = spaceOutsideHalfBracketOption | ||
? messages_1.BRACKET_SPACE_OUTSIDE | ||
: messages_1.BRACKET_NOSPACE_OUTSIDE; | ||
(0, util_1.checkSpaceAfter)(afterSpaceHost, spaceAfter, message); | ||
? BRACKET_SPACE_OUTSIDE | ||
: BRACKET_NOSPACE_OUTSIDE; | ||
checkSpaceAfter(afterSpaceHost, spaceAfter, message); | ||
} | ||
@@ -205,6 +202,6 @@ } | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
spaceOutsideHalfBracket: true, | ||
noSpaceInsideBracket: true | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -22,11 +21,9 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const util_1 = require("./util"); | ||
const parser_1 = require("../parser"); | ||
const messages_1 = require("./messages"); | ||
import { checkSpaceAfter, findVisibleTokenAfter, findVisibleTokenBefore, findWrappersBetween } from './util'; | ||
import { isLetterType, HyperTokenType } from '../parser'; | ||
import { CODE_NOSPACE_OUTSIDE, CODE_SPACE_OUTSIDE } from './messages'; | ||
const generateHandler = (options) => { | ||
const needSpaceOption = options === null || options === void 0 ? void 0 : options.spaceOutsideCode; | ||
const spaceAfter = needSpaceOption ? ' ' : ''; | ||
const message = needSpaceOption ? messages_1.CODE_SPACE_OUTSIDE : messages_1.CODE_NOSPACE_OUTSIDE; | ||
const message = needSpaceOption ? CODE_SPACE_OUTSIDE : CODE_NOSPACE_OUTSIDE; | ||
const handleHyperSpaceOption = (token, _, group) => { | ||
@@ -38,19 +35,19 @@ // skip if there is no options | ||
// skip non-code tokens | ||
if (token.type !== parser_1.HyperTokenType.CODE_CONTENT) { | ||
if (token.type !== HyperTokenType.CODE_CONTENT) { | ||
return; | ||
} | ||
// skip non-after-token situations | ||
const contentTokenBefore = (0, util_1.findVisibleTokenBefore)(group, token); | ||
const contentTokenAfter = (0, util_1.findVisibleTokenAfter)(group, token); | ||
const { spaceHost: beforeSpaceHost } = (0, util_1.findWrappersBetween)(group, contentTokenBefore, token); | ||
const { spaceHost: afterSpaceHost } = (0, util_1.findWrappersBetween)(group, token, contentTokenAfter); | ||
const contentTokenBefore = findVisibleTokenBefore(group, token); | ||
const contentTokenAfter = findVisibleTokenAfter(group, token); | ||
const { spaceHost: beforeSpaceHost } = findWrappersBetween(group, contentTokenBefore, token); | ||
const { spaceHost: afterSpaceHost } = findWrappersBetween(group, token, contentTokenAfter); | ||
// content x code | ||
if (contentTokenBefore && (0, parser_1.isLetterType)(contentTokenBefore.type)) { | ||
beforeSpaceHost && (0, util_1.checkSpaceAfter)(beforeSpaceHost, spaceAfter, message); | ||
if (contentTokenBefore && isLetterType(contentTokenBefore.type)) { | ||
beforeSpaceHost && checkSpaceAfter(beforeSpaceHost, spaceAfter, message); | ||
} | ||
// code x content or code x code | ||
if (contentTokenAfter && | ||
((0, parser_1.isLetterType)(contentTokenAfter.type) || | ||
contentTokenAfter.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
afterSpaceHost && (0, util_1.checkSpaceAfter)(afterSpaceHost, spaceAfter, message); | ||
(isLetterType(contentTokenAfter.type) || | ||
contentTokenAfter.type === HyperTokenType.CODE_CONTENT)) { | ||
afterSpaceHost && checkSpaceAfter(afterSpaceHost, spaceAfter, message); | ||
} | ||
@@ -60,5 +57,5 @@ }; | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
spaceOutsideCode: true | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -24,7 +23,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const util_1 = require("./util"); | ||
const parser_1 = require("../parser"); | ||
const messages_1 = require("./messages"); | ||
import { checkSpaceAfter, findTokenAfter, isWrapper, getWrapperSide } from './util'; | ||
import { MarkSideType } from '../parser'; | ||
import { MARKDOWN_NOSPACE_INSIDE } from './messages'; | ||
const generateHandler = (options) => { | ||
@@ -38,3 +35,3 @@ const noSpaceInsideMarkOption = options === null || options === void 0 ? void 0 : options.noSpaceInsideHyperMark; | ||
// skip non-after-token situations | ||
const tokenAfter = (0, util_1.findTokenAfter)(group, token); | ||
const tokenAfter = findTokenAfter(group, token); | ||
if (!tokenAfter) { | ||
@@ -44,3 +41,3 @@ return; | ||
// skip non-mark situations | ||
if (!(0, util_1.isWrapper)(token) && !(0, util_1.isWrapper)(tokenAfter)) { | ||
if (!isWrapper(token) && !isWrapper(tokenAfter)) { | ||
return; | ||
@@ -51,18 +48,18 @@ } | ||
// 3. non-mark x right | ||
const markSideBefore = (0, util_1.getWrapperSide)(token); | ||
const markSideAfter = (0, util_1.getWrapperSide)(tokenAfter); | ||
const markSideBefore = getWrapperSide(token); | ||
const markSideAfter = getWrapperSide(tokenAfter); | ||
if (markSideBefore === markSideAfter) { | ||
(0, util_1.checkSpaceAfter)(token, '', messages_1.MARKDOWN_NOSPACE_INSIDE); | ||
checkSpaceAfter(token, '', MARKDOWN_NOSPACE_INSIDE); | ||
} | ||
else if (markSideBefore === parser_1.MarkSideType.LEFT && !(0, util_1.isWrapper)(tokenAfter)) { | ||
(0, util_1.checkSpaceAfter)(token, '', messages_1.MARKDOWN_NOSPACE_INSIDE); | ||
else if (markSideBefore === MarkSideType.LEFT && !isWrapper(tokenAfter)) { | ||
checkSpaceAfter(token, '', MARKDOWN_NOSPACE_INSIDE); | ||
} | ||
else if (markSideAfter === parser_1.MarkSideType.RIGHT && !(0, util_1.isWrapper)(token)) { | ||
(0, util_1.checkSpaceAfter)(token, '', messages_1.MARKDOWN_NOSPACE_INSIDE); | ||
else if (markSideAfter === MarkSideType.RIGHT && !isWrapper(token)) { | ||
checkSpaceAfter(token, '', MARKDOWN_NOSPACE_INSIDE); | ||
} | ||
}; | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
noSpaceInsideMark: true | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -32,7 +31,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const util_1 = require("./util"); | ||
const messages_1 = require("./messages"); | ||
import { CharType, isLetterType } from '../parser'; | ||
import { checkSpaceAfter, findVisibleTokenAfter, findWrappersBetween } from './util'; | ||
import { CONTENT_NOSPACE_FULL_WIDTH, CONTENT_NOSPACE_MIXED_WIDTH, CONTENT_SPACE_HALF_WIDTH, CONTENT_SPACE_MIXED_WIDTH } from './messages'; | ||
const generateHandler = (options) => { | ||
@@ -44,12 +41,12 @@ const onlyOneBetweenHalfwidthContentOption = options === null || options === void 0 ? void 0 : options.spaceBetweenHalfwidthContent; | ||
// skip non-content tokens | ||
if (!(0, parser_1.isLetterType)(token.type)) { | ||
if (!isLetterType(token.type)) { | ||
return; | ||
} | ||
// skip non-content after-tokens | ||
const contentTokenAfter = (0, util_1.findVisibleTokenAfter)(group, token); | ||
if (!contentTokenAfter || !(0, parser_1.isLetterType)(contentTokenAfter.type)) { | ||
const contentTokenAfter = findVisibleTokenAfter(group, token); | ||
if (!contentTokenAfter || !isLetterType(contentTokenAfter.type)) { | ||
return; | ||
} | ||
// find the space host | ||
const { spaceHost, tokens } = (0, util_1.findWrappersBetween)(group, token, contentTokenAfter); | ||
const { spaceHost, tokens } = findWrappersBetween(group, token, contentTokenAfter); | ||
// skip if the space host is not found | ||
@@ -63,3 +60,3 @@ if (!spaceHost) { | ||
// skip without custom option | ||
if (token.type === parser_1.CharType.WESTERN_LETTER) { | ||
if (token.type === CharType.WESTERN_LETTER) { | ||
if (!onlyOneBetweenHalfwidthContentOption) { | ||
@@ -79,7 +76,7 @@ return; | ||
} | ||
const spaceAfter = token.type === parser_1.CharType.WESTERN_LETTER ? ' ' : ''; | ||
const message = token.type === parser_1.CharType.WESTERN_LETTER | ||
? messages_1.CONTENT_SPACE_HALF_WIDTH | ||
: messages_1.CONTENT_NOSPACE_FULL_WIDTH; | ||
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message); | ||
const spaceAfter = token.type === CharType.WESTERN_LETTER ? ' ' : ''; | ||
const message = token.type === CharType.WESTERN_LETTER | ||
? CONTENT_SPACE_HALF_WIDTH | ||
: CONTENT_NOSPACE_FULL_WIDTH; | ||
checkSpaceAfter(spaceHost, spaceAfter, message); | ||
} | ||
@@ -93,9 +90,9 @@ else { | ||
const message = betweenMixedwidthContentOption | ||
? messages_1.CONTENT_SPACE_MIXED_WIDTH | ||
: messages_1.CONTENT_NOSPACE_MIXED_WIDTH; | ||
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message); | ||
? CONTENT_SPACE_MIXED_WIDTH | ||
: CONTENT_NOSPACE_MIXED_WIDTH; | ||
checkSpaceAfter(spaceHost, spaceAfter, message); | ||
} | ||
}; | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
spaceBetweenHalfWidthContent: true, | ||
@@ -105,2 +102,2 @@ noSpaceBetweenFullWidthContent: true, | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -31,7 +30,5 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const util_1 = require("./util"); | ||
const messages_1 = require("./messages"); | ||
import { GroupTokenType, isLetterType, isPauseOrStopType, MarkSideType, HyperTokenType, isFullwidthPunctuationType, isHalfwidthPunctuationType } from '../parser'; | ||
import { checkSpaceAfter, findVisibleTokenAfter, findVisibleTokenBefore, findWrappersBetween, isHalfwidthPunctuationWithoutSpaceAround, isSuccessiveHalfwidthPunctuation } from './util'; | ||
import { PUNCTUATION_NOSPACE_AFTER, PUNCTUATION_NOSPACE_BEFORE, PUNCTUATION_SPACE_AFTER } from './messages'; | ||
const generateHandler = (options) => { | ||
@@ -43,11 +40,11 @@ const noBeforePunctuationOption = options === null || options === void 0 ? void 0 : options.noSpaceBeforePauseOrStop; | ||
// skip non-punctuation tokens and non-normal punctuations | ||
if (!(0, parser_1.isPauseOrStopType)(token.type)) { | ||
if (!isPauseOrStopType(token.type)) { | ||
return; | ||
} | ||
// skip half-width punctuations between half-width content without space | ||
if ((0, util_1.isHalfwidthPunctuationWithoutSpaceAround)(group, token)) { | ||
if (isHalfwidthPunctuationWithoutSpaceAround(group, token)) { | ||
return; | ||
} | ||
// skip successive multiple half-width punctuations | ||
if ((0, util_1.isSuccessiveHalfwidthPunctuation)(group, token)) { | ||
if (isSuccessiveHalfwidthPunctuation(group, token)) { | ||
return; | ||
@@ -57,16 +54,16 @@ } | ||
if (noBeforePunctuationOption) { | ||
const contentTokenBefore = (0, util_1.findVisibleTokenBefore)(group, token); | ||
const contentTokenBefore = findVisibleTokenBefore(group, token); | ||
if (contentTokenBefore && | ||
// content | ||
((0, parser_1.isLetterType)(contentTokenBefore.type) || | ||
(isLetterType(contentTokenBefore.type) || | ||
// right-quotation | ||
contentTokenBefore.type === parser_1.GroupTokenType.GROUP || | ||
contentTokenBefore.type === GroupTokenType.GROUP || | ||
// right-bracket | ||
(contentTokenBefore.type === parser_1.HyperTokenType.BRACKET_MARK && | ||
contentTokenBefore.markSide === parser_1.MarkSideType.RIGHT) || | ||
(contentTokenBefore.type === HyperTokenType.BRACKET_MARK && | ||
contentTokenBefore.markSide === MarkSideType.RIGHT) || | ||
// code | ||
contentTokenBefore.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = (0, util_1.findWrappersBetween)(group, contentTokenBefore, token); | ||
contentTokenBefore.type === HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = findWrappersBetween(group, contentTokenBefore, token); | ||
if (spaceHost) { | ||
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.PUNCTUATION_NOSPACE_BEFORE); | ||
checkSpaceAfter(spaceHost, '', PUNCTUATION_NOSPACE_BEFORE); | ||
} | ||
@@ -76,26 +73,26 @@ } | ||
// 2. half/full x content/left-quotation/left-bracket/code | ||
if (((0, parser_1.isFullwidthPunctuationType)(token.modifiedType) && | ||
if ((isFullwidthPunctuationType(token.modifiedType) && | ||
noAfterFullWidthPunctuationOption) || | ||
((0, parser_1.isHalfwidthPunctuationType)(token.modifiedType) && | ||
(isHalfwidthPunctuationType(token.modifiedType) && | ||
oneAfterHalfWidthPunctuationOption)) { | ||
const spaceAfter = (0, parser_1.isHalfwidthPunctuationType)(token.modifiedType) | ||
const spaceAfter = isHalfwidthPunctuationType(token.modifiedType) | ||
? ' ' | ||
: ''; | ||
const message = (0, parser_1.isHalfwidthPunctuationType)(token.modifiedType) | ||
? messages_1.PUNCTUATION_SPACE_AFTER | ||
: messages_1.PUNCTUATION_NOSPACE_AFTER; | ||
const contentTokenAfter = (0, util_1.findVisibleTokenAfter)(group, token); | ||
const message = isHalfwidthPunctuationType(token.modifiedType) | ||
? PUNCTUATION_SPACE_AFTER | ||
: PUNCTUATION_NOSPACE_AFTER; | ||
const contentTokenAfter = findVisibleTokenAfter(group, token); | ||
if (contentTokenAfter && | ||
// content | ||
((0, parser_1.isLetterType)(contentTokenAfter.type) || | ||
(isLetterType(contentTokenAfter.type) || | ||
// left-quotation | ||
contentTokenAfter.type === parser_1.GroupTokenType.GROUP || | ||
contentTokenAfter.type === GroupTokenType.GROUP || | ||
// left-bracket | ||
(contentTokenAfter.type === parser_1.HyperTokenType.BRACKET_MARK && | ||
contentTokenAfter.markSide === parser_1.MarkSideType.LEFT) || | ||
(contentTokenAfter.type === HyperTokenType.BRACKET_MARK && | ||
contentTokenAfter.markSide === MarkSideType.LEFT) || | ||
// code | ||
contentTokenAfter.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = (0, util_1.findWrappersBetween)(group, token, contentTokenAfter); | ||
contentTokenAfter.type === HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = findWrappersBetween(group, token, contentTokenAfter); | ||
if (spaceHost) { | ||
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message); | ||
checkSpaceAfter(spaceHost, spaceAfter, message); | ||
} | ||
@@ -106,3 +103,3 @@ } | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
noSpaceBeforePunctuation: true, | ||
@@ -112,2 +109,2 @@ spaceAfterHalfWidthPunctuation: true, | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -26,9 +25,7 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const parser_1 = require("../parser"); | ||
const util_1 = require("./util"); | ||
const messages_1 = require("./messages"); | ||
import { GroupTokenType, isLetterType, isFullwidthPair, MarkSideType, HyperTokenType } from '../parser'; | ||
import { checkInnerSpaceBefore, checkSpaceAfter, findWrappersBetween, findNonCodeVisibleTokenAfter, findNonCodeVisibleTokenBefore } from './util'; | ||
import { QUOTATION_NOSPACE_INSIDE, QUOTATION_NOSPACE_OUTSIDE, QUOTATION_SPACE_OUTSIDE } from './messages'; | ||
const isFullWidth = (char, adjusted) => { | ||
return (0, parser_1.isFullwidthPair)(char) && adjusted.indexOf(char) === -1; | ||
return isFullwidthPair(char) && adjusted.indexOf(char) === -1; | ||
}; | ||
@@ -42,3 +39,3 @@ const generateHandler = (options) => { | ||
// skip non-group tokens | ||
if (token.type !== parser_1.GroupTokenType.GROUP) { | ||
if (token.type !== GroupTokenType.GROUP) { | ||
return; | ||
@@ -51,13 +48,13 @@ } | ||
if (firstInsdieToken && | ||
firstInsdieToken.markSide !== parser_1.MarkSideType.RIGHT) { | ||
(0, util_1.checkInnerSpaceBefore)(token, '', messages_1.QUOTATION_NOSPACE_INSIDE); | ||
firstInsdieToken.markSide !== MarkSideType.RIGHT) { | ||
checkInnerSpaceBefore(token, '', QUOTATION_NOSPACE_INSIDE); | ||
} | ||
// 1.2 content/punctuation/right-quotation/right-bracket/code/unknown/container x right-quotation | ||
const lastInsideToken = token[token.length - 1]; | ||
if (lastInsideToken && lastInsideToken.markSide !== parser_1.MarkSideType.LEFT) { | ||
(0, util_1.checkSpaceAfter)(lastInsideToken, '', messages_1.QUOTATION_NOSPACE_INSIDE); | ||
if (lastInsideToken && lastInsideToken.markSide !== MarkSideType.LEFT) { | ||
checkSpaceAfter(lastInsideToken, '', QUOTATION_NOSPACE_INSIDE); | ||
} | ||
// 1.3 left-quotation x right-quotation | ||
if (!firstInsdieToken) { | ||
(0, util_1.checkInnerSpaceBefore)(token, '', messages_1.QUOTATION_NOSPACE_INSIDE); | ||
checkInnerSpaceBefore(token, '', QUOTATION_NOSPACE_INSIDE); | ||
} | ||
@@ -69,6 +66,6 @@ } | ||
// 2.1 right-quotation x left-quotation | ||
const contentTokenAfter = (0, util_1.findNonCodeVisibleTokenAfter)(group, token); | ||
const contentTokenAfter = findNonCodeVisibleTokenAfter(group, token); | ||
if (contentTokenAfter && | ||
contentTokenAfter.type === parser_1.GroupTokenType.GROUP) { | ||
const { spaceHost } = (0, util_1.findWrappersBetween)(group, token, contentTokenAfter); | ||
contentTokenAfter.type === GroupTokenType.GROUP) { | ||
const { spaceHost } = findWrappersBetween(group, token, contentTokenAfter); | ||
if (spaceHost) { | ||
@@ -81,3 +78,3 @@ const fullWidth = isFullWidth(token.modifiedEndValue, adjustedFullWidthOption) || | ||
if (noSpaceOutsideFullQuotationOption) { | ||
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTATION_SPACE_OUTSIDE); | ||
checkSpaceAfter(spaceHost, '', QUOTATION_SPACE_OUTSIDE); | ||
} | ||
@@ -89,5 +86,5 @@ } | ||
const message = spaceOutsideHalfQuotationOption | ||
? messages_1.QUOTATION_SPACE_OUTSIDE | ||
: messages_1.QUOTATION_NOSPACE_OUTSIDE; | ||
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message); | ||
? QUOTATION_SPACE_OUTSIDE | ||
: QUOTATION_NOSPACE_OUTSIDE; | ||
checkSpaceAfter(spaceHost, spaceAfter, message); | ||
} | ||
@@ -98,7 +95,7 @@ } | ||
// 2.2 content/code x left-quotation | ||
const contentTokenBefore = (0, util_1.findNonCodeVisibleTokenBefore)(group, token); | ||
const contentTokenBefore = findNonCodeVisibleTokenBefore(group, token); | ||
if (contentTokenBefore && | ||
((0, parser_1.isLetterType)(contentTokenBefore.type) || | ||
contentTokenBefore.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = (0, util_1.findWrappersBetween)(group, contentTokenBefore, token); | ||
(isLetterType(contentTokenBefore.type) || | ||
contentTokenBefore.type === HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = findWrappersBetween(group, contentTokenBefore, token); | ||
if (spaceHost) { | ||
@@ -110,3 +107,3 @@ const fullWidth = isFullWidth(token.modifiedStartValue, adjustedFullWidthOption); | ||
if (noSpaceOutsideFullQuotationOption) { | ||
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTATION_NOSPACE_OUTSIDE); | ||
checkSpaceAfter(spaceHost, '', QUOTATION_NOSPACE_OUTSIDE); | ||
} | ||
@@ -118,5 +115,5 @@ } | ||
const message = spaceOutsideHalfQuotationOption | ||
? messages_1.QUOTATION_SPACE_OUTSIDE | ||
: messages_1.QUOTATION_NOSPACE_OUTSIDE; | ||
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message); | ||
? QUOTATION_SPACE_OUTSIDE | ||
: QUOTATION_NOSPACE_OUTSIDE; | ||
checkSpaceAfter(spaceHost, spaceAfter, message); | ||
} | ||
@@ -128,5 +125,5 @@ } | ||
if (contentTokenAfter && | ||
((0, parser_1.isLetterType)(contentTokenAfter.type) || | ||
contentTokenAfter.type === parser_1.HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = (0, util_1.findWrappersBetween)(group, token, contentTokenAfter); | ||
(isLetterType(contentTokenAfter.type) || | ||
contentTokenAfter.type === HyperTokenType.CODE_CONTENT)) { | ||
const { spaceHost } = findWrappersBetween(group, token, contentTokenAfter); | ||
if (spaceHost) { | ||
@@ -138,3 +135,3 @@ const fullWidth = isFullWidth(token.modifiedEndValue, adjustedFullWidthOption); | ||
if (noSpaceOutsideFullQuotationOption) { | ||
(0, util_1.checkSpaceAfter)(spaceHost, '', messages_1.QUOTATION_NOSPACE_OUTSIDE); | ||
checkSpaceAfter(spaceHost, '', QUOTATION_NOSPACE_OUTSIDE); | ||
} | ||
@@ -146,5 +143,5 @@ } | ||
const message = spaceOutsideHalfQuotationOption | ||
? messages_1.QUOTATION_SPACE_OUTSIDE | ||
: messages_1.QUOTATION_NOSPACE_OUTSIDE; | ||
(0, util_1.checkSpaceAfter)(spaceHost, spaceAfter, message); | ||
? QUOTATION_SPACE_OUTSIDE | ||
: QUOTATION_NOSPACE_OUTSIDE; | ||
checkSpaceAfter(spaceHost, spaceAfter, message); | ||
} | ||
@@ -157,3 +154,3 @@ } | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
spaceOutsideHalfwidthQuotation: true, | ||
@@ -163,2 +160,2 @@ noSpaceInsideQuotation: true, | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -10,6 +9,4 @@ * @fileoverview | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultConfig = void 0; | ||
const messages_1 = require("./messages"); | ||
const util_1 = require("./util"); | ||
import { TRIM_SPACE } from './messages'; | ||
import { checkInnerSpaceBefore, checkSpaceAfter, findVisibleTokenBefore, findConnectedWrappers, isWrapper } from './util'; | ||
const generateHandler = (options) => { | ||
@@ -25,7 +22,7 @@ const trimSpaceOption = options === null || options === void 0 ? void 0 : options.trimSpace; | ||
if (group.modifiedInnerSpaceBefore) { | ||
(0, util_1.checkInnerSpaceBefore)(group, '', messages_1.TRIM_SPACE); | ||
checkInnerSpaceBefore(group, '', TRIM_SPACE); | ||
} | ||
// remove all spaces after beginning marks | ||
if ((0, util_1.isWrapper)(token)) { | ||
(0, util_1.findConnectedWrappers)(group, token).forEach((x) => (0, util_1.checkSpaceAfter)(x, '', messages_1.TRIM_SPACE)); | ||
if (isWrapper(token)) { | ||
findConnectedWrappers(group, token).forEach((x) => checkSpaceAfter(x, '', TRIM_SPACE)); | ||
} | ||
@@ -37,11 +34,11 @@ // get last visible content token -> remove all spaces after | ||
// 2. last token is visible content | ||
if ((0, util_1.isWrapper)(lastToken)) { | ||
const lastContentToken = (0, util_1.findVisibleTokenBefore)(group, token); | ||
if (isWrapper(lastToken)) { | ||
const lastContentToken = findVisibleTokenBefore(group, token); | ||
if (lastContentToken) { | ||
(0, util_1.findConnectedWrappers)(group, lastToken).forEach((x) => (0, util_1.checkSpaceAfter)(x, '', messages_1.TRIM_SPACE)); | ||
(0, util_1.checkSpaceAfter)(lastContentToken, '', messages_1.TRIM_SPACE); | ||
findConnectedWrappers(group, lastToken).forEach((x) => checkSpaceAfter(x, '', TRIM_SPACE)); | ||
checkSpaceAfter(lastContentToken, '', TRIM_SPACE); | ||
} | ||
} | ||
else { | ||
(0, util_1.checkSpaceAfter)(lastToken, '', messages_1.TRIM_SPACE); | ||
checkSpaceAfter(lastToken, '', TRIM_SPACE); | ||
} | ||
@@ -52,5 +49,5 @@ } | ||
}; | ||
exports.defaultConfig = { | ||
export const defaultConfig = { | ||
trimSpace: true | ||
}; | ||
exports.default = generateHandler; | ||
export default generateHandler; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkValue = exports.checkInnerSpaceBefore = exports.checkEndValue = exports.checkStartValue = exports.checkSpaceAfter = exports.removeValidationOnTarget = exports.hasValidationOnTarget = exports.setValidationOnTarget = exports.isSuccessiveHalfwidthPunctuation = exports.isHalfwidthPunctuationWithoutSpaceAround = exports.findWrappersBetween = exports.findConnectedWrappers = exports.getWrapperSide = exports.isWrapper = exports.findVisibleTokenAfter = exports.findVisibleTokenBefore = exports.findNonCodeVisibleTokenAfter = exports.findNonCodeVisibleTokenBefore = exports.findTokenAfter = exports.findTokenBefore = void 0; | ||
const report_1 = require("../report"); | ||
const parser_1 = require("../parser"); | ||
import { ValidationTarget } from '../report'; | ||
import { MarkSideType, HyperTokenType, isNonCodeVisibleType, isInvisibleType, isVisibleType, CharType, isHalfwidthPunctuationType } from '../parser'; | ||
// find tokens | ||
@@ -10,3 +7,3 @@ /** | ||
*/ | ||
const findTokenBefore = (group, token) => { | ||
export const findTokenBefore = (group, token) => { | ||
if (!token) { | ||
@@ -21,7 +18,6 @@ return; | ||
}; | ||
exports.findTokenBefore = findTokenBefore; | ||
/** | ||
* Find the next token if exists | ||
*/ | ||
const findTokenAfter = (group, token) => { | ||
export const findTokenAfter = (group, token) => { | ||
if (!token) { | ||
@@ -36,3 +32,2 @@ return; | ||
}; | ||
exports.findTokenAfter = findTokenAfter; | ||
/** | ||
@@ -44,7 +39,7 @@ * Find a certain token before, which: | ||
*/ | ||
const findNonCodeVisibleTokenBefore = (group, token) => { | ||
export const findNonCodeVisibleTokenBefore = (group, token) => { | ||
if (!token) { | ||
return; | ||
} | ||
const beforeToken = (0, exports.findTokenBefore)(group, token); | ||
const beforeToken = findTokenBefore(group, token); | ||
if (!beforeToken) { | ||
@@ -54,7 +49,7 @@ return; | ||
// hyper mark, html pairs: skip | ||
if ((0, parser_1.isInvisibleType)(beforeToken.type) || getHtmlTagSide(beforeToken)) { | ||
return (0, exports.findNonCodeVisibleTokenBefore)(group, beforeToken); | ||
if (isInvisibleType(beforeToken.type) || getHtmlTagSide(beforeToken)) { | ||
return findNonCodeVisibleTokenBefore(group, beforeToken); | ||
} | ||
// content, punctuation, bracket, group: return token | ||
if ((0, parser_1.isNonCodeVisibleType)(beforeToken.type)) { | ||
if (isNonCodeVisibleType(beforeToken.type)) { | ||
return beforeToken; | ||
@@ -65,3 +60,2 @@ } | ||
}; | ||
exports.findNonCodeVisibleTokenBefore = findNonCodeVisibleTokenBefore; | ||
/** | ||
@@ -73,7 +67,7 @@ * Find a certain token after, which: | ||
*/ | ||
const findNonCodeVisibleTokenAfter = (group, token) => { | ||
export const findNonCodeVisibleTokenAfter = (group, token) => { | ||
if (!token) { | ||
return; | ||
} | ||
const afterToken = (0, exports.findTokenAfter)(group, token); | ||
const afterToken = findTokenAfter(group, token); | ||
if (!afterToken) { | ||
@@ -83,7 +77,7 @@ return; | ||
// hyper mark, html pairs: skip | ||
if ((0, parser_1.isInvisibleType)(afterToken.type) || getHtmlTagSide(afterToken)) { | ||
return (0, exports.findNonCodeVisibleTokenAfter)(group, afterToken); | ||
if (isInvisibleType(afterToken.type) || getHtmlTagSide(afterToken)) { | ||
return findNonCodeVisibleTokenAfter(group, afterToken); | ||
} | ||
// content, punctuation, bracket, group: return token | ||
if ((0, parser_1.isNonCodeVisibleType)(afterToken.type)) { | ||
if (isNonCodeVisibleType(afterToken.type)) { | ||
return afterToken; | ||
@@ -94,3 +88,2 @@ } | ||
}; | ||
exports.findNonCodeVisibleTokenAfter = findNonCodeVisibleTokenAfter; | ||
/** | ||
@@ -102,7 +95,7 @@ * Find a certain token before, which: | ||
*/ | ||
const findVisibleTokenBefore = (group, token) => { | ||
export const findVisibleTokenBefore = (group, token) => { | ||
if (!token) { | ||
return; | ||
} | ||
const beforeToken = (0, exports.findTokenBefore)(group, token); | ||
const beforeToken = findTokenBefore(group, token); | ||
if (!beforeToken) { | ||
@@ -112,7 +105,7 @@ return; | ||
// hyper mark, html pairs: skip | ||
if ((0, parser_1.isInvisibleType)(beforeToken.type) || getHtmlTagSide(beforeToken)) { | ||
return (0, exports.findVisibleTokenBefore)(group, beforeToken); | ||
if (isInvisibleType(beforeToken.type) || getHtmlTagSide(beforeToken)) { | ||
return findVisibleTokenBefore(group, beforeToken); | ||
} | ||
// content, punctuation, bracket, group, code: return token | ||
if ((0, parser_1.isVisibleType)(beforeToken.type)) { | ||
if (isVisibleType(beforeToken.type)) { | ||
return beforeToken; | ||
@@ -123,3 +116,2 @@ } | ||
}; | ||
exports.findVisibleTokenBefore = findVisibleTokenBefore; | ||
/** | ||
@@ -131,7 +123,7 @@ * Find a certain token after, which: | ||
*/ | ||
const findVisibleTokenAfter = (group, token) => { | ||
export const findVisibleTokenAfter = (group, token) => { | ||
if (!token) { | ||
return; | ||
} | ||
const afterToken = (0, exports.findTokenAfter)(group, token); | ||
const afterToken = findTokenAfter(group, token); | ||
if (!afterToken) { | ||
@@ -141,7 +133,7 @@ return; | ||
// hyper mark, html pairs: skip | ||
if ((0, parser_1.isInvisibleType)(afterToken.type) || getHtmlTagSide(afterToken)) { | ||
return (0, exports.findVisibleTokenAfter)(group, afterToken); | ||
if (isInvisibleType(afterToken.type) || getHtmlTagSide(afterToken)) { | ||
return findVisibleTokenAfter(group, afterToken); | ||
} | ||
// content, punctuation, bracket, group, code: return token | ||
if ((0, parser_1.isVisibleType)(afterToken.type)) { | ||
if (isVisibleType(afterToken.type)) { | ||
return afterToken; | ||
@@ -152,6 +144,5 @@ } | ||
}; | ||
exports.findVisibleTokenAfter = findVisibleTokenAfter; | ||
// hyper mark seq | ||
const isHtmlTag = (token) => { | ||
if (token.type !== parser_1.HyperTokenType.HYPER_CONTENT) { | ||
if (token.type !== HyperTokenType.HYPER_CONTENT) { | ||
return false; | ||
@@ -172,14 +163,13 @@ } | ||
if (token.value.match(/^<[^/].+>$/)) { | ||
return parser_1.MarkSideType.LEFT; | ||
return MarkSideType.LEFT; | ||
} | ||
if (token.value.match(/^<\/.+>$/)) { | ||
return parser_1.MarkSideType.RIGHT; | ||
return MarkSideType.RIGHT; | ||
} | ||
}; | ||
const isWrapper = (token) => { | ||
return token.type === parser_1.HyperTokenType.HYPER_MARK || !!getHtmlTagSide(token); | ||
export const isWrapper = (token) => { | ||
return token.type === HyperTokenType.HYPER_MARK || !!getHtmlTagSide(token); | ||
}; | ||
exports.isWrapper = isWrapper; | ||
const getWrapperSide = (token) => { | ||
if (token.type === parser_1.HyperTokenType.HYPER_MARK) { | ||
export const getWrapperSide = (token) => { | ||
if (token.type === HyperTokenType.HYPER_MARK) { | ||
return token.markSide; | ||
@@ -189,7 +179,6 @@ } | ||
}; | ||
exports.getWrapperSide = getWrapperSide; | ||
const spreadHyperMarkSeq = (group, token, seq, isBackward) => { | ||
if (isBackward) { | ||
const tokenBefore = (0, exports.findTokenBefore)(group, token); | ||
if (tokenBefore && (0, exports.isWrapper)(tokenBefore)) { | ||
const tokenBefore = findTokenBefore(group, token); | ||
if (tokenBefore && isWrapper(tokenBefore)) { | ||
seq.unshift(tokenBefore); | ||
@@ -200,4 +189,4 @@ spreadHyperMarkSeq(group, tokenBefore, seq, isBackward); | ||
else { | ||
const tokenAfter = (0, exports.findTokenAfter)(group, token); | ||
if (tokenAfter && (0, exports.isWrapper)(tokenAfter)) { | ||
const tokenAfter = findTokenAfter(group, token); | ||
if (tokenAfter && isWrapper(tokenAfter)) { | ||
seq.push(tokenAfter); | ||
@@ -208,3 +197,3 @@ spreadHyperMarkSeq(group, tokenAfter, seq, isBackward); | ||
}; | ||
const findConnectedWrappers = (group, token) => { | ||
export const findConnectedWrappers = (group, token) => { | ||
const seq = [token]; | ||
@@ -215,3 +204,2 @@ spreadHyperMarkSeq(group, token, seq, false); | ||
}; | ||
exports.findConnectedWrappers = findConnectedWrappers; | ||
const findSpaceHostInHyperMarkSeq = (group, hyperMarkSeq) => { | ||
@@ -224,5 +212,5 @@ // Return nothing if the seq is empty | ||
const lastMark = hyperMarkSeq[hyperMarkSeq.length - 1]; | ||
const firstMarkSide = (0, exports.getWrapperSide)(firstMark); | ||
const lastMarkSide = (0, exports.getWrapperSide)(lastMark); | ||
const tokenBefore = (0, exports.findTokenBefore)(group, firstMark); | ||
const firstMarkSide = getWrapperSide(firstMark); | ||
const lastMarkSide = getWrapperSide(lastMark); | ||
const tokenBefore = findTokenBefore(group, firstMark); | ||
if (!tokenBefore) { | ||
@@ -239,3 +227,3 @@ return; | ||
if (firstMarkSide === lastMarkSide) { | ||
if (firstMarkSide === parser_1.MarkSideType.LEFT) { | ||
if (firstMarkSide === MarkSideType.LEFT) { | ||
return tokenBefore; | ||
@@ -249,3 +237,3 @@ } | ||
// We'd better do nothing and leave this issue to human. | ||
if (firstMarkSide === parser_1.MarkSideType.LEFT) { | ||
if (firstMarkSide === MarkSideType.LEFT) { | ||
return; | ||
@@ -258,4 +246,4 @@ } | ||
while (target && target !== lastMark) { | ||
const nextToken = (0, exports.findTokenAfter)(group, target); | ||
if (nextToken && (0, exports.getWrapperSide)(nextToken) === parser_1.MarkSideType.LEFT) { | ||
const nextToken = findTokenAfter(group, target); | ||
if (nextToken && getWrapperSide(nextToken) === MarkSideType.LEFT) { | ||
return target; | ||
@@ -267,3 +255,3 @@ } | ||
}; | ||
const findWrappersBetween = (group, before, after) => { | ||
export const findWrappersBetween = (group, before, after) => { | ||
if (!before || !after) { | ||
@@ -276,4 +264,4 @@ return { | ||
} | ||
const firstMark = (0, exports.findTokenAfter)(group, before); | ||
const firstVisible = (0, exports.findVisibleTokenAfter)(group, before); | ||
const firstMark = findTokenAfter(group, before); | ||
const firstVisible = findVisibleTokenAfter(group, before); | ||
if (!firstMark || firstVisible !== after) { | ||
@@ -293,3 +281,3 @@ return { | ||
} | ||
const markSeq = (0, exports.findConnectedWrappers)(group, firstMark); | ||
const markSeq = findConnectedWrappers(group, firstMark); | ||
const spaceHost = findSpaceHostInHyperMarkSeq(group, markSeq); | ||
@@ -302,12 +290,11 @@ return { | ||
}; | ||
exports.findWrappersBetween = findWrappersBetween; | ||
// special cases | ||
const isHalfwidthPunctuationWithoutSpaceAround = (group, token) => { | ||
const tokenBefore = (0, exports.findTokenBefore)(group, token); | ||
const tokenAfter = (0, exports.findTokenAfter)(group, token); | ||
if ((0, parser_1.isHalfwidthPunctuationType)(token.type) && | ||
export const isHalfwidthPunctuationWithoutSpaceAround = (group, token) => { | ||
const tokenBefore = findTokenBefore(group, token); | ||
const tokenAfter = findTokenAfter(group, token); | ||
if (isHalfwidthPunctuationType(token.type) && | ||
tokenBefore && | ||
tokenBefore.type === parser_1.CharType.WESTERN_LETTER && | ||
tokenBefore.type === CharType.WESTERN_LETTER && | ||
tokenAfter && | ||
tokenAfter.type === parser_1.CharType.WESTERN_LETTER) { | ||
tokenAfter.type === CharType.WESTERN_LETTER) { | ||
return !tokenBefore.spaceAfter && !token.spaceAfter; | ||
@@ -317,12 +304,11 @@ } | ||
}; | ||
exports.isHalfwidthPunctuationWithoutSpaceAround = isHalfwidthPunctuationWithoutSpaceAround; | ||
const isSuccessiveHalfwidthPunctuation = (group, token) => { | ||
if ((0, parser_1.isHalfwidthPunctuationType)(token.type)) { | ||
const tokenBefore = (0, exports.findTokenBefore)(group, token); | ||
const tokenAfter = (0, exports.findTokenAfter)(group, token); | ||
export const isSuccessiveHalfwidthPunctuation = (group, token) => { | ||
if (isHalfwidthPunctuationType(token.type)) { | ||
const tokenBefore = findTokenBefore(group, token); | ||
const tokenAfter = findTokenAfter(group, token); | ||
if ((tokenBefore && | ||
(0, parser_1.isHalfwidthPunctuationType)(tokenBefore.type) && | ||
isHalfwidthPunctuationType(tokenBefore.type) && | ||
!tokenBefore.spaceAfter) || | ||
(tokenAfter && | ||
(0, parser_1.isHalfwidthPunctuationType)(tokenAfter.type) && | ||
isHalfwidthPunctuationType(tokenAfter.type) && | ||
!token.spaceAfter)) { | ||
@@ -334,3 +320,2 @@ return true; | ||
}; | ||
exports.isSuccessiveHalfwidthPunctuation = isSuccessiveHalfwidthPunctuation; | ||
// validations helpers | ||
@@ -345,11 +330,11 @@ const createValidation = (token, target, message, name) => { | ||
}; | ||
if (target === report_1.ValidationTarget.START_VALUE) { | ||
if (target === ValidationTarget.START_VALUE) { | ||
validation.index = token.startIndex; | ||
validation.length = 0; | ||
} | ||
else if (target === report_1.ValidationTarget.END_VALUE) { | ||
else if (target === ValidationTarget.END_VALUE) { | ||
validation.index = token.endIndex; | ||
validation.length = 0; | ||
} | ||
else if (target === report_1.ValidationTarget.INNER_SPACE_BEFORE) { | ||
else if (target === ValidationTarget.INNER_SPACE_BEFORE) { | ||
validation.index = token.startIndex; | ||
@@ -360,16 +345,13 @@ validation.length = token.startValue.length; | ||
}; | ||
const setValidationOnTarget = (token, target, message, name) => { | ||
export const setValidationOnTarget = (token, target, message, name) => { | ||
const validation = createValidation(token, target, message, name); | ||
(0, exports.removeValidationOnTarget)(token, target); | ||
removeValidationOnTarget(token, target); | ||
token.validations.push(validation); | ||
}; | ||
exports.setValidationOnTarget = setValidationOnTarget; | ||
const hasValidationOnTarget = (token, target) => { | ||
export const hasValidationOnTarget = (token, target) => { | ||
return token.validations.some((validation) => validation.target === target); | ||
}; | ||
exports.hasValidationOnTarget = hasValidationOnTarget; | ||
const removeValidationOnTarget = (token, target) => { | ||
export const removeValidationOnTarget = (token, target) => { | ||
token.validations = token.validations.filter((validation) => validation.target !== target); | ||
}; | ||
exports.removeValidationOnTarget = removeValidationOnTarget; | ||
const genChecker = (key, target) => { | ||
@@ -379,11 +361,11 @@ return (token, value, message) => { | ||
token[key] = value; | ||
(0, exports.setValidationOnTarget)(token, target, message, ''); | ||
setValidationOnTarget(token, target, message, ''); | ||
} | ||
}; | ||
}; | ||
exports.checkSpaceAfter = genChecker('modifiedSpaceAfter', report_1.ValidationTarget.SPACE_AFTER); | ||
exports.checkStartValue = genChecker('modifiedStartValue', report_1.ValidationTarget.START_VALUE); | ||
exports.checkEndValue = genChecker('modifiedEndValue', report_1.ValidationTarget.END_VALUE); | ||
exports.checkInnerSpaceBefore = genChecker('modifiedInnerSpaceBefore', report_1.ValidationTarget.INNER_SPACE_BEFORE); | ||
const checkValue = (token, value, type, message) => { | ||
export const checkSpaceAfter = genChecker('modifiedSpaceAfter', ValidationTarget.SPACE_AFTER); | ||
export const checkStartValue = genChecker('modifiedStartValue', ValidationTarget.START_VALUE); | ||
export const checkEndValue = genChecker('modifiedEndValue', ValidationTarget.END_VALUE); | ||
export const checkInnerSpaceBefore = genChecker('modifiedInnerSpaceBefore', ValidationTarget.INNER_SPACE_BEFORE); | ||
export const checkValue = (token, value, type, message) => { | ||
if (token.modifiedValue === value) { | ||
@@ -396,4 +378,3 @@ return; | ||
} | ||
(0, exports.setValidationOnTarget)(token, report_1.ValidationTarget.VALUE, message, ''); | ||
setValidationOnTarget(token, ValidationTarget.VALUE, message, ''); | ||
}; | ||
exports.checkValue = checkValue; |
@@ -1,23 +0,15 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runWithConfig = exports.run = void 0; | ||
const options_1 = require("./options"); | ||
const parser_1 = require("./parser"); | ||
const rules_1 = __importDefault(require("./rules")); | ||
const ignore_1 = __importDefault(require("./ignore")); | ||
const join_1 = __importDefault(require("./join")); | ||
const replace_block_1 = __importDefault(require("./replace-block")); | ||
const run = (str, options = {}) => { | ||
const normalizedOptions = (0, options_1.normalizeOptions)(options); | ||
import { normalizeOptions, normalizeConfig } from './options'; | ||
import { parse, toMutableResult, travel } from './parser'; | ||
import generateHandlers from './rules'; | ||
import findIgnoredMarks from './ignore'; | ||
import join from './join'; | ||
import replaceBlocks from './replace-block'; | ||
export const run = (str, options = {}) => { | ||
const normalizedOptions = normalizeOptions(options); | ||
return lint(str, normalizedOptions); | ||
}; | ||
exports.run = run; | ||
const runWithConfig = (str, config) => { | ||
const normalizedOptions = (0, options_1.normalizeConfig)(config); | ||
export const runWithConfig = (str, config) => { | ||
const normalizedOptions = normalizeConfig(config); | ||
return lint(str, normalizedOptions); | ||
}; | ||
exports.runWithConfig = runWithConfig; | ||
const lint = (str, normalizedOptions) => { | ||
@@ -58,3 +50,3 @@ // return if the file is totally ignored | ||
// 5. Replace each block back to the string | ||
const ruleHandlers = (0, rules_1.default)(rules); | ||
const ruleHandlers = generateHandlers(rules); | ||
const modifiedBlocks = parsedStatus.blocks.map(({ value, marks, start, end }) => { | ||
@@ -66,9 +58,9 @@ let lastValue = value; | ||
} | ||
const result = (0, parser_1.toMutableResult)((0, parser_1.parse)(value, marks), rules); | ||
const result = toMutableResult(parse(value, marks), rules); | ||
parserErrors.push(...result.errors); | ||
const ignoredMarks = (0, ignore_1.default)(value, status.ignoredByRules, logger); | ||
const ignoredMarks = findIgnoredMarks(value, status.ignoredByRules, logger); | ||
ruleHandlers.forEach((rule) => { | ||
(0, parser_1.travel)(result.tokens, rule); | ||
travel(result.tokens, rule); | ||
if (globalThis.__DEV__) { | ||
const currentValue = (0, join_1.default)(result.tokens, start, ignoredMarks, [], [], []); | ||
const currentValue = join(result.tokens, start, ignoredMarks, [], [], []); | ||
if (lastValue !== currentValue) { | ||
@@ -81,3 +73,3 @@ logger.log(`[After process by ${rule.name}]`); | ||
}); | ||
lastValue = (0, join_1.default)(result.tokens, start, ignoredMarks, ignoredTokens, ruleErrors, ignoredRuleErrors); | ||
lastValue = join(result.tokens, start, ignoredMarks, ignoredTokens, ruleErrors, ignoredRuleErrors); | ||
if (globalThis.__DEV__) { | ||
@@ -90,3 +82,3 @@ logger.log('[Eventual block value]'); | ||
}); | ||
const result = (0, replace_block_1.default)(str, modifiedBlocks); | ||
const result = replaceBlocks(str, modifiedBlocks); | ||
const debugInfo = { | ||
@@ -109,2 +101,2 @@ pieces: result.pieces, | ||
}; | ||
exports.default = exports.run; | ||
export default run; |
{ | ||
"name": "zhlint", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"description": "A linting tool for Chinese language.", | ||
@@ -8,2 +8,3 @@ "bin": { | ||
}, | ||
"type": "module", | ||
"main": "./lib/index.js", | ||
@@ -38,31 +39,32 @@ "unpkg": "./dist/zhlint.umd.js", | ||
"devDependencies": { | ||
"@types/mdast": "^3.0.15", | ||
"@types/node": "^20.11.5", | ||
"@types/react": "^17.0.75", | ||
"@types/unist": "^2.0.10", | ||
"@typescript-eslint/eslint-plugin": "^6.19.0", | ||
"@typescript-eslint/parser": "^6.19.0", | ||
"@vitest/ui": "^1.2.1", | ||
"@types/mdast": "^4.0.3", | ||
"@types/node": "^20.11.17", | ||
"@types/unist": "^3.0.2", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
"@vitest/ui": "^1.2.2", | ||
"eslint": "^8.56.0", | ||
"mdast-util-to-markdown": "^1.5.0", | ||
"mdast-util-to-markdown": "^2.1.0", | ||
"node-stdlib-browser": "^1.2.0", | ||
"prettier": "^3.2.4", | ||
"prettier": "^3.2.5", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12", | ||
"vite": "^5.1.1", | ||
"vite-plugin-node-polyfills": "^0.19.0", | ||
"vitepress": "1.0.0-rc.39" | ||
"vitepress": "1.0.0-rc.39", | ||
"vitest": "^1.2.2" | ||
}, | ||
"dependencies": { | ||
"chalk": "^4.0.0", | ||
"chalk": "^3.0.0", | ||
"glob": "^10.3.10", | ||
"ignore": "^5.3.0", | ||
"ignore": "^5.3.1", | ||
"minimist": "^1.2.8", | ||
"remark-frontmatter": "^1.3.3", | ||
"remark-parse": "^7.0.2", | ||
"unified": "^8.4.2", | ||
"vitest": "^1.2.1", | ||
"vue": "^3.4.15" | ||
"remark-custom-container": "^1.3.1", | ||
"remark-frontmatter": "^4.0.1", | ||
"remark-gfm": "^3.0.1", | ||
"remark-parse": "^10.0.0", | ||
"unified": "^10.0.0" | ||
}, | ||
"scripts": { | ||
"dev": "vitest", | ||
"debug": "vitest debug.test.ts", | ||
"dev:ui": "vitest --ui", | ||
@@ -85,4 +87,5 @@ "build": "pnpm run build:node && pnpm run build:browser", | ||
"docs:serve": "vitepress serve docs", | ||
"docs:deploy": "./deploy.sh" | ||
"docs:deploy": "./deploy.sh", | ||
"prepublish": "pnpm run build && pnpm run docs:runtime && pnpm run docs:readme" | ||
} | ||
} |
@@ -147,14 +147,14 @@ # ![logo](docs/logo.svg) zhlint | ||
- `run(str: string, options?: Options): Result`: Lint a certain content. | ||
- parameters: | ||
- `str`: The text content you want to lint. | ||
- `options`: Some options to config. | ||
- returns: | ||
- The result of a single piece of input string. It contains fixed text content as `value` and the infor of all `validations`. | ||
- `report(results: Result[], logger?: Console): void`: Print out the validation reports for each file. | ||
- parameters: | ||
- `results`: An array for all linted results. | ||
- `logger`: The logger instance, by default it's `console` in Node.js/browser. | ||
- `readRc: (dir: string, config: string, fileIgnore: string, caseIgnore: string, logger?: Console) => Config`: Read config from rc & ignore file(s). | ||
- `runWithConfig(str: string, config: Config): Result`: Lint a certain content with rc config. | ||
- `run(str: string, options?: Options): Result`: Lint a certain content. | ||
- parameters: | ||
- `str`: The text content you want to lint. | ||
- `options`: Some options to config. | ||
- returns: | ||
- The result of a single piece of input string. It contains fixed text content as `value` and the infor of all `validations`. | ||
- `report(results: Result[], logger?: Console): void`: Print out the validation reports for each file. | ||
- parameters: | ||
- `results`: An array for all linted results. | ||
- `logger`: The logger instance, by default it's `console` in Node.js/browser. | ||
- `readRc: (dir: string, config: string, fileIgnore: string, caseIgnore: string, logger?: Console) => Config`: Read config from rc & ignore file(s). | ||
- `runWithConfig(str: string, config: Config): Result`: Lint a certain content with rc config. | ||
@@ -174,15 +174,15 @@ ### Options | ||
- `rules`: customize the linting config. It could be `undefined` which means linting nothing. It could be `{ preset: 'default' }` which just uses the default config. For more details of `RuleOptions`, please see [supported rules](#supported-rules) | ||
- `hyperParse`: customize the hyper parser by their names. It could be `undefined` which means just use default [ignored cases parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/ignore.js), [Markdown parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/md.js) and the [Hexo tags parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/hexo.js). | ||
- `ignoredCases`: provide exception cases which you would like to skip. | ||
- `IgnoredCase`: `{ prefix?, textStart, textEnd?, suffix? }` | ||
- Just follows a certain format `[prefix-,]textStart[,textEnd][,-suffix]` inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment). | ||
- `logger`: same to the parameter in `report(...)`. | ||
- `rules`: customize the linting config. It could be `undefined` which means linting nothing. It could be `{ preset: 'default' }` which just uses the default config. For more details of `RuleOptions`, please see [supported rules](#supported-rules) | ||
- `hyperParse`: customize the hyper parser by their names. It could be `undefined` which means just use default [ignored cases parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/ignore.js), [Markdown parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/md.js) and the [Hexo tags parser](https://github.com/zhlint-project/zhlint/tree/master/src/hypers/hexo.js). | ||
- `ignoredCases`: provide exception cases which you would like to skip. | ||
- `IgnoredCase`: `{ prefix?, textStart, textEnd?, suffix? }` | ||
- Just follows a certain format `[prefix-,]textStart[,textEnd][,-suffix]` inspired from [W3C Scroll To Text Fragment Proposal](https://github.com/WICG/ScrollToTextFragment). | ||
- `logger`: same to the parameter in `report(...)`. | ||
### RC Config | ||
- `preset`: `string` (optional) | ||
- `rules`: `RuleOptions` without the `preset` field. (optional) | ||
- `hyperParsers`: `string[]` (optional) | ||
- `caseIgnores`: `string[]` and the priority is lower than `.zhlintcaseignore`. (optional) | ||
- `preset`: `string` (optional) | ||
- `rules`: `RuleOptions` without the `preset` field. (optional) | ||
- `hyperParsers`: `string[]` (optional) | ||
- `caseIgnores`: `string[]` and the priority is lower than `.zhlintcaseignore`. (optional) | ||
@@ -211,11 +211,11 @@ ### Output | ||
- `Result` | ||
- `file`: The file name. It's an optional field which is only used in CLI. | ||
- `origin`: the original text content. | ||
- `result`: the finally fixed text content. | ||
- `validations`: All the validation information. | ||
- `Validation` | ||
- `index`: The index of the target token in the input string. | ||
- `length`: The length of the target token in the input string. | ||
- `message`: The description of this validation in natural language. | ||
- `Result` | ||
- `file`: The file name. It's an optional field which is only used in CLI. | ||
- `origin`: the original text content. | ||
- `result`: the finally fixed text content. | ||
- `validations`: All the validation information. | ||
- `Validation` | ||
- `index`: The index of the target token in the input string. | ||
- `length`: The length of the target token in the input string. | ||
- `message`: The description of this validation in natural language. | ||
@@ -278,5 +278,5 @@ ## Features | ||
- `ignore`: find all ignored pieces by the HTML comment `<!-- zhlint ignore: ... -->` | ||
- `hexo`: find all Hexo tags to avoid them being parsed. | ||
- `markdown`: parse by markdown syntax and find all block-level texts and inline-level marks. | ||
- `ignore`: find all ignored pieces by the HTML comment `<!-- zhlint ignore: ... -->` | ||
- `hexo`: find all Hexo tags to avoid them being parsed. | ||
- `markdown`: parse by markdown syntax and find all block-level texts and inline-level marks. | ||
@@ -353,3 +353,6 @@ ## Supported rules | ||
// ``` | ||
unifiedPunctuation?: 'traditional' | 'simplified' | Record<string, boolean | string[]> & { default: boolean } | ||
unifiedPunctuation?: | ||
| 'traditional' | ||
| 'simplified' | ||
| (Record<string, boolean | string[]> & { default: boolean }) | ||
@@ -356,0 +359,0 @@ // Special case: skip `fullWidthPunctuation` for abbreviations. |
@@ -5,3 +5,4 @@ { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"module": "ES6", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
@@ -8,0 +9,0 @@ "strictNullChecks": true, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2933733
13583
482
Yes
+ Addedremark-gfm@^3.0.1
+ Added@types/debug@4.1.12(transitive)
+ Added@types/mdast@3.0.15(transitive)
+ Added@types/ms@0.7.34(transitive)
+ Addedbail@2.0.2(transitive)
+ Addedccount@2.0.1(transitive)
+ Addedchalk@3.0.0(transitive)
+ Addedcharacter-entities@2.0.2(transitive)
+ Addeddecode-named-character-reference@1.0.2(transitive)
+ Addeddequal@2.0.3(transitive)
+ Addeddiff@5.2.0(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedfault@2.0.1(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addedkleur@4.1.5(transitive)
+ Addedlongest-streak@3.1.0(transitive)
+ Addedmarkdown-table@3.0.4(transitive)
+ Addedmdast-util-find-and-replace@2.2.2(transitive)
+ Addedmdast-util-from-markdown@1.3.1(transitive)
+ Addedmdast-util-frontmatter@1.0.1(transitive)
+ Addedmdast-util-gfm@2.0.2(transitive)
+ Addedmdast-util-gfm-autolink-literal@1.0.3(transitive)
+ Addedmdast-util-gfm-footnote@1.0.2(transitive)
+ Addedmdast-util-gfm-strikethrough@1.0.3(transitive)
+ Addedmdast-util-gfm-table@1.0.7(transitive)
+ Addedmdast-util-gfm-task-list-item@1.0.2(transitive)
+ Addedmdast-util-phrasing@3.0.1(transitive)
+ Addedmdast-util-to-markdown@1.5.0(transitive)
+ Addedmdast-util-to-string@3.2.0(transitive)
+ Addedmicromark@3.2.0(transitive)
+ Addedmicromark-core-commonmark@1.1.0(transitive)
+ Addedmicromark-extension-frontmatter@1.1.1(transitive)
+ Addedmicromark-extension-gfm@2.0.3(transitive)
+ Addedmicromark-extension-gfm-autolink-literal@1.0.5(transitive)
+ Addedmicromark-extension-gfm-footnote@1.1.2(transitive)
+ Addedmicromark-extension-gfm-strikethrough@1.0.7(transitive)
+ Addedmicromark-extension-gfm-table@1.0.7(transitive)
+ Addedmicromark-extension-gfm-tagfilter@1.0.2(transitive)
+ Addedmicromark-extension-gfm-task-list-item@1.0.5(transitive)
+ Addedmicromark-factory-destination@1.1.0(transitive)
+ Addedmicromark-factory-label@1.1.0(transitive)
+ Addedmicromark-factory-space@1.1.0(transitive)
+ Addedmicromark-factory-title@1.1.0(transitive)
+ Addedmicromark-factory-whitespace@1.1.0(transitive)
+ Addedmicromark-util-character@1.2.0(transitive)
+ Addedmicromark-util-chunked@1.1.0(transitive)
+ Addedmicromark-util-classify-character@1.1.0(transitive)
+ Addedmicromark-util-combine-extensions@1.1.0(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
+ Addedmicromark-util-decode-string@1.1.0(transitive)
+ Addedmicromark-util-encode@1.1.0(transitive)
+ Addedmicromark-util-html-tag-name@1.2.0(transitive)
+ Addedmicromark-util-normalize-identifier@1.1.0(transitive)
+ Addedmicromark-util-resolve-all@1.1.0(transitive)
+ Addedmicromark-util-sanitize-uri@1.2.0(transitive)
+ Addedmicromark-util-subtokenize@1.1.0(transitive)
+ Addedmicromark-util-symbol@1.1.0(transitive)
+ Addedmicromark-util-types@1.1.0(transitive)
+ Addedmri@1.2.0(transitive)
+ Addedremark-custom-container@1.3.1(transitive)
+ Addedremark-frontmatter@4.0.1(transitive)
+ Addedremark-gfm@3.0.1(transitive)
+ Addedremark-parse@10.0.2(transitive)
+ Addedsade@1.8.1(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
+ Addeduvu@0.5.6(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-message@3.1.4(transitive)
+ Addedzwitch@2.0.4(transitive)
- Removedvitest@^1.2.1
- Removedvue@^3.4.15
- Removed@babel/helper-string-parser@7.25.9(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@babel/parser@7.26.5(transitive)
- Removed@babel/types@7.26.5(transitive)
- Removed@esbuild/aix-ppc64@0.21.5(transitive)
- Removed@esbuild/android-arm@0.21.5(transitive)
- Removed@esbuild/android-arm64@0.21.5(transitive)
- Removed@esbuild/android-x64@0.21.5(transitive)
- Removed@esbuild/darwin-arm64@0.21.5(transitive)
- Removed@esbuild/darwin-x64@0.21.5(transitive)
- Removed@esbuild/freebsd-arm64@0.21.5(transitive)
- Removed@esbuild/freebsd-x64@0.21.5(transitive)
- Removed@esbuild/linux-arm@0.21.5(transitive)
- Removed@esbuild/linux-arm64@0.21.5(transitive)
- Removed@esbuild/linux-ia32@0.21.5(transitive)
- Removed@esbuild/linux-loong64@0.21.5(transitive)
- Removed@esbuild/linux-mips64el@0.21.5(transitive)
- Removed@esbuild/linux-ppc64@0.21.5(transitive)
- Removed@esbuild/linux-riscv64@0.21.5(transitive)
- Removed@esbuild/linux-s390x@0.21.5(transitive)
- Removed@esbuild/linux-x64@0.21.5(transitive)
- Removed@esbuild/netbsd-x64@0.21.5(transitive)
- Removed@esbuild/openbsd-x64@0.21.5(transitive)
- Removed@esbuild/sunos-x64@0.21.5(transitive)
- Removed@esbuild/win32-arm64@0.21.5(transitive)
- Removed@esbuild/win32-ia32@0.21.5(transitive)
- Removed@esbuild/win32-x64@0.21.5(transitive)
- Removed@jest/schemas@29.6.3(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@rollup/rollup-android-arm-eabi@4.30.1(transitive)
- Removed@rollup/rollup-android-arm64@4.30.1(transitive)
- Removed@rollup/rollup-darwin-arm64@4.30.1(transitive)
- Removed@rollup/rollup-darwin-x64@4.30.1(transitive)
- Removed@rollup/rollup-freebsd-arm64@4.30.1(transitive)
- Removed@rollup/rollup-freebsd-x64@4.30.1(transitive)
- Removed@rollup/rollup-linux-arm-gnueabihf@4.30.1(transitive)
- Removed@rollup/rollup-linux-arm-musleabihf@4.30.1(transitive)
- Removed@rollup/rollup-linux-arm64-gnu@4.30.1(transitive)
- Removed@rollup/rollup-linux-arm64-musl@4.30.1(transitive)
- Removed@rollup/rollup-linux-loongarch64-gnu@4.30.1(transitive)
- Removed@rollup/rollup-linux-powerpc64le-gnu@4.30.1(transitive)
- Removed@rollup/rollup-linux-riscv64-gnu@4.30.1(transitive)
- Removed@rollup/rollup-linux-s390x-gnu@4.30.1(transitive)
- Removed@rollup/rollup-linux-x64-gnu@4.30.1(transitive)
- Removed@rollup/rollup-linux-x64-musl@4.30.1(transitive)
- Removed@rollup/rollup-win32-arm64-msvc@4.30.1(transitive)
- Removed@rollup/rollup-win32-ia32-msvc@4.30.1(transitive)
- Removed@rollup/rollup-win32-x64-msvc@4.30.1(transitive)
- Removed@sinclair/typebox@0.27.8(transitive)
- Removed@types/estree@1.0.6(transitive)
- Removed@vitest/expect@1.6.0(transitive)
- Removed@vitest/runner@1.6.0(transitive)
- Removed@vitest/snapshot@1.6.0(transitive)
- Removed@vitest/spy@1.6.0(transitive)
- Removed@vitest/utils@1.6.0(transitive)
- Removed@vue/compiler-core@3.5.13(transitive)
- Removed@vue/compiler-dom@3.5.13(transitive)
- Removed@vue/compiler-sfc@3.5.13(transitive)
- Removed@vue/compiler-ssr@3.5.13(transitive)
- Removed@vue/reactivity@3.5.13(transitive)
- Removed@vue/runtime-core@3.5.13(transitive)
- Removed@vue/runtime-dom@3.5.13(transitive)
- Removed@vue/server-renderer@3.5.13(transitive)
- Removed@vue/shared@3.5.13(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedansi-styles@5.2.0(transitive)
- Removedassertion-error@1.1.0(transitive)
- Removedbail@1.0.5(transitive)
- Removedcac@6.7.14(transitive)
- Removedchai@4.5.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcharacter-entities@1.2.4(transitive)
- Removedcharacter-entities-legacy@1.1.4(transitive)
- Removedcharacter-reference-invalid@1.1.4(transitive)
- Removedcheck-error@1.0.3(transitive)
- Removedcollapse-white-space@1.0.6(transitive)
- Removedconfbox@0.1.8(transitive)
- Removedcsstype@3.1.3(transitive)
- Removeddeep-eql@4.1.4(transitive)
- Removeddiff-sequences@29.6.3(transitive)
- Removedentities@4.5.0(transitive)
- Removedesbuild@0.21.5(transitive)
- Removedestree-walker@2.0.23.0.3(transitive)
- Removedexeca@8.0.1(transitive)
- Removedfault@1.0.4(transitive)
- Removedfsevents@2.3.3(transitive)
- Removedget-func-name@2.0.2(transitive)
- Removedget-stream@8.0.1(transitive)
- Removedhuman-signals@5.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-alphabetical@1.0.4(transitive)
- Removedis-alphanumerical@1.0.4(transitive)
- Removedis-decimal@1.0.4(transitive)
- Removedis-hexadecimal@1.0.4(transitive)
- Removedis-plain-obj@2.1.0(transitive)
- Removedis-stream@3.0.0(transitive)
- Removedis-whitespace-character@1.0.4(transitive)
- Removedis-word-character@1.0.4(transitive)
- Removedjs-tokens@9.0.1(transitive)
- Removedlocal-pkg@0.5.1(transitive)
- Removedloupe@2.3.7(transitive)
- Removedmagic-string@0.30.17(transitive)
- Removedmarkdown-escapes@1.0.4(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmimic-fn@4.0.0(transitive)
- Removedmlly@1.7.3(transitive)
- Removednanoid@3.3.8(transitive)
- Removednpm-run-path@5.3.0(transitive)
- Removedonetime@6.0.0(transitive)
- Removedp-limit@5.0.0(transitive)
- Removedparse-entities@1.2.2(transitive)
- Removedpath-key@4.0.0(transitive)
- Removedpathe@1.1.2(transitive)
- Removedpathval@1.1.1(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedpkg-types@1.3.0(transitive)
- Removedpostcss@8.4.49(transitive)
- Removedpretty-format@29.7.0(transitive)
- Removedreact-is@18.3.1(transitive)
- Removedremark-frontmatter@1.3.3(transitive)
- Removedremark-parse@7.0.2(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedrollup@4.30.1(transitive)
- Removedsiginfo@2.0.0(transitive)
- Removedsource-map-js@1.2.1(transitive)
- Removedstackback@0.0.2(transitive)
- Removedstate-toggle@1.0.3(transitive)
- Removedstd-env@3.8.0(transitive)
- Removedstrip-final-newline@3.0.0(transitive)
- Removedstrip-literal@2.1.1(transitive)
- Removedtinybench@2.9.0(transitive)
- Removedtinypool@0.8.4(transitive)
- Removedtinyspy@2.2.1(transitive)
- Removedtrim@0.0.1(transitive)
- Removedtrim-trailing-lines@1.1.4(transitive)
- Removedtrough@1.0.5(transitive)
- Removedtype-detect@4.1.0(transitive)
- Removedufo@1.5.4(transitive)
- Removedunherit@1.1.3(transitive)
- Removedunified@8.4.2(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-remove-position@1.1.4(transitive)
- Removedunist-util-stringify-position@2.0.3(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
- Removedvfile@4.2.1(transitive)
- Removedvfile-location@2.0.6(transitive)
- Removedvfile-message@2.0.4(transitive)
- Removedvite@5.4.11(transitive)
- Removedvite-node@1.6.0(transitive)
- Removedvitest@1.6.0(transitive)
- Removedvue@3.5.13(transitive)
- Removedwhy-is-node-running@2.3.0(transitive)
- Removedxtend@4.0.2(transitive)
- Removedyocto-queue@1.1.1(transitive)
Updatedchalk@^3.0.0
Updatedignore@^5.3.1
Updatedremark-frontmatter@^4.0.1
Updatedremark-parse@^10.0.0
Updatedunified@^10.0.0