Options
All
  • Public
  • Public/Protected
  • All
Menu

Module source/numbers

Index

Variables

Variables

Const numbers

numbers: { containsDecimal: (num: string | number) => boolean; containsFraction: (num: string) => boolean; containsNum: (num: string | number) => boolean; convertToHex: (num: string | number) => string | null; decimal: (num: string | number) => boolean; fraction: (num: string) => boolean; isPhoneNumber: (str: string | number) => boolean; whole: (num: string | number) => boolean } = ...

Type declaration

  • containsDecimal: (num: string | number) => boolean
      • (num: string | number): boolean
      • Takes a string and returns boolean indicating whether string contains a decimal somwhere in it

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const hasDec = numbers.containsDecimal('has a decimal 123456.789');
        const noDec = numbers.whole('no decimal 123456');
        console.log(hasDec); // true
        console.log(noDec); // false
        

        Parameters

        • num: string | number

        Returns boolean

  • containsFraction: (num: string) => boolean
      • (num: string): boolean
      • Takes a string and returns a boolean indicating whether the string contains a fraction

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const hasFraction = numbers.containsFraction('this string has a fraction 1/2');
        const noFraction = numbers.containsFraction('this string does not have a fraction');
        console.log(hasFraction) // true
        console.log(noFraction) // false
        

        Parameters

        • num: string

        Returns boolean

  • containsNum: (num: string | number) => boolean
      • (num: string | number): boolean
      • Takes string and returns boolean for whether string contains at least 1 number

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const yes = numbers.containsNum('this has a number 33');
        const no = numbers.containsNum('this has a number 33');
        console.log(yes); // true
        console.log(no); // false
        

        Parameters

        • num: string | number

        Returns boolean

  • convertToHex: (num: string | number) => string | null
      • (num: string | number): string | null
      • Takes a number as a string or number form and returns the hexidecimal equivalent

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const hex = numbers.convertToHex('255');
        const moreHex = numbers.convertToHex(0);
        const notHex = numbers.convertToHex('nope');
        console.log(hex) // 'ff'
        console.log(moreHex) // '00'
        console.log(notHex) // 'NAN'
        

        Parameters

        • num: string | number

        Returns string | null

  • decimal: (num: string | number) => boolean
      • (num: string | number): boolean
      • Takes a string or a number and returns a boolean for whether it is a valid decimal

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const isDec = numbers.decimal(123456.789);
        const notDec = numbers.whole(123456);
        console.log(isDec); // true
        console.log(notDec); // false
        

        Parameters

        • num: string | number

        Returns boolean

  • fraction: (num: string) => boolean
      • (num: string): boolean
      • Takes a string and returns a boolean for whether it is a valid fraction.

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const valid = numbers.fraction('1/3');
        const invalid = numbers.fraction('3.33');
        console.log(isDec); // true
        console.log(notDec); // false
        

        Parameters

        • num: string

        Returns boolean

  • isPhoneNumber: (str: string | number) => boolean
      • (str: string | number): boolean
      • Takes a string or number and validates whether it is a valid phone number format.

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const valid = numbers.isPhoneNumber('(888) 555-1234');
        const invalid = numbers.isPhoneNumber('888-55-2345');
        console.log(valid); // true
        console.log(invalid); // false
        

        Valid formats:

        (123) 456-7890
        (123)456-7890
        123-456-7890
        123.456.7890
        1234567890
        +31636363634
        075-63546725
        

        Parameters

        • str: string | number

        Returns boolean

  • whole: (num: string | number) => boolean
      • (num: string | number): boolean
      • Takes a string or a number and returns boolean for whether it is a valid whole number

        Basic usage example:

        const numbers = require('stringman').numbers; // or `import {numbers} from 'stringman'`;
        const isWhole = numbers.whole(123456);
        const notWhole = numbers.whole(123456.789);
        console.log(isWhole); // true
        console.log(notWhole); // false
        

        Parameters

        • num: string | number

        Returns boolean

Generated using TypeDoc