@stll/stdnum 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_util/clean.d.ts +6 -1
- package/dist/_util/clean.js +7 -2
- package/dist/_util/clean.js.map +1 -1
- package/package.json +1 -1
- package/src/_util/clean.ts +7 -2
package/dist/_util/clean.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
//#region src/_util/clean.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Normalize Unicode artifacts to ASCII
|
|
4
|
-
* equivalents
|
|
4
|
+
* equivalents, strip the given characters, and
|
|
5
|
+
* remove surrounding whitespace.
|
|
6
|
+
*
|
|
7
|
+
* The trailing trim removes whitespace outside the
|
|
8
|
+
* separator set (newlines, tabs) so validators
|
|
9
|
+
* accept copy-pasted input.
|
|
5
10
|
*
|
|
6
11
|
* @param value - The input string
|
|
7
12
|
* @param strip - Characters to remove
|
package/dist/_util/clean.js
CHANGED
|
@@ -54,7 +54,12 @@ const CHAR_MAP = {
|
|
|
54
54
|
const CHAR_REGEX = new RegExp(`[${Object.keys(CHAR_MAP).join("")}]`, "g");
|
|
55
55
|
/**
|
|
56
56
|
* Normalize Unicode artifacts to ASCII
|
|
57
|
-
* equivalents
|
|
57
|
+
* equivalents, strip the given characters, and
|
|
58
|
+
* remove surrounding whitespace.
|
|
59
|
+
*
|
|
60
|
+
* The trailing trim removes whitespace outside the
|
|
61
|
+
* separator set (newlines, tabs) so validators
|
|
62
|
+
* accept copy-pasted input.
|
|
58
63
|
*
|
|
59
64
|
* @param value - The input string
|
|
60
65
|
* @param strip - Characters to remove
|
|
@@ -63,7 +68,7 @@ const CHAR_REGEX = new RegExp(`[${Object.keys(CHAR_MAP).join("")}]`, "g");
|
|
|
63
68
|
const clean = (value, strip = "") => {
|
|
64
69
|
let result = value.replace(CHAR_REGEX, (ch) => CHAR_MAP[ch] ?? ch);
|
|
65
70
|
if (strip) for (const ch of strip) result = result.replaceAll(ch, "");
|
|
66
|
-
return result;
|
|
71
|
+
return result.trim();
|
|
67
72
|
};
|
|
68
73
|
//#endregion
|
|
69
74
|
export { clean };
|
package/dist/_util/clean.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.js","names":[],"sources":["../../src/_util/clean.ts"],"sourcesContent":["/**\n * Unicode normalization map for common OCR, PDF\n * extraction, and copy-paste artifacts.\n *\n * Maps fullwidth digits, various dashes, dots,\n * spaces, and quotes to their ASCII equivalents.\n * Ported from python-stdnum's util.py _char_map.\n */\nconst CHAR_MAP: Record<string, string> = {\n // Fullwidth digits\n \"\\uFF10\": \"0\",\n \"\\uFF11\": \"1\",\n \"\\uFF12\": \"2\",\n \"\\uFF13\": \"3\",\n \"\\uFF14\": \"4\",\n \"\\uFF15\": \"5\",\n \"\\uFF16\": \"6\",\n \"\\uFF17\": \"7\",\n \"\\uFF18\": \"8\",\n \"\\uFF19\": \"9\",\n // Dashes and hyphens\n \"\\u2010\": \"-\", // hyphen\n \"\\u2011\": \"-\", // non-breaking hyphen\n \"\\u2012\": \"-\", // figure dash\n \"\\u2013\": \"-\", // en dash\n \"\\u2014\": \"-\", // em dash\n \"\\u2015\": \"-\", // horizontal bar\n \"\\u2212\": \"-\", // minus sign\n \"\\uFE58\": \"-\", // small em dash\n \"\\uFE63\": \"-\", // small hyphen-minus\n \"\\uFF0D\": \"-\", // fullwidth hyphen-minus\n // Dots and periods\n \"\\u2024\": \".\", // one dot leader\n \"\\uFE52\": \".\", // small full stop\n \"\\uFF0E\": \".\", // fullwidth full stop\n // Spaces\n \"\\u00A0\": \" \", // non-breaking space\n \"\\u2000\": \" \", // en quad\n \"\\u2001\": \" \", // em quad\n \"\\u2002\": \" \", // en space\n \"\\u2003\": \" \", // em space\n \"\\u2004\": \" \", // three-per-em space\n \"\\u2005\": \" \", // four-per-em space\n \"\\u2006\": \" \", // six-per-em space\n \"\\u2007\": \" \", // figure space\n \"\\u2008\": \" \", // punctuation space\n \"\\u2009\": \" \", // thin space\n \"\\u200A\": \" \", // hair space\n \"\\u200B\": \"\", // zero-width space (remove)\n \"\\u202F\": \" \", // narrow no-break space\n \"\\u205F\": \" \", // medium mathematical space\n \"\\u3000\": \" \", // ideographic space\n \"\\uFEFF\": \"\", // BOM / zero-width no-break\n // Slashes\n \"\\uFF0F\": \"/\", // fullwidth solidus\n \"\\u2044\": \"/\", // fraction slash\n};\n\nconst CHAR_REGEX = new RegExp(\n `[${Object.keys(CHAR_MAP).join(\"\")}]`,\n \"g\",\n);\n\n/**\n * Normalize Unicode artifacts to ASCII\n * equivalents
|
|
1
|
+
{"version":3,"file":"clean.js","names":[],"sources":["../../src/_util/clean.ts"],"sourcesContent":["/**\n * Unicode normalization map for common OCR, PDF\n * extraction, and copy-paste artifacts.\n *\n * Maps fullwidth digits, various dashes, dots,\n * spaces, and quotes to their ASCII equivalents.\n * Ported from python-stdnum's util.py _char_map.\n */\nconst CHAR_MAP: Record<string, string> = {\n // Fullwidth digits\n \"\\uFF10\": \"0\",\n \"\\uFF11\": \"1\",\n \"\\uFF12\": \"2\",\n \"\\uFF13\": \"3\",\n \"\\uFF14\": \"4\",\n \"\\uFF15\": \"5\",\n \"\\uFF16\": \"6\",\n \"\\uFF17\": \"7\",\n \"\\uFF18\": \"8\",\n \"\\uFF19\": \"9\",\n // Dashes and hyphens\n \"\\u2010\": \"-\", // hyphen\n \"\\u2011\": \"-\", // non-breaking hyphen\n \"\\u2012\": \"-\", // figure dash\n \"\\u2013\": \"-\", // en dash\n \"\\u2014\": \"-\", // em dash\n \"\\u2015\": \"-\", // horizontal bar\n \"\\u2212\": \"-\", // minus sign\n \"\\uFE58\": \"-\", // small em dash\n \"\\uFE63\": \"-\", // small hyphen-minus\n \"\\uFF0D\": \"-\", // fullwidth hyphen-minus\n // Dots and periods\n \"\\u2024\": \".\", // one dot leader\n \"\\uFE52\": \".\", // small full stop\n \"\\uFF0E\": \".\", // fullwidth full stop\n // Spaces\n \"\\u00A0\": \" \", // non-breaking space\n \"\\u2000\": \" \", // en quad\n \"\\u2001\": \" \", // em quad\n \"\\u2002\": \" \", // en space\n \"\\u2003\": \" \", // em space\n \"\\u2004\": \" \", // three-per-em space\n \"\\u2005\": \" \", // four-per-em space\n \"\\u2006\": \" \", // six-per-em space\n \"\\u2007\": \" \", // figure space\n \"\\u2008\": \" \", // punctuation space\n \"\\u2009\": \" \", // thin space\n \"\\u200A\": \" \", // hair space\n \"\\u200B\": \"\", // zero-width space (remove)\n \"\\u202F\": \" \", // narrow no-break space\n \"\\u205F\": \" \", // medium mathematical space\n \"\\u3000\": \" \", // ideographic space\n \"\\uFEFF\": \"\", // BOM / zero-width no-break\n // Slashes\n \"\\uFF0F\": \"/\", // fullwidth solidus\n \"\\u2044\": \"/\", // fraction slash\n};\n\nconst CHAR_REGEX = new RegExp(\n `[${Object.keys(CHAR_MAP).join(\"\")}]`,\n \"g\",\n);\n\n/**\n * Normalize Unicode artifacts to ASCII\n * equivalents, strip the given characters, and\n * remove surrounding whitespace.\n *\n * The trailing trim removes whitespace outside the\n * separator set (newlines, tabs) so validators\n * accept copy-pasted input.\n *\n * @param value - The input string\n * @param strip - Characters to remove\n * (e.g. \" -/\" to strip spaces, dashes, slashes)\n */\nexport const clean = (\n value: string,\n strip: string = \"\",\n): string => {\n let result = value.replace(\n CHAR_REGEX,\n (ch) => CHAR_MAP[ch] ?? ch,\n );\n if (strip) {\n for (const ch of strip) {\n result = result.replaceAll(ch, \"\");\n }\n }\n return result.trim();\n};\n"],"mappings":";;;;;;;;;AAQA,MAAM,WAAmC;CAEvC,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CAEV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CAEV,KAAU;CACV,KAAU;CACV,KAAU;CAEV,QAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CACV,KAAU;CAEV,KAAU;CACV,KAAU;AACZ;AAEA,MAAM,aAAa,IAAI,OACrB,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,IACnC,GACF;;;;;;;;;;;;;;AAeA,MAAa,SACX,OACA,QAAgB,OACL;CACX,IAAI,SAAS,MAAM,QACjB,aACC,OAAO,SAAS,OAAO,EAC1B;CACA,IAAI,OACF,KAAK,MAAM,MAAM,OACf,SAAS,OAAO,WAAW,IAAI,EAAE;CAGrC,OAAO,OAAO,KAAK;AACrB"}
|
package/package.json
CHANGED
package/src/_util/clean.ts
CHANGED
|
@@ -63,7 +63,12 @@ const CHAR_REGEX = new RegExp(
|
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Normalize Unicode artifacts to ASCII
|
|
66
|
-
* equivalents
|
|
66
|
+
* equivalents, strip the given characters, and
|
|
67
|
+
* remove surrounding whitespace.
|
|
68
|
+
*
|
|
69
|
+
* The trailing trim removes whitespace outside the
|
|
70
|
+
* separator set (newlines, tabs) so validators
|
|
71
|
+
* accept copy-pasted input.
|
|
67
72
|
*
|
|
68
73
|
* @param value - The input string
|
|
69
74
|
* @param strip - Characters to remove
|
|
@@ -82,5 +87,5 @@ export const clean = (
|
|
|
82
87
|
result = result.replaceAll(ch, "");
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
|
-
return result;
|
|
90
|
+
return result.trim();
|
|
86
91
|
};
|