vuetify-masked
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "vuetify-masked", | ||
"description": "vuetify masked textfield and filter", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": "Kim Mannstedt <k.mannstedt+dev@gmail.com>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -114,3 +114,3 @@ # vuetify-masked | ||
|falseCharWildcard|string |``''`` |yes |yes |False characters of the provided v-model/value will be replaced with this one. By default they will simply be deleted.| | ||
|formatMask |string, object |``'##########'`` |yes |yes |Used to mask the given value. Meaining of characters and usable aatributes for obecjt can be foudn below table| | ||
|formatMask |string, object |``'##########'`` |yes |yes |Used to mask the given value. Meaning of characters and usable attributes for object can be found below table| | ||
|hints |object ||yes|no| Hints will be displayed depending on the cursor position and according to the next possible character that can be entered. | | ||
@@ -117,0 +117,0 @@ |length |number |``null`` |yes |no |Max number of digits (including precision) that can be entered into the text field. Ignored for type text.| |
import { formatFloat, formatText } from "./utils/formatter"; | ||
import { prepareMask } from './utils/preparator' | ||
let globalOptions = { | ||
type: 'text', | ||
formatMask: '##########', | ||
deformatMask: null, | ||
maskCharacter: ['-', '.', ',', ' ', '/', '(', ')', '_', '\\', '\'', '~', '*', '&', '"', '?'], | ||
empty: null, | ||
precision: 2, | ||
locale: 'en-EN', | ||
suffix: null, | ||
falseCharWildcard: '' | ||
} | ||
function formatMask () { | ||
function formatMask (options) { | ||
var m = [] | ||
if(typeIsText) { | ||
if(Array.isArray(globalOptions.formatMask)) { | ||
for(var i = 0; i < globalOptions.formatMask.length; i++) { | ||
let c = globalOptions.formatMask[i] | ||
if(typeIsText(options)) { | ||
if(Array.isArray(options.formatMask)) { | ||
for(var i = 0; i < options.formatMask.length; i++) { | ||
let c = options.formatMask[i] | ||
let o = prepareMask(c, {}, cmpMaskCharacter()) | ||
let o = prepareMask(c, {}, cmpMaskCharacter(options)) | ||
@@ -28,3 +16,3 @@ m.push(o) | ||
} else { | ||
let stringMask = globalOptions.formatMask.split('') | ||
let stringMask = options.formatMask.split('') | ||
@@ -34,3 +22,3 @@ for(var i = 0; i < stringMask.length; i++) { | ||
let o = prepareMask(c, {}, cmpMaskCharacter()) | ||
let o = prepareMask(c, {}, cmpMaskCharacter(options)) | ||
@@ -44,4 +32,4 @@ m.push(o) | ||
function typeIsText() { | ||
if(globalOptions.type === 'text') { | ||
function typeIsText(options) { | ||
if(options.type === 'text') { | ||
return true | ||
@@ -53,4 +41,4 @@ } else { | ||
function typeIsFloat() { | ||
if(['percentage', 'currency', 'integer', 'float'].indexOf(globalOptions.type) !== -1) { | ||
function typeIsFloat(options) { | ||
if(['percentage', 'currency', 'integer', 'float'].indexOf(options.type) !== -1) { | ||
return true | ||
@@ -62,22 +50,22 @@ } else { | ||
function cmpMaskCharacter() { | ||
let v = globalOptions.maskCharacter.filter(char => char != globalOptions.falseCharWildcard) | ||
function cmpMaskCharacter(options) { | ||
let v = options.maskCharacter.filter(char => char != options.falseCharWildcard) | ||
return v | ||
} | ||
function cmpPrecision() { | ||
if(globalOptions.type === 'integer') { | ||
function cmpPrecision(options) { | ||
if(options.type === 'integer') { | ||
return 0 | ||
} else { | ||
return globalOptions.precision | ||
return options.precision | ||
} | ||
} | ||
function cmpSuffix() { | ||
if(globalOptions.type === 'percentage') { | ||
return globalOptions.suffix || '%' | ||
} else if(globalOptions.type === 'currency') { | ||
return globalOptions.suffix || 'USD' | ||
function cmpSuffix(options) { | ||
if(options.type === 'percentage') { | ||
return options.suffix || '%' | ||
} else if(options.type === 'currency') { | ||
return options.suffix || 'USD' | ||
} else { | ||
return globalOptions.suffix || '' | ||
return options.suffix || '' | ||
} | ||
@@ -87,13 +75,25 @@ } | ||
export default (value, options) => { | ||
globalOptions = Object.assign(globalOptions, options) | ||
let defaultOptions = { | ||
type: 'text', | ||
formatMask: '##########', | ||
deformatMask: null, | ||
maskCharacter: ['-', '.', ',', ' ', '/', '(', ')', '_', '\\', '\'', '~', '*', '&', '"', '?'], | ||
empty: null, | ||
precision: 2, | ||
locale: 'en-EN', | ||
suffix: null, | ||
falseCharWildcard: '' | ||
} | ||
let result = globalOptions.empty | ||
defaultOptions = Object.assign(defaultOptions, options) | ||
if(typeIsText()) { | ||
result = formatText(value, formatMask(), cmpMaskCharacter(), '') | ||
} else if (typeIsFloat()) { | ||
result = formatFloat(value, globalOptions.locale, cmpPrecision()) | ||
let result = defaultOptions.empty | ||
if(typeIsText(defaultOptions)) { | ||
result = formatText(value, formatMask(defaultOptions), cmpMaskCharacter(defaultOptions), '') | ||
} else if (typeIsFloat(defaultOptions)) { | ||
result = formatFloat(value, defaultOptions.locale, cmpPrecision(defaultOptions)) | ||
} | ||
return result + cmpSuffix() | ||
return result + cmpSuffix(defaultOptions) | ||
} |
36323