aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.mjs')
-rw-r--r--src/utils.mjs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils.mjs b/src/utils.mjs
index dbb3881..d2c5d8f 100644
--- a/src/utils.mjs
+++ b/src/utils.mjs
@@ -235,3 +235,20 @@ export function getCommonAncestor (selector) {
235 // Return the common ancestor 235 // Return the common ancestor
236 return range.commonAncestorContainer 236 return range.commonAncestorContainer
237} 237}
238
239/**
240 * full2Half: full-Width Digits To Half-Width.
241 *
242 * @param {String} str
243 */
244export const full2Half = (str) => {
245 // Create a regular expression to match full-width digits (U+FF10 to U+FF19)
246 const fullWidthDigitsRegex = /[\uFF0E\uFF10-\uFF19]/g
247
248 // Replace full-width digits with their half-width equivalents
249 return str.replace(fullWidthDigitsRegex, (match) => {
250 const fullWidthDigit = match.charCodeAt(0)
251 const halfWidthDigit = fullWidthDigit - 65248 // Offset to convert full-width to half-width
252 return String.fromCharCode(halfWidthDigit)
253 })
254}