forked from probil/v-mask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Max Lyashuk
committed
Aug 12, 2016
0 parents
commit 40a18c8
Showing
6 changed files
with
278 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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,120 @@ | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
### SublimeText template | ||
# cache files for sublime text | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
*.stTheme.cache | ||
|
||
# workspace files are user-specific | ||
*.sublime-workspace | ||
|
||
# project files should be checked into the repository, unless a significant | ||
# proportion of contributors will probably not be using SublimeText | ||
# *.sublime-project | ||
|
||
# sftp configuration file | ||
sftp-config.json | ||
|
||
# Package control specific files | ||
Package Control.last-run | ||
Package Control.ca-list | ||
Package Control.ca-bundle | ||
Package Control.system-ca-bundle | ||
Package Control.cache/ | ||
Package Control.ca-certs/ | ||
bh_unicode_properties.cache | ||
|
||
# Sublime-github package stores a github token in this file | ||
# https://packagecontrol.io/packages/sublime-github | ||
GitHub.sublime-settings | ||
|
||
### JetBrains IDEs | ||
|
||
# IntelliJ project files | ||
.idea | ||
|
||
### Windows template | ||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
### OSX template | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Max Lyashuk | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,41 @@ | ||
Vue input mask | ||
============== | ||
|
||
Simple input mask lib for vue.js based on [PureMask.js](https://github.com/romulobrasil/PureMask.js) | ||
|
||
## Installation | ||
|
||
`npm install v-mask` | ||
|
||
## Usage | ||
|
||
import Vue from 'vue | ||
import VueMask from 'v-mask' | ||
|
||
/** Activate vue.js plugins **/ | ||
Vue.use(VueMask); | ||
|
||
Now you are ready to use it in code! | ||
|
||
<input type="text" v-mask format="####-##"> | ||
<!-- OR --> | ||
<input type="text" data-mask="##/##/#### ##:##" > | ||
|
||
## Format description | ||
|
||
List of supported placeholders: | ||
|
||
| Value | Format | | ||
|-------|------------------------------| | ||
| # | Number (0-9) | | ||
| A | Letter in any case (a-z,A-Z) | | ||
| N | Number or letter | | ||
| X | Any symbol | | ||
|
||
## Tests | ||
|
||
In TODO | ||
|
||
## Contributing | ||
|
||
PR is welcome! |
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,63 @@ | ||
"use strict"; | ||
|
||
/** | ||
* Format function | ||
* @param {String} data String to mask (input value) | ||
* @param {String} mask Mask format, like `####-##` | ||
* @returns {string} Formatted text | ||
*/ | ||
function format (data, mask){ | ||
var text = ''; | ||
var c, m, i, x; | ||
|
||
for (i = 0, x = 1; x && i < mask.length; ++i) { | ||
c = data.charAt(i); | ||
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 'X' : text += c; break; | ||
default : text += m; break; | ||
} | ||
} | ||
return text; | ||
} | ||
|
||
/** | ||
* Vue plugin definition | ||
* @param {Vue} Vue | ||
*/ | ||
module.exports.install = function (Vue) { | ||
Vue.directive('mask', { | ||
params: ['format'], | ||
bind : function () { | ||
/** | ||
* Fires on input change | ||
*/ | ||
this.handler = function () { | ||
var value = this.el.value; | ||
var mask = this.params.format; | ||
var new_value = value; | ||
|
||
if (this.previous.length < value.length) { | ||
new_value = format(value, mask); | ||
} | ||
|
||
this.el.value = new_value; | ||
this.previous = new_value; | ||
|
||
}.bind(this); | ||
|
||
this.previous = ''; | ||
|
||
this.el.addEventListener('input', this.handler, false); | ||
this.handler(); | ||
}, | ||
unbind: function () { | ||
this.el.removeEventListener('input', this.handler, false) | ||
} | ||
}); | ||
}; | ||
|
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,24 @@ | ||
{ | ||
"name": "v-mask", | ||
"version": "0.1.0", | ||
"description": "Simple input mask lib for vue.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/probil/v-mask.git" | ||
}, | ||
"keywords": [ | ||
"vue.js", | ||
"vue", | ||
"vue-mask" | ||
], | ||
"author": "Max Lyashuk <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/probil/v-mask/issues" | ||
}, | ||
"homepage": "https://github.com/probil/v-mask#readme" | ||
} |