New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-maskedinput

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-maskedinput - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

es6/index.js

7

CHANGES.md

@@ -1,3 +0,8 @@

## 3.1.0 / 2015-10-23
## 3.1.1 / 2016-03-09
* Convert tooling to use [nwb](https://github.com/insin/nwb/) [[bpugh]][[bpugh]]
* Publish `dist` files
## 3.1.0 / 2016-02-11
* Added support for `value` behaving as a controlled component.

@@ -4,0 +9,0 @@

190

lib/index.js
'use strict';
var React = require('react')
var $__0= require('react/lib/ReactInputSelection'),getSelection=$__0.getSelection,setSelection=$__0.setSelection
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var InputMask = require('inputmask-core')
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var KEYCODE_Z = 90
var KEYCODE_Y = 89
var React = require('react');
var _require = require('react/lib/ReactInputSelection');
var getSelection = _require.getSelection;
var setSelection = _require.setSelection;
var InputMask = require('inputmask-core');
var KEYCODE_Z = 90;
var KEYCODE_Y = 89;
function isUndo(e) {
return (e.ctrlKey || e.metaKey) && e.keyCode === (e.shiftKey ? KEYCODE_Y : KEYCODE_Z)
return (e.ctrlKey || e.metaKey) && e.keyCode === (e.shiftKey ? KEYCODE_Y : KEYCODE_Z);
}
function isRedo(e) {
return (e.ctrlKey || e.metaKey) && e.keyCode === (e.shiftKey ? KEYCODE_Z : KEYCODE_Y)
return (e.ctrlKey || e.metaKey) && e.keyCode === (e.shiftKey ? KEYCODE_Z : KEYCODE_Y);
}
var MaskedInput = React.createClass({displayName: "MaskedInput",
var MaskedInput = React.createClass({
displayName: 'MaskedInput',
propTypes: {

@@ -27,9 +37,9 @@ mask: React.PropTypes.string.isRequired,

getDefaultProps:function() {
getDefaultProps: function getDefaultProps() {
return {
value: ''
}
};
},
componentWillMount:function() {
componentWillMount: function componentWillMount() {
var options = {

@@ -39,81 +49,80 @@ pattern: this.props.mask,

formatCharacters: this.props.formatCharacters
}
};
if (this.props.placeholderChar) {
options.placeholderChar = this.props.placeholderChar
options.placeholderChar = this.props.placeholderChar;
}
this.mask = new InputMask(options)
this.mask = new InputMask(options);
},
componentWillReceiveProps:function(nextProps) {
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
this.mask.setValue(nextProps.value)
this.mask.setValue(nextProps.value);
}
if (this.props.mask !== nextProps.mask) {
this.mask.setPattern(nextProps.mask, {value: this.mask.getRawValue()})
this.mask.setPattern(nextProps.mask, { value: this.mask.getRawValue() });
}
},
_updateMaskSelection:function() {
this.mask.selection = getSelection(this.input)
_updateMaskSelection: function _updateMaskSelection() {
this.mask.selection = getSelection(this.input);
},
_updateInputSelection:function() {
setSelection(this.input, this.mask.selection)
_updateInputSelection: function _updateInputSelection() {
setSelection(this.input, this.mask.selection);
},
_onChange:function(e) {
_onChange: function _onChange(e) {
// console.log('onChange', JSON.stringify(getSelection(this.input)), e.target.value)
var maskValue = this.mask.getValue()
if (e.target.value != maskValue) {
var maskValue = this.mask.getValue();
if (e.target.value !== maskValue) {
// Cut or delete operations will have shortened the value
if (e.target.value.length < maskValue.length) {
var sizeDiff = maskValue.length - e.target.value.length
this._updateMaskSelection()
this.mask.selection.end = this.mask.selection.start + sizeDiff
this.mask.backspace()
var sizeDiff = maskValue.length - e.target.value.length;
this._updateMaskSelection();
this.mask.selection.end = this.mask.selection.start + sizeDiff;
this.mask.backspace();
}
var value = this._getDisplayValue()
e.target.value = value
var value = this._getDisplayValue();
e.target.value = value;
if (value) {
this._updateInputSelection()
this._updateInputSelection();
}
}
if (this.props.onChange) {
this.props.onChange(e)
this.props.onChange(e);
}
},
_onKeyDown:function(e) {
_onKeyDown: function _onKeyDown(e) {
// console.log('onKeyDown', JSON.stringify(getSelection(this.input)), e.key, e.target.value)
if (isUndo(e)) {
e.preventDefault()
e.preventDefault();
if (this.mask.undo()) {
e.target.value = this._getDisplayValue()
this._updateInputSelection()
this.props.onChange(e)
e.target.value = this._getDisplayValue();
this._updateInputSelection();
this.props.onChange(e);
}
return
}
else if (isRedo(e)) {
e.preventDefault()
return;
} else if (isRedo(e)) {
e.preventDefault();
if (this.mask.redo()) {
e.target.value = this._getDisplayValue()
this._updateInputSelection()
this.props.onChange(e)
e.target.value = this._getDisplayValue();
this._updateInputSelection();
this.props.onChange(e);
}
return
return;
}
if (e.key == 'Backspace') {
e.preventDefault()
this._updateMaskSelection()
if (e.key === 'Backspace') {
e.preventDefault();
this._updateMaskSelection();
if (this.mask.backspace()) {
var value = this._getDisplayValue()
e.target.value = value
var value = this._getDisplayValue();
e.target.value = value;
if (value) {
this._updateInputSelection()
this._updateInputSelection();
}
this.props.onChange(e)
this.props.onChange(e);
}

@@ -123,3 +132,3 @@ }

_onKeyPress:function(e) {
_onKeyPress: function _onKeyPress(e) {
// console.log('onKeyPress', JSON.stringify(getSelection(this.input)), e.key, e.target.value)

@@ -129,49 +138,62 @@

// Ignore enter key to allow form submission
if (e.metaKey || e.altKey || e.ctrlKey || e.key == 'Enter') { return }
if (e.metaKey || e.altKey || e.ctrlKey || e.key === 'Enter') {
return;
}
e.preventDefault()
this._updateMaskSelection()
e.preventDefault();
this._updateMaskSelection();
if (this.mask.input(e.key)) {
e.target.value = this.mask.getValue()
this._updateInputSelection()
this.props.onChange(e)
e.target.value = this.mask.getValue();
this._updateInputSelection();
this.props.onChange(e);
}
},
_onPaste:function(e) {
_onPaste: function _onPaste(e) {
// console.log('onPaste', JSON.stringify(getSelection(this.input)), e.clipboardData.getData('Text'), e.target.value)
e.preventDefault()
this._updateMaskSelection()
e.preventDefault();
this._updateMaskSelection();
// getData value needed for IE also works in FF & Chrome
if (this.mask.paste(e.clipboardData.getData('Text'))) {
e.target.value = this.mask.getValue()
e.target.value = this.mask.getValue();
// Timeout needed for IE
setTimeout(this._updateInputSelection, 0)
this.props.onChange(e)
setTimeout(this._updateInputSelection, 0);
this.props.onChange(e);
}
},
_getDisplayValue:function() {
var value = this.mask.getValue()
return value === this.mask.emptyValue ? '' : value
_getDisplayValue: function _getDisplayValue() {
var value = this.mask.getValue();
return value === this.mask.emptyValue ? '' : value;
},
render:function() {
var $__0= this.props,mask=$__0.mask,formatCharacters=$__0.formatCharacters,size=$__0.size,placeholder=$__0.placeholder,props=(function(source, exclusion) {var rest = {};var hasOwn = Object.prototype.hasOwnProperty;if (source == null) {throw new TypeError();}for (var key in source) {if (hasOwn.call(source, key) && !hasOwn.call(exclusion, key)) {rest[key] = source[key];}}return rest;})($__0,{mask:1,formatCharacters:1,size:1,placeholder:1})
var patternLength = this.mask.pattern.length
return React.createElement("input", React.__spread({}, props,
{ref: function(r) {return this.input = r;}.bind(this),
maxLength: patternLength,
onChange: this._onChange,
onKeyDown: this._onKeyDown,
onKeyPress: this._onKeyPress,
onPaste: this._onPaste,
placeholder: placeholder || this.mask.emptyValue,
size: size || patternLength,
value: this._getDisplayValue()})
)
render: function render() {
var _this = this;
var _props = this.props;
var mask = _props.mask;
var formatCharacters = _props.formatCharacters;
var size = _props.size;
var placeholder = _props.placeholder;
var props = _objectWithoutProperties(_props, ['mask', 'formatCharacters', 'size', 'placeholder']);
var patternLength = this.mask.pattern.length;
return React.createElement('input', _extends({}, props, {
ref: function (r) {
return _this.input = r;
},
maxLength: patternLength,
onChange: this._onChange,
onKeyDown: this._onKeyDown,
onKeyPress: this._onKeyPress,
onPaste: this._onPaste,
placeholder: placeholder || this.mask.emptyValue,
size: size || patternLength,
value: this._getDisplayValue()
}));
}
})
});
module.exports = MaskedInput
module.exports = MaskedInput;
{
"name": "react-maskedinput",
"description": "Masked <input/> React component",
"version": "3.1.0",
"version": "3.1.1",
"main": "./lib/index.js",
"jsnext:main": "es6/index.js",
"standalone": "MaskedInput",

@@ -16,2 +17,15 @@ "homepage": "https://github.com/insin/react-maskedinput",

],
"files": [
"es6",
"lib",
"umd"
],
"scripts": {
"build": "nwb build",
"clean": "nwb clean",
"lint": "eslint src",
"start": "nwb serve",
"test": "nwb test",
"test:watch": "nwb test --server"
},
"dependencies": {

@@ -21,31 +35,10 @@ "inputmask-core": "^2.1.1"

"peerDependencies": {
"react": ">=0.14.0"
"react": "0.14.x"
},
"devDependencies": {
"browserify": "^10.1.3",
"browserify-shim": "^3.8.6",
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-header": "^1.2.2",
"gulp-jshint": "^1.10.0",
"gulp-plumber": "^1.0.0",
"gulp-react": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-streamify": "0.0.5",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.4",
"jshint-stylish": "^1.0.2",
"react": ">=0.13.0",
"tape": "^4.0.0",
"vinyl-source-stream": "^1.1.0"
"eslint-config-jonnybuchanan": "2.0.3",
"nwb": "0.8.x",
"react": "0.14.x",
"react-dom": "0.14.x"
},
"scripts": {
"debug": "gulp --debug",
"dist": "gulp bundle-js --production --release && gulp bundle-js --development --release",
"test": "gulp transpile-js && tape test/*.js",
"watch": "gulp"
},
"browserify-shim": {
"react": "global:React"
},
"repository": {

@@ -52,0 +45,0 @@ "type": "git",

@@ -23,3 +23,4 @@ # `MaskedInput`

You can find it in the [/dist directory](https://github.com/insin/react-maskedinput/tree/master/dist).
* [react-maskedinput.js](https://npmcdn.com/react-maskedinput/umd/react-maskedinput.js) (development version)
* [react-maskedinput.min.js](https://npmcdn.com/react-maskedinput/umd/react-maskedinput.min.js) (compressed production version)

@@ -26,0 +27,0 @@ ## Usage

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc