2
0
mirror of https://github.com/tenrok/maska.git synced 2026-06-08 17:22:27 +03:00

Added custom transform function support alongside uppercase and lowercase

Added tests to an upcoming functionality
Fixed several lint issues manually
Added "lint:fix" npm script
Made it available to use 'uppercase' or  'lowercase' alongside custom transform function & applied several tests editions
This commit is contained in:
Sergey Luschik
2020-10-09 01:44:09 +03:00
parent 26234704f0
commit dd90143364
4 changed files with 91 additions and 4 deletions
+10 -1
View File
@@ -69,7 +69,7 @@ function process (value, mask, tokens, masked = true) {
}
}
// fix mask that ends with parentesis
// fix mask that ends with parenthesis
while (masked && im < mask.length) { // eslint-disable-line no-unmodified-loop-condition
const maskCharRest = mask[im]
if (tokens[maskCharRest]) {
@@ -83,7 +83,16 @@ function process (value, mask, tokens, masked = true) {
return ret + rest
}
/**
*
* @param {String} value
* @param {'uppercase' | 'lowercase' | 'transform'} token
*/
function tokenTransform (value, token) {
if (token.transform) {
value = token.transform(value)
}
if (token.uppercase) {
return value.toLocaleUpperCase()
} else if (token.lowercase) {
+7 -2
View File
@@ -19,7 +19,7 @@ function fixInputSelection (el, position, digit) {
position++
}
const selectionRange = (el.type && el.type.match(/^(text|search|password|tel|url)$/i) || !el.type)
const selectionRange = el.type ? el.type.match(/^(text|search|password|tel|url)$/i) : !el.type
if (selectionRange && el === document.activeElement) {
el.setSelectionRange(position, position)
setTimeout(function () {
@@ -32,4 +32,9 @@ function isString (val) {
return Object.prototype.toString.call(val) === '[object String]'
}
export { event, findInputElement, fixInputSelection, isString }
export {
event,
findInputElement,
fixInputSelection,
isString
}