Skip to content

Commit 2ffaa04

Browse files
Merge pull request #107 from knowledgecode/develop
Support literal square brackets in format strings
2 parents e2066ae + 5154271 commit 2ffaa04

File tree

10 files changed

+264
-212
lines changed

10 files changed

+264
-212
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

eslint.config.ts renamed to eslint.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
// @ts-check
2+
import { defineConfig } from 'eslint/config';
13
import tseslint from 'typescript-eslint';
24

3-
export default tseslint.config(
4-
...tseslint.configs.strict,
5-
...tseslint.configs.stylistic,
5+
export default defineConfig(
6+
tseslint.configs.strict,
7+
tseslint.configs.stylistic,
68
{
79
files: ['**/*.ts'],
810
languageOptions: {
911
ecmaVersion: 2021,
1012
sourceType: 'module',
1113
globals: {
14+
process: true
1215
},
1316
parserOptions: {
1417
project: './tsconfig.json',

0 commit comments

Comments
 (0)