@liquid-js/lyr-date-fns 0.0.0-stage → 22.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +23 -0
- package/README.md +36 -2
- package/fesm2022/liquid-js-lyr-date-fns.mjs +125 -0
- package/fesm2022/liquid-js-lyr-date-fns.mjs.map +1 -0
- package/package.json +41 -3
- package/types/liquid-js-lyr-date-fns.d.ts +38 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Akveo.
|
|
4
|
+
Copyright (c) 2026 Liquid-JS and contributors.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lyra date-fns adapter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/Liquid-JS/lyra/blob/master/LICENSE.txt)
|
|
4
|
+
[](https://www.npmjs.com/package/@liquid-js/lyr-date-fns)
|
|
5
|
+
[](https://www.npmjs.com/package/@liquid-js/lyr-date-fns)
|
|
6
|
+
|
|
7
|
+
A date service for Lyra's calendars and datepickers that formats and parses native dates with date-fns.
|
|
8
|
+
|
|
9
|
+
## Quick links
|
|
10
|
+
|
|
11
|
+
- [Datepicker](https://liquid-js.github.io/lyra/components/forms/datepicker/overview/)
|
|
12
|
+
- [Documentation](https://liquid-js.github.io/lyra/)
|
|
13
|
+
|
|
14
|
+
### Installing
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install --save @liquid-js/lyr-date-fns date-fns
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Provide the date service
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { provideNbTheme } from '@liquid-js/lyr-core'
|
|
24
|
+
import { provideNbDateFnsDate } from '@liquid-js/lyr-date-fns'
|
|
25
|
+
|
|
26
|
+
bootstrapApplication(AppComponent, {
|
|
27
|
+
providers: [
|
|
28
|
+
provideNbTheme(),
|
|
29
|
+
provideNbDateFnsDate({
|
|
30
|
+
format: 'dd.MM.yyyy'
|
|
31
|
+
})
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`format` is the format datepickers use when they set none. `parseOptions`, `formatOptions` and `getWeekOptions` pass
|
|
37
|
+
date-fns's options, such as the locale.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { NgModule, Service, inject, makeEnvironmentProviders } from "@angular/core";
|
|
3
|
+
import { NB_DATE_SERVICE_OPTIONS, NbDateService, NbNativeDateService } from "@liquid-js/lyr-core";
|
|
4
|
+
import { format, getWeek, parse } from "date-fns";
|
|
5
|
+
var NbDateFnsDateService = class NbDateFnsDateService extends NbNativeDateService {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.options = inject(NB_DATE_SERVICE_OPTIONS, { optional: true }) || {};
|
|
9
|
+
}
|
|
10
|
+
format(date, format$1) {
|
|
11
|
+
if (date) return format(date, this.resolveFormat(format$1), this.options.formatOptions);
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
parse(date, format) {
|
|
15
|
+
const resolved = format || this.options.format;
|
|
16
|
+
return resolved ? parse(date, resolved, /* @__PURE__ */ new Date(), this.options.parseOptions) : /* @__PURE__ */ new Date(NaN);
|
|
17
|
+
}
|
|
18
|
+
getId() {
|
|
19
|
+
return "date-fns";
|
|
20
|
+
}
|
|
21
|
+
resolveFormat(format) {
|
|
22
|
+
const resolved = format || this.options.format;
|
|
23
|
+
if (resolved === void 0) throw new Error("format is required when using NbDateFnsDateModule");
|
|
24
|
+
return resolved;
|
|
25
|
+
}
|
|
26
|
+
getWeekNumber(date) {
|
|
27
|
+
return getWeek(date, this.options.getWeekOptions);
|
|
28
|
+
}
|
|
29
|
+
getDateFormat() {
|
|
30
|
+
return "yyyy-MM-dd";
|
|
31
|
+
}
|
|
32
|
+
static {
|
|
33
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
34
|
+
minVersion: "12.0.0",
|
|
35
|
+
version: "22.3.0",
|
|
36
|
+
ngImport: i0,
|
|
37
|
+
type: NbDateFnsDateService,
|
|
38
|
+
deps: [],
|
|
39
|
+
target: i0.ɵɵFactoryTarget.Service
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
static {
|
|
43
|
+
this.ɵprov = i0.ɵɵngDeclareService({
|
|
44
|
+
minVersion: "22.0.0",
|
|
45
|
+
version: "22.3.0",
|
|
46
|
+
ngImport: i0,
|
|
47
|
+
type: NbDateFnsDateService,
|
|
48
|
+
autoProvided: false
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
53
|
+
minVersion: "12.0.0",
|
|
54
|
+
version: "22.3.0",
|
|
55
|
+
ngImport: i0,
|
|
56
|
+
type: NbDateFnsDateService,
|
|
57
|
+
decorators: [{
|
|
58
|
+
type: Service,
|
|
59
|
+
args: [{ autoProvided: false }]
|
|
60
|
+
}]
|
|
61
|
+
});
|
|
62
|
+
const dateFnsServiceProvider = {
|
|
63
|
+
provide: NbDateService,
|
|
64
|
+
useClass: NbDateFnsDateService
|
|
65
|
+
};
|
|
66
|
+
function provideNbDateFnsDate(options = {}) {
|
|
67
|
+
return makeEnvironmentProviders([dateFnsServiceProvider, {
|
|
68
|
+
provide: NB_DATE_SERVICE_OPTIONS,
|
|
69
|
+
useValue: options
|
|
70
|
+
}]);
|
|
71
|
+
}
|
|
72
|
+
var NbDateFnsDateModule = class NbDateFnsDateModule {
|
|
73
|
+
static forRoot(options) {
|
|
74
|
+
return {
|
|
75
|
+
ngModule: NbDateFnsDateModule,
|
|
76
|
+
providers: [provideNbDateFnsDate(options)]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
static forChild(options) {
|
|
80
|
+
return {
|
|
81
|
+
ngModule: NbDateFnsDateModule,
|
|
82
|
+
providers: [provideNbDateFnsDate(options)]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
static {
|
|
86
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
87
|
+
minVersion: "12.0.0",
|
|
88
|
+
version: "22.3.0",
|
|
89
|
+
ngImport: i0,
|
|
90
|
+
type: NbDateFnsDateModule,
|
|
91
|
+
deps: [],
|
|
92
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
static {
|
|
96
|
+
this.ɵmod = i0.ɵɵngDeclareNgModule({
|
|
97
|
+
minVersion: "14.0.0",
|
|
98
|
+
version: "22.3.0",
|
|
99
|
+
ngImport: i0,
|
|
100
|
+
type: NbDateFnsDateModule
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static {
|
|
104
|
+
this.ɵinj = i0.ɵɵngDeclareInjector({
|
|
105
|
+
minVersion: "12.0.0",
|
|
106
|
+
version: "22.3.0",
|
|
107
|
+
ngImport: i0,
|
|
108
|
+
type: NbDateFnsDateModule,
|
|
109
|
+
providers: [dateFnsServiceProvider]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
114
|
+
minVersion: "12.0.0",
|
|
115
|
+
version: "22.3.0",
|
|
116
|
+
ngImport: i0,
|
|
117
|
+
type: NbDateFnsDateModule,
|
|
118
|
+
decorators: [{
|
|
119
|
+
type: NgModule,
|
|
120
|
+
args: [{ providers: [dateFnsServiceProvider] }]
|
|
121
|
+
}]
|
|
122
|
+
});
|
|
123
|
+
export { NbDateFnsDateModule, NbDateFnsDateService, provideNbDateFnsDate };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=liquid-js-lyr-date-fns.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-js-lyr-date-fns.mjs","names":["format","formatDate"],"sources":["../../../packages/date-fns/src/services/date-fns-date.service.ts","../../../packages/date-fns/src/date-fns.module.ts"],"sourcesContent":["import { inject, Service } from '@angular/core'\n\nimport { NB_DATE_SERVICE_OPTIONS, NbNativeDateService } from '@liquid-js/lyr-core'\n\nimport { format as formatDate, getWeek, parse } from 'date-fns'\n\nexport interface NbDateFnsOptions {\n /** The format `format` and `parse` use when they're given none; without it they need one every time. */\n format: string\n /** date-fns's options for `parse`, `format` and `getWeek`, e.g. the locale. */\n parseOptions: {}\n formatOptions: {}\n getWeekOptions: {}\n}\n\n@Service({ autoProvided: false })\nexport class NbDateFnsDateService extends NbNativeDateService {\n protected options: Partial<NbDateFnsOptions> = inject(NB_DATE_SERVICE_OPTIONS, { optional: true }) || {}\n\n override format(date: Date, format: string): string {\n if (date) {\n return formatDate(date, this.resolveFormat(format), this.options.formatOptions)\n }\n\n return ''\n }\n\n override parse(date: string, format: string): Date {\n const resolved = format || this.options.format\n // Without a format the text can't be parsed; date-fns returns an invalid date for that, and so does this.\n return resolved ? parse(date, resolved, new Date(), this.options.parseOptions) : new Date(NaN)\n }\n\n override getId(): string {\n return 'date-fns'\n }\n\n /** The format given, or the options'; throws without either. */\n protected resolveFormat(format: string): string {\n const resolved = format || this.options.format\n if (resolved === undefined) {\n throw new Error('format is required when using NbDateFnsDateModule')\n }\n return resolved\n }\n\n override getWeekNumber(date: Date): number {\n return getWeek(date, this.options.getWeekOptions)\n }\n\n override getDateFormat(): string {\n // `yyyy` is the calendar year; `YYYY` is the week-numbering year, which date-fns rejects by default.\n return 'yyyy-MM-dd'\n }\n}\n","import { ModuleWithProviders, NgModule, EnvironmentProviders, makeEnvironmentProviders } from '@angular/core'\n\nimport { NB_DATE_SERVICE_OPTIONS, NbDateService } from '@liquid-js/lyr-core'\nimport { NbDateFnsOptions, NbDateFnsDateService } from './services/date-fns-date.service'\n\nconst dateFnsServiceProvider = { provide: NbDateService, useClass: NbDateFnsDateService }\n\n/**\n * Replaces the native date service with the date-fns one, in place of `NbDateFnsDateModule.forRoot()` or\n * `forChild()`.\n */\nexport function provideNbDateFnsDate(options: Partial<NbDateFnsOptions> = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n dateFnsServiceProvider,\n { provide: NB_DATE_SERVICE_OPTIONS, useValue: options }\n ])\n}\n\n@NgModule({\n providers: [dateFnsServiceProvider]\n})\nexport class NbDateFnsDateModule {\n static forRoot(options: Partial<NbDateFnsOptions>): ModuleWithProviders<NbDateFnsDateModule> {\n return { ngModule: NbDateFnsDateModule, providers: [provideNbDateFnsDate(options)] }\n }\n\n static forChild(options: Partial<NbDateFnsOptions>): ModuleWithProviders<NbDateFnsDateModule> {\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AAqC,CAAA,GAAE;CACxE,OAAO,yBAAyB,CAC5B,wBACA;EAAE,SAAS;EAAyB,UAAU;CAAO,CACxD,CAAA;AACL;AAKA,IAAa,sBAAb,MAAa,oBAAmB;CAC5B,OAAO,QAAQ,SAAkC;EAC7C,OAAO;GAAE,UAAU;GAAqB,WAAW,CAAC,qBAAqB,OAAO,CAAC;EAAC;CACtF;CAEA,OAAO,SAAS,SAAkC;EAC9C,OAAO;GAAE,UAAU;GAAqB,WAAW,CAAC,qBAAqB,OAAO,CAAC;EAAC;CACtF;CAPS;EAAA,KAAA,OAAA,GAAA,mBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAmB,MAAA,CAAA;GAAA,QAAA,GAAA,gBAAA;EAAA,CAAA;CAAA;CAAnB;EAAA,KAAA,OAAA,GAAA,oBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;EAAmB,CAAA;CAAA;CAAnB;EAAA,KAAA,OAAA,GAAA,oBAAA;GAAA,YAAA;GAAA,SAAA;GAAA,UAAA;GAAA,MAAA;GAAmB,WAFjB,CAAC,sBAAsB;EAAC,CAAA;CAAA;;AAE1B,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAmB,YAAA,CAAA;EAH/B,MAAA;EAAS,MAAA,CAAA,EACN,WAAW,CAAC,sBAAsB,EACrC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liquid-js/lyr-date-fns",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"description": "date-fns date adapter for Lyra",
|
|
4
|
+
"bugs": {
|
|
5
|
+
"url": "https://github.com/Liquid-JS/lyra/issues"
|
|
6
|
+
},
|
|
7
|
+
"version": "22.0.0-alpha.0",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "HitkoDev <development@hitko.si>",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Liquid-JS/lyra.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/Liquid-JS/lyra/tree/master/packages/date-fns#readme",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"angular",
|
|
18
|
+
"typescript",
|
|
19
|
+
"lyra",
|
|
20
|
+
"ui",
|
|
21
|
+
"components",
|
|
22
|
+
"date-fns"
|
|
23
|
+
],
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@angular/core": "^22.0.0",
|
|
26
|
+
"@liquid-js/lyr-core": "^22.0.0",
|
|
27
|
+
"date-fns": "^4.4.0"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"module": "fesm2022/liquid-js-lyr-date-fns.mjs",
|
|
31
|
+
"typings": "types/liquid-js-lyr-date-fns.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
"./package.json": {
|
|
34
|
+
"default": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./types/liquid-js-lyr-date-fns.d.ts",
|
|
38
|
+
"default": "./fesm2022/liquid-js-lyr-date-fns.mjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"tslib": "^2.9.1"
|
|
43
|
+
}
|
|
6
44
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
import { NbNativeDateService } from "@liquid-js/lyr-core";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
import { EnvironmentProviders, ModuleWithProviders } from "@angular/core";
|
|
7
|
+
export interface NbDateFnsOptions {
|
|
8
|
+
/** The format `format` and `parse` use when they're given none; without it they need one every time. */
|
|
9
|
+
format: string;
|
|
10
|
+
/** date-fns's options for `parse`, `format` and `getWeek`, e.g. the locale. */
|
|
11
|
+
parseOptions: {};
|
|
12
|
+
formatOptions: {};
|
|
13
|
+
getWeekOptions: {};
|
|
14
|
+
}
|
|
15
|
+
export declare class NbDateFnsDateService extends NbNativeDateService {
|
|
16
|
+
protected options: Partial<NbDateFnsOptions>;
|
|
17
|
+
format(date: Date, format: string): string;
|
|
18
|
+
parse(date: string, format: string): Date;
|
|
19
|
+
getId(): string;
|
|
20
|
+
/** The format given, or the options'; throws without either. */
|
|
21
|
+
protected resolveFormat(format: string): string;
|
|
22
|
+
getWeekNumber(date: Date): number;
|
|
23
|
+
getDateFormat(): string;
|
|
24
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NbDateFnsDateService, never>;
|
|
25
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Replaces the native date service with the date-fns one, in place of `NbDateFnsDateModule.forRoot()` or
|
|
29
|
+
* `forChild()`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function provideNbDateFnsDate(options?: Partial<NbDateFnsOptions>): EnvironmentProviders;
|
|
32
|
+
export declare class NbDateFnsDateModule {
|
|
33
|
+
static forRoot(options: Partial<NbDateFnsOptions>): ModuleWithProviders<NbDateFnsDateModule>;
|
|
34
|
+
static forChild(options: Partial<NbDateFnsOptions>): ModuleWithProviders<NbDateFnsDateModule>;
|
|
35
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NbDateFnsDateModule, never>;
|
|
36
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<NbDateFnsDateModule, never, never, never>;
|
|
37
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<NbDateFnsDateModule>;
|
|
38
|
+
}
|