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
1
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.0.1 to 2.1.0

11

CHANGES.md

@@ -0,4 +1,10 @@

## 2.1.0 / 2015-07-15
Added `mask.getRawValue()` to get the user's raw input, without any non-editable placeholder characters. [[muffinresearch][muffinresearch]]
Added customisation of the character used to fill in editable slots for which these is no input yet, by passing a single-character `placeholderChar` string as an option to the `InputMask` constructor. [[muffinresearch][muffinresearch]]
## 2.0.1 / 2015-07-14
Fixed taking input for patterns with leading static parts when the cursor or entire selection is in the static part.
Fixed taking input for patterns with leading static parts when the cursor or entire selection is in the static part. [[jordansexton][jordansexton]]

@@ -55,1 +61,4 @@ ## 2.0.0 / 2015-04-03

* Backspacing
[jordansexton]: https://github.com/jordansexton
[muffinresearch]: https://github.com/muffinresearch

60

lib/index.js

@@ -1,2 +0,2 @@

'use strict';
'use strict'

@@ -40,3 +40,2 @@ function extend(dest, src) {

var PLACEHOLDER = '_'
var ESCAPE_CHAR = '\\'

@@ -48,2 +47,3 @@

var DEFAULT_PLACEHOLDER_CHAR = '_'
var DEFAULT_FORMAT_CHARACTERS = {

@@ -73,5 +73,9 @@ '*': {

*/
function Pattern(source, formatCharacters) {
if (!(this instanceof Pattern)) { return new Pattern(source) }
function Pattern(source, formatCharacters, placeholderChar) {
if (!(this instanceof Pattern)) {
return new Pattern(source, formatCharacters, placeholderChar)
}
/** Placeholder character */
this.placeholderChar = placeholderChar || DEFAULT_PLACEHOLDER_CHAR
/** Format character definitions. */

@@ -143,3 +147,3 @@ this.formatCharacters = formatCharacters || DEFAULT_FORMAT_CHARACTERS

? this.transform(value[valueIndex], i)
: PLACEHOLDER)
: this.placeholderChar)
valueIndex++

@@ -188,2 +192,3 @@ }

pattern: null,
placeholderChar: DEFAULT_PLACEHOLDER_CHAR,
selection: {start: 0, end: 0},

@@ -197,2 +202,7 @@ value: ''

if (options.placeholderChar.length !== 1) {
throw new Error('InputMask: placeholderChar should be a single character.')
}
this.placeholderChar = options.placeholderChar
this.formatCharacters = mergeFormatCharacters(options.formatCharacters)

@@ -244,3 +254,3 @@ this.setPattern(options.pattern, {

if (this.pattern.isEditableIndex(end)) {
this.value[end] = PLACEHOLDER
this.value[end] = this.placeholderChar
}

@@ -267,5 +277,5 @@ end--

}
if (this._lastOp != 'input' ||
selectionBefore.start != selectionBefore.end ||
this._lastSelection != null && selectionBefore.start != this._lastSelection.start) {
if (this._lastOp !== 'input' ||
selectionBefore.start !== selectionBefore.end ||
this._lastSelection !== null && selectionBefore.start !== this._lastSelection.start) {
this._history.push({value: valueBefore, selection: selectionBefore, lastOp: this._lastOp})

@@ -294,8 +304,6 @@ }

var format
// No range selected - work on the character preceding the cursor
if (this.selection.start === this.selection.end) {
if (this.pattern.isEditableIndex(this.selection.start - 1)) {
this.value[this.selection.start - 1] = PLACEHOLDER
this.value[this.selection.start - 1] = this.placeholderChar
}

@@ -310,3 +318,3 @@ this.selection.start--

if (this.pattern.isEditableIndex(end)) {
this.value[end] = PLACEHOLDER
this.value[end] = this.placeholderChar
}

@@ -323,5 +331,5 @@ end--

}
if (this._lastOp != 'backspace' ||
selectionBefore.start != selectionBefore.end ||
this._lastSelection != null && selectionBefore.start != this._lastSelection.start) {
if (this._lastOp !== 'backspace' ||
selectionBefore.start !== selectionBefore.end ||
this._lastSelection !== null && selectionBefore.start !== this._lastSelection.start) {
this._history.push({value: valueBefore, selection: selectionBefore, lastOp: this._lastOp})

@@ -371,3 +379,3 @@ }

for (var i = 0, l = input.length;
for (i = 0, l = input.length;
i < l && this.selection.start <= this.pattern.lastEditableIndex;

@@ -412,5 +420,5 @@ i++) {

var value = this.getValue()
if (historyItem.value != value ||
historyItem.selection.start != this.selection.start ||
historyItem.selection.end != this.selection.end) {
if (historyItem.value !== value ||
historyItem.selection.start !== this.selection.start ||
historyItem.selection.end !== this.selection.end) {
this._history.push({value: value, selection: copy(this.selection), lastOp: this._lastOp, startUndo: true})

@@ -455,3 +463,3 @@ }

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

@@ -486,2 +494,12 @@ this.emptyValue = this.pattern.formatValue([]).join('')

InputMask.prototype.getRawValue = function getRawValue() {
var rawValue = []
for (var i = 0; i < this.value.length; i++) {
if (this.pattern._editableIndices[i] === true) {
rawValue.push(this.value[i])
}
}
return rawValue.join('')
}
InputMask.prototype._resetHistory = function _resetHistory() {

@@ -488,0 +506,0 @@ this._history = []

{
"name": "inputmask-core",
"version": "2.0.1",
"version": "2.1.0",
"description": "Standalone input mask implementation, independent of any GUI",
"main": "lib/index.js",
"scripts": {
"lint": "eslint lib test",
"test": "tape test/*.js"

@@ -16,2 +17,4 @@ },

"devDependencies": {
"eslint": "^0.24.1",
"eslint-config-standard": "^3.4.1",
"tape": "^3.5.0"

@@ -18,0 +21,0 @@ },

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

### `placeholderChar` : `string`
The character which is used to fill in editable slots for which these is no input yet when getting the mask's current value.
Defaults to `'_'`; must be a single character.
```javascript
var mask = new InputMask({pattern: '11/11/1111', placeholderChar: ' '})
mask.input('1')
// → true
mask.getValue()
// → '1 / / '
```
### `value` : `string`

@@ -310,2 +324,20 @@

### `getRawValue()` : `string`
Gets the current value in the mask without non-editable pattern characters.
This can be useful when changing the mask's pattern, to "replay" the user's input so far into the new patten:
```javascript
var mask = new InputMask({pattern: '1111 1111', value: '98781'})
mask.getValue()
// → '9878 1___'
mask.getRawValue()
// → '98781'
mask.setPattern('111 111', {value: mask.getRawValue()})
mask.getValue()
// → '987 81_'
```
### `setValue(value: string)`

@@ -335,2 +367,2 @@

## MIT Licensed
## MIT Licensed

Sorry, the diff of this file is not supported yet

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