spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← All files
name: dist/Utilities/TypeConverter.d.ts
-rw-r--r--
6879
  1import * as moment from "moment";
  2/**
  3 * Static class of helpers used to convert let ious types to each other.
  4 */
  5declare class TypeConverter {
  6    static ORIGIN_MOMENT: moment.Moment;
  7    private static SECONDS_IN_DAY;
  8    /**
  9     * Converts a datetime string to a moment object. Will return undefined if the string can't be converted.
 10     * @param {string} timeString - string to parse and convert.
 11     * @returns {moment.Moment}
 12     */
 13    static stringToMoment(timeString: string): moment.Moment;
 14    /**
 15     * Converts a time-formatted string to a number between 0 and 1, exclusive on 1.
 16     * @param timeString
 17     * @returns {number} representing time of day
 18     */
 19    static stringToTimeNumber(timeString: string): number;
 20    /**
 21     * Parses a string returning a moment that is either valid, invalid or undefined.
 22     * @param dateString to parse.
 23     * @returns {moment}
 24     */
 25    private static parseStringToMoment(dateString);
 26    /**
 27     * Parses a string as a date number. Throws error if parsing not possible.
 28     * @param dateString to parse
 29     * @returns {number} resulting date
 30     */
 31    static stringToDateNumber(dateString: string): number;
 32    /**
 33     * Converts strings to numbers, returning undefined if string cannot be parsed to number. Examples: "100", "342424",
 34     * "10%", "33.213131", "41.1231", "10e+1", "10E-1", "10.44E1", "-$9.29", "+$9.29", "1,000.1", "2000,000,000".
 35     * For reference see: https://regex101.com/r/PwghnF/9/
 36     * @param value to parse.
 37     * @returns {number} or undefined
 38     */
 39    static stringToNumber(value: string): number;
 40    /**
 41     * Converts any value to an inverted number or throws an error if it cannot coerce it to the number type
 42     * @param value to convert
 43     * @returns {number} to return. Will always return a number or throw an error. Never returns undefined.
 44     */
 45    static valueToInvertedNumber(value: any): number;
 46    /**
 47     * Converts any value to a number or throws an error if it cannot coerce it to the number type
 48     * @param value to convert
 49     * @returns {number} to return. Will always return a number or throw an error. Never returns undefined.
 50     */
 51    static valueToNumber(value: any): number;
 52    /**
 53     * Converts any value to a number, defaulting to 0 value in cases in which it cannot coerce it to a number type
 54     * @param value to conver
 55     * @returns {number} to return. Will always return a number or 0.
 56     */
 57    static valueToNumberGracefully(value: any): number;
 58    /**
 59     * Converts any value to a boolean or throws an error if it cannot coerce it to the boolean type.
 60     * @param value to convert
 61     * @returns {boolean} to return.
 62     */
 63    static valueToBoolean(value: any): boolean;
 64    /**
 65     * Convert a value to string.
 66     * @param value of any type, including array. array cannot be empty.
 67     * @returns {string} string representation of value
 68     */
 69    static valueToString(value: any): string;
 70    /**
 71     * Converts a value to a time number; a value between 0 and 1, exclusive on 1.
 72     * @param value to convert
 73     * @returns {number} representing a time value
 74     */
 75    static valueToTimestampNumber(value: any): number;
 76    /**
 77     * Returns true if string is number format.
 78     * @param str to check
 79     * @returns {boolean}
 80     */
 81    static isNumber(str: string): boolean;
 82    /**
 83     * Returns true if we can coerce it to the number type.
 84     * @param value to coerce
 85     * @returns {boolean} if could be coerced to a number
 86     */
 87    static canCoerceToNumber(value: any): boolean;
 88    /**
 89     * Takes any input type and will throw a REF_ERROR or coerce it into a number.
 90     * @param input to attempt to coerce into a number
 91     * @returns {number} number representation of the input
 92     */
 93    static firstValueAsNumber(input: any): number;
 94    /**
 95     * Takes any input type and will throw a REF_ERROR or coerce it into a string.
 96     * @param input to attempt to coerce into a string
 97     * @returns {number} number representation of the input
 98     */
 99    static firstValueAsString(input: any): string;
100    /**
101     * Returns the first value that is not of the type array. Will throw RefError if any empty arrays are passed in.
102     * @param input to retrieve first value of
103     * @returns {any} any non-array value.
104     */
105    static firstValue(input: any): any;
106    /**
107     * Takes any input type and will throw a REF_ERROR or coerce it into a string.
108     * @param input to attempt to coerce into a string
109     * @returns {number} number representation of the input
110     */
111    static firstValueAsBoolean(input: any): boolean;
112    /**
113     * Takes the input type and will throw a REF_ERROR or coerce it into a date number
114     * @param input input to attempt to coerce to a date number
115     * @param coerceBoolean should a boolean be converted
116     * @returns {number} representing a date
117     */
118    static firstValueAsDateNumber(input: any, coerceBoolean?: boolean): number;
119    /**
120     * Takes the input type and will throw a REF_ERROR or coerce it into a time number
121     * @param input input to attempt to coerce to a time number
122     * @returns {number} representing time of day
123     */
124    static firstValueAsTimestampNumber(input: any): number;
125    /**
126     * Convert a value to date number if possible.
127     * @param value to convert
128     * @param coerceBoolean should a boolean be converted
129     * @returns {number} date
130     */
131    static valueToDateNumber(value: any, coerceBoolean?: boolean): number;
132    /**
133     * Converts a moment to a date number.
134     * @param m to convert
135     * @returns {number} date
136     */
137    static momentToNumber(m: moment.Moment): number;
138    /**
139     * Converts a moment to a date number, floored to the whole day date.
140     * @param m to convert
141     * @returns {number} date
142     */
143    static momentToDayNumber(m: moment.Moment): number;
144    /**
145     * Converts a number to moment.
146     * @param n to convert
147     * @returns {Moment} date
148     */
149    static numberToMoment(n: number): moment.Moment;
150    /**
151     * Converts a number to moment while preserving the decimal part of the number.
152     * @param n to convert
153     * @returns {Moment} date
154     */
155    static decimalNumberToMoment(n: number): moment.Moment;
156    /**
157     * Using timestamp units, create a time number between 0 and 1, exclusive on end.
158     * @param hours
159     * @param minutes
160     * @param seconds
161     * @returns {number} representing time of day between 0 and 1, exclusive on end.
162     */
163    static unitsToTimeNumber(hours: number, minutes: number, seconds: number): number;
164}
165/**
166 * Catches divide by zero situations and throws them as errors
167 * @param n number to check
168 * @returns {number} n as long as it's not zero.
169 */
170declare let checkForDevideByZero: (n: number) => number;
171export { TypeConverter, checkForDevideByZero };