Skip to content

Commit e74a3e7

Browse files
committed
Update documentation for square bracket escaping
Add examples demonstrating how to escape square brackets in format strings and update code examples to use the new feature.
1 parent ed94bc7 commit e74a3e7

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

docs/api/compile.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ dates.forEach(date => {
7676
import { compile, format } from 'date-and-time';
7777

7878
class Logger {
79-
private timestampPattern = compile('YYYY-MM-DD HH:mm:ss.SSS');
80-
79+
private timestampPattern = compile('\\[YYYY-MM-DD HH:mm:ss.SSS\\]');
80+
8181
log(level: string, message: string) {
8282
const timestamp = format(new Date(), this.timestampPattern);
83-
console.log(`[${timestamp}] ${level.toUpperCase()}: ${message}`);
83+
console.log(`${timestamp} ${level.toUpperCase()}: ${message}`);
8484
}
8585
}
8686

docs/api/format.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ format(date, 'YYYY-MM-DD[T]HH:mm:ss[Z]');
274274

275275
format(date, '[Report generated on] YYYY/MM/DD [at] HH:mm');
276276
// => Report generated on 2025/08/23 at 14:30
277+
278+
// Escape square brackets to output them literally
279+
format(date, '\\[YYYY-MM-DD HH:mm:ss\\]');
280+
// => [2025-08-23 14:30:45]
277281
```
278282

279283
### Complex Localized Formatting

docs/api/parse.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ parse('2025-08-23T14:30:45Z', 'YYYY-MM-DD[T]HH:mm:ss[Z]');
383383

384384
parse('Report generated on 2025/08/23 at 14:30', '[Report generated on] YYYY/MM/DD [at] HH:mm');
385385
// => Fri Aug 23 2025 14:30:00 GMT+0900
386+
387+
// Escape square brackets to parse them from input string
388+
parse('[2025-08-23 14:30:45]', '\\[YYYY-MM-DD HH:mm:ss\\]');
389+
// => Fri Aug 23 2025 14:30:45 GMT+0900
386390
```
387391

388392
### Wildcard Parsing

docs/guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
- **Timezone Support** - Comprehensive timezone data from timezonedb
6060
- **Locale Support** - 40+ languages with native formatting
61-
- **Plugin System** - Extensible with microsecond/nanosecond precision
61+
- **Plugin System** - Extend formatters and parsers
6262
- **Duration Objects** - Rich time difference calculations
6363

6464
## Version 4.x Highlights

0 commit comments

Comments
 (0)