Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/dom

Package Overview
Dependencies
Maintainers
14
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/dom - npm Package Compare versions

Comparing version 2.8.0 to 2.9.0

19

build-module/dom.js

@@ -436,2 +436,17 @@ /**

/**
* Check whether the given element is an input field of type number
* and has a valueAsNumber
*
* @param {HTMLElement} element The HTML element.
*
* @return {boolean} True if the element is input and holds a number.
*/
export function isNumberInput(element) {
var nodeName = element.nodeName,
type = element.type,
valueAsNumber = element.valueAsNumber;
return nodeName === 'INPUT' && type === 'number' && !!valueAsNumber;
}
/**
* Check wether the current document has a selection.

@@ -448,2 +463,6 @@ * This checks both for focus in an input field and general text selection.

if (isNumberInput(document.activeElement)) {
return true;
}
var selection = window.getSelection();

@@ -450,0 +469,0 @@ var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -13,2 +13,3 @@ "use strict";

exports.isTextField = isTextField;
exports.isNumberInput = isNumberInput;
exports.documentHasSelection = documentHasSelection;

@@ -468,2 +469,18 @@ exports.isEntirelySelected = isEntirelySelected;

/**
* Check whether the given element is an input field of type number
* and has a valueAsNumber
*
* @param {HTMLElement} element The HTML element.
*
* @return {boolean} True if the element is input and holds a number.
*/
function isNumberInput(element) {
var nodeName = element.nodeName,
type = element.type,
valueAsNumber = element.valueAsNumber;
return nodeName === 'INPUT' && type === 'number' && !!valueAsNumber;
}
/**
* Check wether the current document has a selection.

@@ -481,2 +498,6 @@ * This checks both for focus in an input field and general text selection.

if (isNumberInput(document.activeElement)) {
return true;
}
var selection = window.getSelection();

@@ -483,0 +504,0 @@ var range = selection.rangeCount ? selection.getRangeAt(0) : null;

6

package.json
{
"name": "@wordpress/dom",
"version": "2.8.0",
"version": "2.9.0",
"description": "DOM utilities module for WordPress.",

@@ -26,3 +26,3 @@ "author": "The WordPress Contributors",

"dependencies": {
"@babel/runtime": "^7.8.3",
"@babel/runtime": "^7.9.2",
"lodash": "^4.17.15"

@@ -33,3 +33,3 @@ },

},
"gitHead": "41fc84af285da696c65c235331ee245dfe23971d"
"gitHead": "65dbf3a9503402ca3837090dc89d0207f7d96352"
}

@@ -121,2 +121,15 @@ # DOM

<a name="isNumberInput" href="#isNumberInput">#</a> **isNumberInput**
Check whether the given element is an input field of type number
and has a valueAsNumber
_Parameters_
- _element_ `HTMLElement`: The HTML element.
_Returns_
- `boolean`: True if the element is input and holds a number.
<a name="isTextField" href="#isTextField">#</a> **isTextField**

@@ -123,0 +136,0 @@

@@ -473,2 +473,16 @@ /**

/**
* Check whether the given element is an input field of type number
* and has a valueAsNumber
*
* @param {HTMLElement} element The HTML element.
*
* @return {boolean} True if the element is input and holds a number.
*/
export function isNumberInput( element ) {
const { nodeName, type, valueAsNumber } = element;
return nodeName === 'INPUT' && type === 'number' && !! valueAsNumber;
}
/**
* Check wether the current document has a selection.

@@ -484,2 +498,6 @@ * This checks both for focus in an input field and general text selection.

if ( isNumberInput( document.activeElement ) ) {
return true;
}
const selection = window.getSelection();

@@ -486,0 +504,0 @@ const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

@@ -9,2 +9,3 @@ /**

__unstableStripHTML as stripHTML,
isNumberInput,
} from '../dom';

@@ -147,2 +148,17 @@

it( 'should return false for empty input element of type number', () => {
const input = document.createElement( 'input' );
input.type = 'number';
expect( isNumberInput( input ) ).toBe( false );
} );
it( 'should return true for an input element of type number', () => {
const input = document.createElement( 'input' );
input.type = 'number';
input.valueAsNumber = 23;
expect( isNumberInput( input ) ).toBe( true );
} );
it( 'should return true for a contenteditable element', () => {

@@ -149,0 +165,0 @@ const div = document.createElement( 'div' );

Sorry, the diff of this file is not supported yet

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