-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
75 lines (68 loc) 路 1.65 KB
/
Copy pathindex.d.ts
File metadata and controls
75 lines (68 loc) 路 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Language options for number-to-words conversion
*/
export type Language = 'id' | 'en' | 'ms';
/**
* Number type options
*/
export type NumberType = 'cardinal' | 'ordinal';
/**
* Supported currency codes
*/
export type Currency = 'IDR' | 'MYR' | 'USD' | string;
/**
* Options for the toWords function
*/
export interface ToWordsOptions {
/**
* Language for conversion
* - 'id': Bahasa Indonesia
* - 'en': English
* - 'ms': Bahasa Malaysia
* @default 'id'
*/
lang?: Language;
/**
* Currency code (e.g., 'IDR', 'MYR', 'USD')
* When specified, adds currency label to the result
*/
currency?: Currency;
/**
* Type of number representation
* - 'cardinal': Standard number (e.g., "one", "satu")
* - 'ordinal': Ordinal number (e.g., "first", "pertama")
* @default 'cardinal'
*/
type?: NumberType;
}
/**
* Convert numbers to words in Indonesian, Malaysian, or English
*
* @param num - Number to convert (can be string for decimal support)
* @param options - Conversion options
* @returns The number converted to words
*
* @example
* ```ts
* // CommonJS
* const { toWords } = require('number-to-words-id');
*
* // ES Modules
* import { toWords } from 'number-to-words-id';
*
* toWords(12500, { lang: 'id' })
* // "dua belas ribu lima ratus"
*
* toWords(50000, { lang: 'id', currency: 'IDR' })
* // "lima puluh ribu rupiah"
*
* toWords('12.34', { lang: 'id' })
* // "dua belas koma tiga empat"
*
* toWords(1, { lang: 'id', type: 'ordinal' })
* // "pertama"
* ```
*/
export function toWords(num: number | string, options?: ToWordsOptions): string;
// CommonJS compatibility
export = { toWords };