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

inputmask-core

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inputmask-core - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

6

CHANGES.md

@@ -0,1 +1,7 @@

## 2.2.0 / 2016-09-15
Fixed placeholderChar to allow `''`
Fixed `setSelection` to set the selection to the end of the prior value chunk (user-input value)
Added `isRevealingMask` property
## 2.1.1 / 2015-09-11

@@ -2,0 +8,0 @@

37

lib/index.js

@@ -71,3 +71,3 @@ 'use strict'

*/
function Pattern(source, formatCharacters, placeholderChar) {
function Pattern(source, formatCharacters, placeholderChar, isRevealingMask) {
if (!(this instanceof Pattern)) {

@@ -91,5 +91,6 @@ return new Pattern(source, formatCharacters, placeholderChar)

this.lastEditableIndex = null
/** Lookup for indices of editable characters in the pattern. */
this._editableIndices = {}
/** If true, only the pattern before the last valid value character shows. */
this.isRevealingMask = isRevealingMask || false

@@ -144,2 +145,7 @@ this._parse()

if (this.isEditableIndex(i)) {
if (this.isRevealingMask &&
value.length <= valueIndex &&
!this.isValidAtIndex(value[valueIndex], i)) {
break
}
valueBuffer[i] = (value.length > valueIndex && this.isValidAtIndex(value[valueIndex], i)

@@ -187,6 +193,6 @@ ? this.transform(value[valueIndex], i)

if (!(this instanceof InputMask)) { return new InputMask(options) }
options = extend({
formatCharacters: null,
pattern: null,
isRevealingMask: false,
placeholderChar: DEFAULT_PLACEHOLDER_CHAR,

@@ -201,4 +207,4 @@ selection: {start: 0, end: 0},

if (options.placeholderChar.length !== 1) {
throw new Error('InputMask: placeholderChar should be a single character.')
if (typeof options.placeholderChar !== 'string' || options.placeholderChar.length > 1) {
throw new Error('InputMask: placeholderChar should be a single character or an empty string.')
}

@@ -210,3 +216,4 @@

value: options.value,
selection: options.selection
selection: options.selection,
isRevealingMask: options.isRevealingMask
})

@@ -272,3 +279,2 @@ }

// Took more input after undoing, so blow any subsequent history away
console.log('splice(', this._historyIndex, this._history.length - this._historyIndex, ')')
this._history.splice(this._historyIndex, this._history.length - this._historyIndex)

@@ -457,3 +463,3 @@ this._historyIndex = null

}, options)
this.pattern = new Pattern(pattern, this.formatCharacters, this.placeholderChar)
this.pattern = new Pattern(pattern, this.formatCharacters, this.placeholderChar, options.isRevealingMask)
this.setValue(options.value)

@@ -472,6 +478,15 @@ this.emptyValue = this.pattern.formatValue([]).join('')

}
if (this.selection.end > this.pattern.lastEditableIndex + 1) {
this.selection.start = this.selection.end = this.pattern.lastEditableIndex + 1
return true
// Set selection to the first editable, non-placeholder character before the selection
// OR to the beginning of the pattern
var index = this.selection.start
while (index >= this.pattern.firstEditableIndex) {
if (this.pattern.isEditableIndex(index - 1) &&
this.value[index - 1] !== this.placeholderChar ||
index === this.pattern.firstEditableIndex) {
this.selection.start = this.selection.end = index
break
}
index--
}
return true
}

@@ -478,0 +493,0 @@ return false

{
"name": "inputmask-core",
"version": "2.1.1",
"version": "2.2.0",
"description": "Standalone input mask implementation, independent of any GUI",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -143,3 +143,3 @@ # inputmask-core [![Build Status](https://secure.travis-ci.org/insin/inputmask-core.png)](http://travis-ci.org/insin/inputmask-core)

validate: function(char) { return /\w/.test(char) }
format: function(char) { return char.toLowerCase() }
transform: function(char) { return char.toLowerCase() }
}

@@ -150,3 +150,3 @@ }

To override a built-in format character, pass its character as a property of this object along iwht the new definition.
To override a built-in format character, pass its character as a property of this object along with the new definition.

@@ -166,3 +166,3 @@ To disable a built-in format character, pass its character as a property of this object with a `null` value:

The character which is used to fill in editable slots for which these is no input yet when getting the mask's current value.
The character which is used to fill in editable slots for which there is no input yet when getting the mask's current value.

@@ -187,2 +187,11 @@ Defaults to `'_'`; must be a single character.

### `isRevealingMask` : `boolean`
An optional property that, if true, progressively shows the mask as input is entered. Defaults to `false`
Example:
Given an input with a mask of `111-1111 x 111`, a value of `47`, and `isRevealingMask` set to `true`, then the input's value is formatted as `47`
Given the same input but with a value of `476`, then the input's value is formatted as `476-`
Given the same input but with a value of `47 3191`, then the input's value is formatted as `47_-3191 x `
## `InputMask` editing methods

@@ -189,0 +198,0 @@

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