1.3.0 • Published 1 year ago

@chriscodesthings/is-hex-number v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

is-hex-number Test workflow status NPM Version License: MIT

Function to determine if a string is a hexadecimal number

Description

Tests a variable to see if it's a hex number.

See...


Install

npm install --save @chriscodesthings/is-hex-number

Use

import isHexNumber from '@chriscodesthings/is-hex-number';

console.log(isHexNumber("c0ffee"));
// => true

Syntax

isHexNumber(str, float, prefix0x);

Parameters

  • str: a string to test
  • float (optional): if true, allow a floating point hex number
  • prefix0x (optional): if true, allow the 0x prefix

Return Value

Returns boolean true if str is a valid hex number, false otherwise.

Examples

// convert to decimal or return null if invalid
function hex2dec(hex) {
    if( isHexNumber(hex)) {
        return parseInt(hex,16);
    }

    return null;
}

See Also...

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago