This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from shrpne/feature-rollup
Add minified version, build with rollup
- Loading branch information
Showing
12 changed files
with
349 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
{ | ||
"presets": ["es2015", "stage-2"], | ||
"plugins": ["transform-runtime"], | ||
"comments": false | ||
"presets": [ | ||
["es2015", { | ||
"modules": false | ||
}], | ||
], | ||
"comments": false, | ||
"env": { | ||
"test": { | ||
"presets": ["es2015"], | ||
"plugins": ["transform-runtime", "syntax-dynamic-import"], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
|
||
export default { | ||
entry: 'src/index.js', | ||
plugins: [ | ||
nodeResolve(), | ||
babel(), | ||
], | ||
targets: [ | ||
{ | ||
format: 'umd', | ||
moduleName: 'VueMask', | ||
dest: 'dist/v-mask.js', | ||
}, | ||
{ | ||
format: 'es', | ||
dest: 'dist/v-mask.esm.js', | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import nodeResolve from 'rollup-plugin-node-resolve'; | ||
import babel from 'rollup-plugin-babel'; | ||
import uglify from 'rollup-plugin-uglify'; | ||
|
||
|
||
export default { | ||
entry: 'src/index.js', | ||
plugins: [ | ||
nodeResolve(), | ||
babel(), | ||
uglify(), | ||
], | ||
format: 'umd', | ||
moduleName: 'VueMask', | ||
dest: 'dist/v-mask.min.js', | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
var format = function (data, mask) { | ||
if (!mask) return data; | ||
|
||
var maskStartRegExp = /^([^#ANX]+)/; | ||
|
||
if (data.length == 1 && maskStartRegExp.test(mask)) { | ||
data = maskStartRegExp.exec(mask)[0] + data; | ||
} | ||
|
||
var text = ''; | ||
|
||
var cOffset = 0; | ||
|
||
for (var i = 0; i < mask.length; i++) { | ||
var m = mask.charAt(i); | ||
switch (m) { | ||
case '#': | ||
break; | ||
case 'A': | ||
break; | ||
case '?': | ||
break; | ||
case 'N': | ||
break; | ||
case 'X': | ||
break; | ||
default: | ||
data = data.replace(m, ''); | ||
} | ||
} | ||
for (var _i = 0, x = 1; x && _i < mask.length; ++_i) { | ||
var c = data.charAt(_i - cOffset); | ||
var _m = mask.charAt(_i); | ||
|
||
switch (_m) { | ||
case '#': | ||
if (/\d/.test(c)) { | ||
text += c; | ||
} else { | ||
x = 0; | ||
}break; | ||
case 'A': | ||
if (/[a-z]/i.test(c)) { | ||
text += c; | ||
} else { | ||
x = 0; | ||
}break; | ||
case 'N': | ||
if (/[a-z0-9]/i.test(c)) { | ||
text += c; | ||
} else { | ||
x = 0; | ||
}break; | ||
|
||
case '?': | ||
cOffset++;break; | ||
case 'X': | ||
text += c;break; | ||
default: | ||
text += _m; | ||
|
||
if (c && c !== _m) { | ||
data = ' ' + data; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
return text; | ||
}; | ||
|
||
var trigger = function trigger(el, type) { | ||
var e = document.createEvent('HTMLEvents'); | ||
e.initEvent(type, true, true); | ||
el.dispatchEvent(e); | ||
}; | ||
|
||
function updateValue(el) { | ||
var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var value = el.value, | ||
_el$dataset = el.dataset, | ||
_el$dataset$previousV = _el$dataset.previousValue, | ||
previousValue = _el$dataset$previousV === undefined ? "" : _el$dataset$previousV, | ||
mask = _el$dataset.mask; | ||
|
||
|
||
if (force || value && value !== previousValue && value.length > previousValue.length) { | ||
el.value = format(value, mask); | ||
trigger(el, 'input'); | ||
} | ||
|
||
el.dataset.previousValue = value; | ||
} | ||
|
||
function updateMask(el, mask) { | ||
el.dataset.mask = mask; | ||
} | ||
|
||
var VueMaskDirective = { | ||
bind: function bind(el, _ref) { | ||
var value = _ref.value; | ||
|
||
updateMask(el, value); | ||
updateValue(el); | ||
}, | ||
componentUpdated: function componentUpdated(el, _ref2) { | ||
var value = _ref2.value, | ||
oldValue = _ref2.oldValue; | ||
|
||
|
||
var isMaskChanged = value !== oldValue; | ||
|
||
if (isMaskChanged) { | ||
updateMask(el, value); | ||
} | ||
|
||
updateValue(el, isMaskChanged); | ||
} | ||
}; | ||
|
||
var VueMaskPlugin = function VueMaskPlugin(Vue) { | ||
Vue.directive('mask', VueMaskDirective); | ||
}; | ||
|
||
export { VueMaskPlugin, VueMaskDirective };export default VueMaskPlugin; |
Oops, something went wrong.