MCPcopy Index your code
hub / github.com/WP-API/node-wpapi / argumentIsNumeric

Function argumentIsNumeric

lib/util/argument-is-numeric.js:13–35  ·  view source on GitHub ↗
( val )

Source from the content-addressed store, hash-verified

11 * @returns {void}
12 */
13const argumentIsNumeric = ( val ) => {
14 if ( typeof val === 'number' ) {
15 return true;
16 }
17
18 if ( typeof val === 'string' ) {
19 return /^\d+$/.test( val );
20 }
21
22 if ( Array.isArray( val ) ) {
23 for ( let i = 0; i < val.length; i++ ) {
24 // Fail early if any argument isn't determined to be numeric
25 if ( ! argumentIsNumeric( val[ i ] ) ) {
26 return false;
27 }
28 }
29 return true;
30 }
31
32 // If it's not an array, and not a string, and not a number, we don't
33 // know what to do with it
34 return false;
35};
36
37module.exports = argumentIsNumeric;

Callers 2

parameters.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected