Skip to content

Commit fffefd7

Browse files
docs: document format and toString methods
1 parent eac81d1 commit fffefd7

File tree

6 files changed

+119
-2
lines changed

6 files changed

+119
-2
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import { parseNumber } from '@telerik/kendo-intl';
7777

7878
parseNumber("12.22"); // 12.22
7979
parseNumber("1.212,22 €", "de"); // 1212.22
80-
parseNumber("10.22 %"); // 0.1022
80+
parseNumber("10.22 %"); // 0.1022
8181
parseNumber("1,0000123e+4", "bg"); // 10000.123
8282
```
8383

@@ -105,6 +105,22 @@ formatNumber(2345678, "##,#.00"); // 2,345,678.00
105105

106106
For more examples and available configuration options, refer to the article on [number formatting](https://github.com/telerik/kendo-intl/blob/master/docs/num-formatting/index.md).
107107

108+
### General Formatting
109+
110+
Provides methods for placeholder and type independent formatting using the locale specific settings.
111+
112+
```js
113+
import { format, toString } from '@telerik/kendo-intl';
114+
115+
format('Date: {0:d} - Price: {1:c}', [new Date(), 10.5], "en") // Date: 1/5/2017 - Price: $10.50
116+
117+
toString(10.5, "c", "bg"); // 10,50 лв.
118+
119+
toString(new Date(), "d"); // 1/5/2017
120+
```
121+
122+
For more examples and available configuration options, refer to the article on [general formatting](https://github.com/telerik/kendo-intl/blob/master/docs/general-formatting/index.md).
123+
108124
## Installation
109125

110126
The Internationalization library is published as a [scoped NPM package](https://docs.npmjs.com/misc/scope) in the [NPMJS Telerik account](https://www.npmjs.com/~telerik).

docs/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Errors
33
page_title: Errors | Kendo UI Internationalization Package
44
description: "List of possible exceptions that the package could throw."
55
slug: errors_internalization_kendoui
6-
position: 6
6+
position: 7
77
---
88

99
# Errors list

docs/general-formatting/_meta.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: General Formatting
2+
position: 6

docs/general-formatting/api.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: General Formatting API
3+
page_title: General Formatting API | Kendo UI Internationalization
4+
description: "Learn about the exported methods from the Kendo UI Internationalization General Formatting module."
5+
slug: dateformatapi_internalization
6+
position: 2
7+
---
8+
9+
# General Formatting API
10+
11+
Provides information about the exported methods from the format module.
12+
13+
## Methods
14+
15+
#### format
16+
17+
Replaces the format string placeholders with the provided values based on the index.
18+
19+
## Parameters
20+
21+
#### formatString `String`
22+
23+
The format string.
24+
25+
#### values `Array`
26+
27+
The values that should be replaced in the format string
28+
29+
#### locale `String`
30+
31+
Optional locale id. If not specified 'en' will be used.
32+
33+
## Return Value
34+
35+
#### Returns `String`
36+
37+
The format string with replaced formatted values.
38+
39+
#### toString
40+
41+
Formats dates and numbers based on the specified format and locale
42+
43+
## Parameters
44+
45+
#### value `String|Date|Number`
46+
47+
The value to be formatted.
48+
49+
#### format `String|Object`
50+
51+
A string representing a predefined or custom date or number format, or a configuration object.
52+
53+
#### locale `String`
54+
55+
Optional locale id. If not specified 'en' will be used.
56+
57+
## Return Value
58+
59+
#### Returns `String`
60+
61+
The formatted value.

docs/general-formatting/index.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: General Formatting
3+
page_title: General Formatting | Kendo UI Internationalization
4+
description: "Use the formatting capabilities of the format and toString methods when working with the Kendo UI Internationalization package."
5+
slug: generalformatting_internalization
6+
position: 1
7+
---
8+
9+
# General Formatting
10+
11+
Provides methods for applying placeholder format and type independent value formatting using the locale specific settings.
12+
13+
## Placeholder formatting
14+
15+
The `format` method can be used to replace the format string placeholders(`{index}`) with the provided values based on the index.
16+
A specific format can also be specified for `Date` and `Number` values by adding `:format` after the index.
17+
18+
import { format } from '@telerik/kendo-intl';
19+
20+
format('Date: {0:d} - Price: {1:c}', [new Date(), 10.5], "en"); // Date: 1/5/2017 - Price: $10.50
21+
22+
## Type independent formatting
23+
24+
The `toString` method can be used to format both `Date` and `Number` values using the locale specific settings. If a string is passed as value then it will be returned without modification.
25+
26+
import { toString } from '@telerik/kendo-intl';
27+
28+
toString(new Date(), "d", "en"); // 1/5/2017
29+
30+
toString(10.5, "c", "bg"); // 10,50 лв.
31+
32+
## Suggested Links
33+
34+
* [General Formatting API]({% slug generalformatapi_internalization %})
35+
* [Date Formatting]({% slug dateformatting_internalization %})
36+
* [Number Formatting]({% slug numbeformatting_internalization %})

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The Date Parsing and Date Formatting modules provide methods for parsing and for
1818

1919
The Number Parsing and Number Formatting modules provide methods for parsing and formatting of numbers.
2020

21+
The General Formatting module provides methods for placeholder and type independent formatting.
22+
2123
## Suggested Links
2224

2325
* [Get Started with CLDR]({% slug cldrdata_overview_internalization %})

0 commit comments

Comments
 (0)