UNPKG

3.9 kBTypeScriptView Raw
1export as namespace numeral;
2
3/**
4 * A javascript library for formatting and manipulating numbers.
5 */
6declare function numeral(input?: any): numeral.Numeral;
7
8type VERSION = "2.0.6";
9
10declare namespace numeral {
11 /** compare numeral object */
12 function isNumeral(value: any): boolean;
13
14 const version: VERSION;
15 const options: NumeralJSOptions;
16 /**
17 * Object with all loaded locales
18 */
19 const locales: NumeralJSLocales;
20
21 /**
22 * Object with all loaded formats
23 */
24 const formats: NumeralJSFormats;
25
26 /**
27 * Object with utility functions
28 */
29 const _: NumeralJSUtils;
30
31 /**
32 * This function sets the current locale. If no arguments are passed in,
33 * it will simply return the current global locale key.
34 */
35 function locale(key?: string): string;
36
37 /**
38 * This function provides access to the loaded locale data. If
39 * no arguments are passed in, it will simply return the current
40 * global locale object.
41 *
42 * @param key Locale key, e.g 'es' for a spanish locale definition
43 */
44 function localeData(key?: string): NumeralJSLocale;
45
46 /**
47 * This function resets the configuration to all the defaults
48 */
49 function reset(): void;
50
51 function zeroFormat(format: string): void;
52 function nullFormat(format: string): void;
53 function defaultFormat(format: string): void;
54 /**
55 * Registers a language definition or a custom format definition.
56 *
57 * @param what Allowed values are: either 'format' or 'locale'
58 * @param key The key of the registerd type, e.g. 'de' for a german locale definition
59 * @param value The locale definition or the format definitiion
60 */
61 function register(
62 what: RegisterType,
63 key: string,
64 value: NumeralJSLocale | NumeralJSFormat,
65 ): NumeralJSLocale | NumeralJSFormat;
66
67 function validate(value: any, culture: any): boolean;
68
69 const fn: Numeral["prototype"];
70
71 // http://numeraljs.com/#use-it
72 class Numeral {
73 constructor(input: any, value: number);
74 prototype: Numeral;
75 clone(): Numeral;
76 format(inputString?: string, roundingFunction?: RoundingFunction): string;
77 value(): number | null;
78 input(): any;
79 set(value: any): Numeral;
80 add(value: any): Numeral;
81 subtract(value: any): Numeral;
82 multiply(value: any): Numeral;
83 divide(value: any): Numeral;
84 difference(value: any): number;
85 }
86
87 // http://numeraljs.com/#locales
88 interface NumeralJSLocale {
89 delimiters: {
90 thousands: string;
91 decimal: string;
92 };
93 abbreviations: {
94 thousand: string;
95 million: string;
96 billion: string;
97 trillion: string;
98 };
99 ordinal(num: number): string;
100 currency: {
101 symbol: string;
102 };
103 }
104
105 interface NumeralJSLocales {
106 [id: string]: NumeralJSLocale;
107 }
108
109 interface NumeralJSOptions {
110 currentLocale: string;
111 zeroFormat: string;
112 nullFormat: string;
113 defaultFormat: string;
114 scalePercentBy100: boolean;
115 }
116
117 type RoundingFunction = (value: number) => number;
118
119 // http://numeraljs.com/#custom-formats
120 interface NumeralJSFormat {
121 regexps: {
122 format: RegExp;
123 unformat: RegExp;
124 };
125 format: (value: any, format: string, roundingFunction: RoundingFunction) => string;
126 unformat: (value: string) => number;
127 }
128
129 interface NumeralJSFormats {
130 [id: string]: NumeralJSFormat;
131 }
132
133 interface NumeralJSUtils {
134 numberToFormat: (value: number, format: string, roundingFunction?: RoundingFunction) => string;
135 stringToNumber: (string: string) => number;
136 }
137
138 type RegisterType = "format" | "locale";
139}
140
141export = numeral;