@ts-charts/time 0.1.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.md +21 -0
- package/README.md +153 -0
- package/dist/day.d.ts +6 -0
- package/dist/duration.d.ts +7 -0
- package/dist/hour.d.ts +4 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +1 -0
- package/dist/interval.d.ts +12 -0
- package/dist/millisecond.d.ts +2 -0
- package/dist/minute.d.ts +4 -0
- package/dist/month.d.ts +4 -0
- package/dist/second.d.ts +2 -0
- package/dist/ticks.d.ts +4 -0
- package/dist/week.d.ts +28 -0
- package/dist/year.d.ts +4 -0
- package/package.json +24 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![GitHub Actions][github-actions-src]][github-actions-href]
|
|
5
|
+
[![Commitizen friendly][commitizen-src]][commitizen-href]
|
|
6
|
+
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
|
+
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
8
|
+
|
|
9
|
+
# ts-charts
|
|
10
|
+
|
|
11
|
+
> A complete TypeScript rewrite of D3.js โ fully typed, zero dependencies, Bun-first.
|
|
12
|
+
|
|
13
|
+
All 30 D3.js packages, rewritten from the ground up in TypeScript with `isolatedDeclarations` support. Ships as a single umbrella package or 30+ individually installable sub-packages.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- ๐ท **Fully Typed** โ strict TypeScript with `isolatedDeclarations: true`, no `any` leaks
|
|
18
|
+
- ๐ฆ **Zero Dependencies** โ no external runtime dependencies, everything inlined
|
|
19
|
+
- โก **Bun-First** โ optimized for Bun, works in all modern browsers
|
|
20
|
+
- ๐ณ **Tree-Shakeable** โ ESM-only, import only what you need
|
|
21
|
+
- ๐งช **3,500+ Tests** โ comprehensive test suite ported from D3, all passing
|
|
22
|
+
- ๐ฏ **D3 API Compatible** โ drop-in replacement for D3.js
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# install the umbrella package (everything)
|
|
28
|
+
bun add ts-charts
|
|
29
|
+
|
|
30
|
+
# or install individual packages
|
|
31
|
+
bun add @ts-charts/scale
|
|
32
|
+
bun add @ts-charts/selection
|
|
33
|
+
bun add @ts-charts/shape
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// import everything
|
|
40
|
+
import { scaleLinear, line, select } from 'ts-charts'
|
|
41
|
+
|
|
42
|
+
// or import from individual packages
|
|
43
|
+
import { scaleLinear } from '@ts-charts/scale'
|
|
44
|
+
import { line } from '@ts-charts/shape'
|
|
45
|
+
import { select } from '@ts-charts/selection'
|
|
46
|
+
|
|
47
|
+
// create a linear scale
|
|
48
|
+
const x = scaleLinear()
|
|
49
|
+
.domain([0, 100])
|
|
50
|
+
.range([0, 960])
|
|
51
|
+
|
|
52
|
+
// create a line generator
|
|
53
|
+
const myLine = line()
|
|
54
|
+
.x((d: [number, number]) => x(d[0]))
|
|
55
|
+
.y((d: [number, number]) => d[1])
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Packages
|
|
59
|
+
|
|
60
|
+
| Package | Description |
|
|
61
|
+
|---------|-------------|
|
|
62
|
+
| `@ts-charts/array` | Array manipulation, statistics, histograms, bisection |
|
|
63
|
+
| `@ts-charts/axis` | SVG axis generators for scales |
|
|
64
|
+
| `@ts-charts/brush` | 1D and 2D brush selections |
|
|
65
|
+
| `@ts-charts/chord` | Chord diagram layout and ribbon generator |
|
|
66
|
+
| `@ts-charts/color` | Color spaces: RGB, HSL, Lab, HCL, Cubehelix |
|
|
67
|
+
| `@ts-charts/contour` | Contour polygons and density estimation |
|
|
68
|
+
| `@ts-charts/delaunay` | Delaunay triangulation and Voronoi diagrams |
|
|
69
|
+
| `@ts-charts/dispatch` | Named event dispatching |
|
|
70
|
+
| `@ts-charts/drag` | Drag-and-drop interaction |
|
|
71
|
+
| `@ts-charts/dsv` | CSV and TSV parsing and formatting |
|
|
72
|
+
| `@ts-charts/ease` | Easing functions for transitions |
|
|
73
|
+
| `@ts-charts/fetch` | Convenience wrappers for the Fetch API |
|
|
74
|
+
| `@ts-charts/force` | Force-directed graph layout |
|
|
75
|
+
| `@ts-charts/format` | Number formatting (SI, fixed, currency, etc.) |
|
|
76
|
+
| `@ts-charts/geo` | Geographic projections and path generators |
|
|
77
|
+
| `@ts-charts/hierarchy` | Tree, treemap, pack, and partition layouts |
|
|
78
|
+
| `@ts-charts/interpolate` | Value interpolation for animations |
|
|
79
|
+
| `@ts-charts/path` | SVG path serialization |
|
|
80
|
+
| `@ts-charts/polygon` | Polygon area, centroid, convex hull |
|
|
81
|
+
| `@ts-charts/quadtree` | 2D spatial indexing |
|
|
82
|
+
| `@ts-charts/random` | Random number generators for various distributions |
|
|
83
|
+
| `@ts-charts/scale` | Scales: linear, log, ordinal, time, etc. |
|
|
84
|
+
| `@ts-charts/scale-chromatic` | Color schemes: sequential, diverging, categorical |
|
|
85
|
+
| `@ts-charts/selection` | DOM selection and manipulation |
|
|
86
|
+
| `@ts-charts/shape` | Shape generators: line, area, arc, pie, stack |
|
|
87
|
+
| `@ts-charts/time` | Time intervals and rounding |
|
|
88
|
+
| `@ts-charts/time-format` | Date/time parsing and formatting |
|
|
89
|
+
| `@ts-charts/timer` | Efficient animation scheduling via `requestAnimationFrame` |
|
|
90
|
+
| `@ts-charts/transition` | Animated transitions on selections |
|
|
91
|
+
| `@ts-charts/zoom` | Pan and zoom interaction |
|
|
92
|
+
|
|
93
|
+
## Testing
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
bun test
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Changelog
|
|
100
|
+
|
|
101
|
+
Please see our [releases][releases-href] page for more information on what has changed recently.
|
|
102
|
+
|
|
103
|
+
## Contributing
|
|
104
|
+
|
|
105
|
+
Please see [CONTRIBUTING][contributing-href] for details.
|
|
106
|
+
|
|
107
|
+
## Community
|
|
108
|
+
|
|
109
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
110
|
+
|
|
111
|
+
[Discussions on GitHub][discussions-href]
|
|
112
|
+
|
|
113
|
+
For casual chit-chat with others using this package:
|
|
114
|
+
|
|
115
|
+
[Join the Stacks Discord Server][discord-href]
|
|
116
|
+
|
|
117
|
+
## Postcardware
|
|
118
|
+
|
|
119
|
+
"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.
|
|
120
|
+
|
|
121
|
+
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States ๐
|
|
122
|
+
|
|
123
|
+
## Sponsors
|
|
124
|
+
|
|
125
|
+
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
|
|
126
|
+
|
|
127
|
+
- [JetBrains][jetbrains-href]
|
|
128
|
+
- [The Solana Foundation][solana-href]
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
The MIT License (MIT). Please see [LICENSE][license-href] for more information.
|
|
133
|
+
|
|
134
|
+
Made with ๐
|
|
135
|
+
|
|
136
|
+
<!-- Badges -->
|
|
137
|
+
[npm-version-src]: https://img.shields.io/npm/v/ts-charts?style=flat-square
|
|
138
|
+
[npm-version-href]: https://npmjs.com/package/ts-charts
|
|
139
|
+
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/ts-charts/ci.yml?style=flat-square&branch=main
|
|
140
|
+
[github-actions-href]: https://github.com/stacksjs/ts-charts/actions?query=workflow%3Aci
|
|
141
|
+
|
|
142
|
+
[commitizen-src]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
|
|
143
|
+
[commitizen-href]: http://commitizen.github.io/cz-cli/
|
|
144
|
+
[releases-href]: https://github.com/stacksjs/ts-charts/releases
|
|
145
|
+
[contributing-href]: .github/CONTRIBUTING.md
|
|
146
|
+
[discussions-href]: https://github.com/stacksjs/ts-charts/discussions
|
|
147
|
+
[discord-href]: https://discord.gg/stacksjs
|
|
148
|
+
[jetbrains-href]: https://www.jetbrains.com/
|
|
149
|
+
[solana-href]: https://solana.com/
|
|
150
|
+
[license-href]: LICENSE.md
|
|
151
|
+
|
|
152
|
+
<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-charts/main?style=flat-square
|
|
153
|
+
[codecov-href]: https://codecov.io/gh/stacksjs/ts-charts -->
|
package/dist/day.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const timeDay: TimeInterval;
|
|
2
|
+
export declare const timeDays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
3
|
+
export declare const utcDay: TimeInterval;
|
|
4
|
+
export declare const utcDays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
5
|
+
export declare const unixDay: TimeInterval;
|
|
6
|
+
export declare const unixDays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const durationSecond: number;
|
|
2
|
+
export declare const durationMinute: number;
|
|
3
|
+
export declare const durationHour: number;
|
|
4
|
+
export declare const durationDay: number;
|
|
5
|
+
export declare const durationWeek: number;
|
|
6
|
+
export declare const durationMonth: number;
|
|
7
|
+
export declare const durationYear: number;
|
package/dist/hour.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const timeHour: TimeInterval;
|
|
2
|
+
export declare const timeHours: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
3
|
+
export declare const utcHour: TimeInterval;
|
|
4
|
+
export declare const utcHours: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type { TimeInterval } from './interval.ts';
|
|
2
|
+
export {
|
|
3
|
+
timeInterval,
|
|
4
|
+
} from './interval.ts';
|
|
5
|
+
export {
|
|
6
|
+
millisecond as utcMillisecond,
|
|
7
|
+
milliseconds as utcMilliseconds,
|
|
8
|
+
millisecond as timeMillisecond,
|
|
9
|
+
milliseconds as timeMilliseconds,
|
|
10
|
+
} from './millisecond.ts';
|
|
11
|
+
export {
|
|
12
|
+
second as utcSecond,
|
|
13
|
+
seconds as utcSeconds,
|
|
14
|
+
second as timeSecond,
|
|
15
|
+
seconds as timeSeconds,
|
|
16
|
+
} from './second.ts';
|
|
17
|
+
export {
|
|
18
|
+
timeMinute,
|
|
19
|
+
timeMinutes,
|
|
20
|
+
utcMinute,
|
|
21
|
+
utcMinutes,
|
|
22
|
+
} from './minute.ts';
|
|
23
|
+
export {
|
|
24
|
+
timeHour,
|
|
25
|
+
timeHours,
|
|
26
|
+
utcHour,
|
|
27
|
+
utcHours,
|
|
28
|
+
} from './hour.ts';
|
|
29
|
+
export {
|
|
30
|
+
timeDay,
|
|
31
|
+
timeDays,
|
|
32
|
+
utcDay,
|
|
33
|
+
utcDays,
|
|
34
|
+
unixDay,
|
|
35
|
+
unixDays,
|
|
36
|
+
} from './day.ts';
|
|
37
|
+
export {
|
|
38
|
+
timeSunday as timeWeek,
|
|
39
|
+
timeSundays as timeWeeks,
|
|
40
|
+
timeSunday,
|
|
41
|
+
timeSundays,
|
|
42
|
+
timeMonday,
|
|
43
|
+
timeMondays,
|
|
44
|
+
timeTuesday,
|
|
45
|
+
timeTuesdays,
|
|
46
|
+
timeWednesday,
|
|
47
|
+
timeWednesdays,
|
|
48
|
+
timeThursday,
|
|
49
|
+
timeThursdays,
|
|
50
|
+
timeFriday,
|
|
51
|
+
timeFridays,
|
|
52
|
+
timeSaturday,
|
|
53
|
+
timeSaturdays,
|
|
54
|
+
utcSunday as utcWeek,
|
|
55
|
+
utcSundays as utcWeeks,
|
|
56
|
+
utcSunday,
|
|
57
|
+
utcSundays,
|
|
58
|
+
utcMonday,
|
|
59
|
+
utcMondays,
|
|
60
|
+
utcTuesday,
|
|
61
|
+
utcTuesdays,
|
|
62
|
+
utcWednesday,
|
|
63
|
+
utcWednesdays,
|
|
64
|
+
utcThursday,
|
|
65
|
+
utcThursdays,
|
|
66
|
+
utcFriday,
|
|
67
|
+
utcFridays,
|
|
68
|
+
utcSaturday,
|
|
69
|
+
utcSaturdays,
|
|
70
|
+
} from './week.ts';
|
|
71
|
+
export {
|
|
72
|
+
timeMonth,
|
|
73
|
+
timeMonths,
|
|
74
|
+
utcMonth,
|
|
75
|
+
utcMonths,
|
|
76
|
+
} from './month.ts';
|
|
77
|
+
export {
|
|
78
|
+
timeYear,
|
|
79
|
+
timeYears,
|
|
80
|
+
utcYear,
|
|
81
|
+
utcYears,
|
|
82
|
+
} from './year.ts';
|
|
83
|
+
export {
|
|
84
|
+
utcTicks,
|
|
85
|
+
utcTickInterval,
|
|
86
|
+
timeTicks,
|
|
87
|
+
timeTickInterval,
|
|
88
|
+
} from './ticks.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var Z=new Date,$=new Date;function l(n,e,a,i){function u(t){let r=t==null?new Date:new Date(+t);return n(r),r}if(u.floor=(t)=>{let r=new Date(+t);return n(r),r},u.ceil=(t)=>{let r=new Date(+t-1);return n(r),e(r,1),n(r),r},u.round=(t)=>{let r=u(t),m=u.ceil(t);return+t-+r<+m-+t?r:m},u.offset=(t,r)=>{let m=new Date(+t);return e(m,r==null?1:Math.floor(r)),m},u.range=(t,r,m)=>{let f=[],o=u.ceil(t),y=m==null?1:Math.floor(m);if(!(o<new Date(+r))||!(y>0))return f;let c;do c=new Date(+o),f.push(c),e(o,y),n(o);while(c<o&&o<new Date(+r));return f},u.filter=(t)=>{return l((r)=>{if(r>=r)while(n(r),!t(r))r.setTime(+r-1)},(r,m)=>{if(r>=r)if(m<0)while(++m<=0)while(e(r,-1),!t(r));else while(--m>=0)while(e(r,1),!t(r));})},a)u.count=(t,r)=>{return Z.setTime(+t),$.setTime(+r),n(Z),n($),Math.floor(a(Z,$))},u.every=(t)=>{return t=Math.floor(t),!isFinite(t)||!(t>0)?null:!(t>1)?u:u.filter(i?(r)=>i(r)%t===0:(r)=>u.count(0,r)%t===0)};return u}var M=l(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>{return+e-+n});M.every=(n)=>{if(n=Math.floor(n),!isFinite(n)||!(n>0))return null;if(!(n>1))return M;return l((e)=>{e.setTime(Math.floor(+e/n)*n)},(e,a)=>{e.setTime(+e+a*n)},(e,a)=>{return(+a-+e)/n})};var _=M.range;var d=1000,s=60000,x=3600000,I=86400000,C=604800000,B=2592000000,W=31536000000;var T=l((n)=>{n.setTime(+n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*d)},(n,e)=>{return(+e-+n)/d},(n)=>{return n.getUTCSeconds()}),z=T.range;var q=l((n)=>{n.setTime(+n-n.getMilliseconds()-n.getSeconds()*d)},(n,e)=>{n.setTime(+n+e*s)},(n,e)=>{return(+e-+n)/s},(n)=>{return n.getMinutes()}),Ln=q.range,K=l((n)=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*s)},(n,e)=>{return(+e-+n)/s},(n)=>{return n.getUTCMinutes()}),Nn=K.range;var E=l((n)=>{n.setTime(+n-n.getMilliseconds()-n.getSeconds()*d-n.getMinutes()*s)},(n,e)=>{n.setTime(+n+e*x)},(n,e)=>{return(+e-+n)/x},(n)=>{return n.getHours()}),Wn=E.range,O=l((n)=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*x)},(n,e)=>{return(+e-+n)/x},(n)=>{return n.getUTCHours()}),qn=O.range;var Y=l((n)=>{n.setHours(0,0,0,0)},(n,e)=>{n.setDate(n.getDate()+e)},(n,e)=>(+e-+n-(e.getTimezoneOffset()-n.getTimezoneOffset())*s)/I,(n)=>n.getDate()-1),Kn=Y.range,j=l((n)=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>{return(+e-+n)/I},(n)=>{return n.getUTCDate()-1}),En=j.range,G=l((n)=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>{return(+e-+n)/I},(n)=>{return Math.floor(+n/I)}),On=G.range;function g(n){return l((e)=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,a)=>{e.setDate(e.getDate()+a*7)},(e,a)=>{return(+a-+e-(a.getTimezoneOffset()-e.getTimezoneOffset())*s)/C})}var k=g(0),nn=g(1),en=g(2),rn=g(3),tn=g(4),on=g(5),un=g(6),an=k.range,Yn=nn.range,Gn=en.range,Fn=rn.range,Vn=tn.range,Jn=on.range,Pn=un.range;function w(n){return l((e)=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,a)=>{e.setUTCDate(e.getUTCDate()+a*7)},(e,a)=>{return(+a-+e)/C})}var v=w(0),mn=w(1),fn=w(2),yn=w(3),cn=w(4),ln=w(5),bn=w(6),sn=v.range,Qn=mn.range,Xn=fn.range,Zn=yn.range,$n=cn.range,Bn=ln.range,Rn=bn.range;var F=l((n)=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>{return e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12},(n)=>{return n.getMonth()}),_n=F.range,V=l((n)=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>{return e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12},(n)=>{return n.getUTCMonth()}),zn=V.range;var H=l((n)=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>{return e.getFullYear()-n.getFullYear()},(n)=>{return n.getFullYear()});H.every=(n)=>{return n=Math.floor(n),!isFinite(n)||!(n>0)?null:l((e)=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,a)=>{e.setFullYear(e.getFullYear()+a*n)})};var jn=H.range,h=l((n)=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>{return e.getUTCFullYear()-n.getUTCFullYear()},(n)=>{return n.getUTCFullYear()});h.every=(n)=>{return n=Math.floor(n),!isFinite(n)||!(n>0)?null:l((e)=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,a)=>{e.setUTCFullYear(e.getUTCFullYear()+a*n)})};var ne=h.range;function p(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function J(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function A(n){let e,a,i;if(n.length!==2)e=p,a=(m,f)=>p(n(m),f),i=(m,f)=>n(m)-f;else e=n===p||n===J?n:ee,a=n,i=n;function u(m,f,o=0,y=m.length){if(o<y){if(e(f,f)!==0)return y;do{let c=o+y>>>1;if(a(m[c],f)<0)o=c+1;else y=c}while(o<y)}return o}function t(m,f,o=0,y=m.length){if(o<y){if(e(f,f)!==0)return y;do{let c=o+y>>>1;if(a(m[c],f)<=0)o=c+1;else y=c}while(o<y)}return o}function r(m,f,o=0,y=m.length){let c=u(m,f,o,y-1);return c>o&&i(m[c-1],f)>-i(m[c],f)?c-1:c}return{left:u,center:r,right:t}}function ee(){return 0}function P(n){return n===null?NaN:+n}var pn=A(p),re=pn.right,te=pn.left,oe=A(P).center;var ue=Dn(dn),ae=Dn(me);function Dn(n){return function(e,a,i=a){if(!((a=+a)>=0))throw RangeError("invalid rx");if(!((i=+i)>=0))throw RangeError("invalid ry");let{data:u,width:t,height:r}=e;if(!((t=Math.floor(t))>=0))throw RangeError("invalid width");if(!((r=Math.floor(r!==void 0?r:u.length/t))>=0))throw RangeError("invalid height");if(!t||!r||!a&&!i)return e;let m=a&&n(a),f=i&&n(i),o=u.slice();if(m&&f)S(m,o,u,t,r),S(m,u,o,t,r),S(m,o,u,t,r),U(f,u,o,t,r),U(f,o,u,t,r),U(f,u,o,t,r);else if(m)S(m,u,o,t,r),S(m,o,u,t,r),S(m,u,o,t,r);else if(f)U(f,u,o,t,r),U(f,o,u,t,r),U(f,u,o,t,r);return e}}function S(n,e,a,i,u){for(let t=0,r=i*u;t<r;)n(e,a,t,t+=i,1)}function U(n,e,a,i,u){for(let t=0,r=i*u;t<i;++t)n(e,a,t,t+r,i)}function me(n){let e=dn(n);return(a,i,u,t,r)=>{u<<=2,t<<=2,r<<=2,e(a,i,u+0,t+0,r),e(a,i,u+1,t+1,r),e(a,i,u+2,t+2,r),e(a,i,u+3,t+3,r)}}function dn(n){let e=Math.floor(n);if(e===n)return fe(n);let a=n-e,i=2*n+1;return(u,t,r,m,f)=>{if(!((m-=f)>=r))return;let o=e*t[r],y=f*e,c=y+f;for(let b=r,D=r+y;b<D;b+=f)o+=t[Math.min(m,b)];for(let b=r,D=m;b<=D;b+=f)o+=t[Math.min(m,b+y)],u[b]=(o+a*(t[Math.max(r,b-c)]+t[Math.min(m,b+c)]))/i,o-=t[Math.max(r,b-y)]}}function fe(n){let e=2*n+1;return(a,i,u,t,r)=>{if(!((t-=r)>=u))return;let m=n*i[u],f=r*n;for(let o=u,y=u+f;o<y;o+=r)m+=i[Math.min(t,o)];for(let o=u,y=t;o<=y;o+=r)m+=i[Math.min(t,o+f)],a[o]=m/e,m-=i[Math.max(u,o-f)]}}var In=Array.prototype,pe=In.slice,Yr=In.map;var De=Math.sqrt(50),de=Math.sqrt(10),xe=Math.sqrt(2);function Tn(n,e,a){let i=(e-n)/Math.max(0,a),u=Math.floor(Math.log10(i)),t=i/Math.pow(10,u),r=t>=De?10:t>=de?5:t>=xe?2:1,m,f,o;if(u<0){if(o=Math.pow(10,-u)/r,m=Math.round(n*o),f=Math.round(e*o),m/o<n)++m;if(f/o>e)--f;o=-o}else{if(o=Math.pow(10,u)*r,m=Math.round(n/o),f=Math.round(e/o),m*o<n)++m;if(f*o>e)--f}if(f<m&&0.5<=a&&a<2)return Tn(n,e,a*2);return[m,f,o]}function L(n,e,a){return e=+e,n=+n,a=+a,Tn(n,e,a)[2]}function Q(n,e,a){e=+e,n=+n,a=+a;let i=e<n,u=i?L(e,n,a):L(n,e,a);return(i?-1:1)*(u<0?1/-u:u)}function Un(n){return function(a,i=0,u=a.length){let t=u-(i=+i);while(t){let r=n()*t--|0,m=a[t+i];a[t+i]=a[r+i],a[r+i]=m}return a}}var $t=Un(Math.random);function Cn(n,e,a,i,u,t){let r=[[T,1,d],[T,5,5*d],[T,15,15*d],[T,30,30*d],[t,1,s],[t,5,5*s],[t,15,15*s],[t,30,30*s],[u,1,x],[u,3,3*x],[u,6,6*x],[u,12,12*x],[i,1,I],[i,2,2*I],[a,1,C],[e,1,B],[e,3,3*B],[n,1,W]];function m(o,y,c){let b=y<o;if(b)[o,y]=[y,o];let D=c&&typeof c.range==="function"?c:f(o,y,c),N=D?D.range(o,+y+1):[];return b?N.reverse():N}function f(o,y,c){let b=Math.abs(+y-+o)/c,D=A(([,,hn])=>hn).right(r,b);if(D===r.length)return n.every(Q(+o/W,+y/W,c));if(D===0)return M.every(Math.max(Q(+o,+y,c),1));let[N,Hn]=r[b/r[D-1][2]<r[D][2]/b?D-1:D];return N.every(Hn)}return[m,f]}var kn=Cn(h,V,v,G,O,K),vn=Cn(H,F,k,Y,E,q),We=kn[0],qe=kn[1],Ke=vn[0],Ee=vn[1];export{ne as utcYears,h as utcYear,sn as utcWeeks,v as utcWeek,Zn as utcWednesdays,yn as utcWednesday,Xn as utcTuesdays,fn as utcTuesday,We as utcTicks,qe as utcTickInterval,$n as utcThursdays,cn as utcThursday,sn as utcSundays,v as utcSunday,z as utcSeconds,T as utcSecond,Rn as utcSaturdays,bn as utcSaturday,zn as utcMonths,V as utcMonth,Qn as utcMondays,mn as utcMonday,Nn as utcMinutes,K as utcMinute,_ as utcMilliseconds,M as utcMillisecond,qn as utcHours,O as utcHour,Bn as utcFridays,ln as utcFriday,En as utcDays,j as utcDay,On as unixDays,G as unixDay,jn as timeYears,H as timeYear,an as timeWeeks,k as timeWeek,Fn as timeWednesdays,rn as timeWednesday,Gn as timeTuesdays,en as timeTuesday,Ke as timeTicks,Ee as timeTickInterval,Vn as timeThursdays,tn as timeThursday,an as timeSundays,k as timeSunday,z as timeSeconds,T as timeSecond,Pn as timeSaturdays,un as timeSaturday,_n as timeMonths,F as timeMonth,Yn as timeMondays,nn as timeMonday,Ln as timeMinutes,q as timeMinute,_ as timeMilliseconds,M as timeMillisecond,l as timeInterval,Wn as timeHours,E as timeHour,Jn as timeFridays,on as timeFriday,Kn as timeDays,Y as timeDay};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function timeInterval(floori: (date: Date) => void, offseti: (date: Date, step: number) => void, count?: (start: Date, end: Date) => number, field?: (date: Date) => number): TimeInterval;
|
|
2
|
+
export declare interface TimeInterval {
|
|
3
|
+
(date?: Date | number): Date
|
|
4
|
+
floor: (date: Date | number) => Date
|
|
5
|
+
ceil: (date: Date | number) => Date
|
|
6
|
+
round: (date: Date | number) => Date
|
|
7
|
+
offset: (date: Date | number, step?: number) => Date
|
|
8
|
+
range: (start: Date | number, stop: Date | number, step?: number) => Date[]
|
|
9
|
+
filter: (test: (date: Date) => boolean) => TimeInterval
|
|
10
|
+
count?: (start: Date | number, end: Date | number) => number
|
|
11
|
+
every?: (step: number) => TimeInterval | null
|
|
12
|
+
}
|
package/dist/minute.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const timeMinute: TimeInterval;
|
|
2
|
+
export declare const timeMinutes: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
3
|
+
export declare const utcMinute: TimeInterval;
|
|
4
|
+
export declare const utcMinutes: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
package/dist/month.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const timeMonth: TimeInterval;
|
|
2
|
+
export declare const timeMonths: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
3
|
+
export declare const utcMonth: TimeInterval;
|
|
4
|
+
export declare const utcMonths: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
package/dist/second.d.ts
ADDED
package/dist/ticks.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const utcTicks: (start: Date | number, stop: Date | number, count: TimeInterval | number) => Date[];
|
|
2
|
+
export declare const utcTickInterval: (start: Date | number, stop: Date | number, count: number) => TimeInterval | null | undefined;
|
|
3
|
+
export declare const timeTicks: (start: Date | number, stop: Date | number, count: TimeInterval | number) => Date[];
|
|
4
|
+
export declare const timeTickInterval: (start: Date | number, stop: Date | number, count: number) => TimeInterval | null | undefined;
|
package/dist/week.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const timeSunday: TimeInterval;
|
|
2
|
+
export declare const timeMonday: TimeInterval;
|
|
3
|
+
export declare const timeTuesday: TimeInterval;
|
|
4
|
+
export declare const timeWednesday: TimeInterval;
|
|
5
|
+
export declare const timeThursday: TimeInterval;
|
|
6
|
+
export declare const timeFriday: TimeInterval;
|
|
7
|
+
export declare const timeSaturday: TimeInterval;
|
|
8
|
+
export declare const timeSundays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
9
|
+
export declare const timeMondays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
10
|
+
export declare const timeTuesdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
11
|
+
export declare const timeWednesdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
12
|
+
export declare const timeThursdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
13
|
+
export declare const timeFridays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
14
|
+
export declare const timeSaturdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
15
|
+
export declare const utcSunday: TimeInterval;
|
|
16
|
+
export declare const utcMonday: TimeInterval;
|
|
17
|
+
export declare const utcTuesday: TimeInterval;
|
|
18
|
+
export declare const utcWednesday: TimeInterval;
|
|
19
|
+
export declare const utcThursday: TimeInterval;
|
|
20
|
+
export declare const utcFriday: TimeInterval;
|
|
21
|
+
export declare const utcSaturday: TimeInterval;
|
|
22
|
+
export declare const utcSundays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
23
|
+
export declare const utcMondays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
24
|
+
export declare const utcTuesdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
25
|
+
export declare const utcWednesdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
26
|
+
export declare const utcThursdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
27
|
+
export declare const utcFridays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
28
|
+
export declare const utcSaturdays: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
package/dist/year.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const timeYear: TimeInterval;
|
|
2
|
+
export declare const timeYears: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
|
3
|
+
export declare const utcYear: TimeInterval;
|
|
4
|
+
export declare const utcYears: (start: Date | number, stop: Date | number, step?: number) => Date[];
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-charts/time",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./src/index.ts"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"module": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun --bun build.ts",
|
|
18
|
+
"prepublishOnly": "bun --bun run build",
|
|
19
|
+
"test": "bun test"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ts-charts/array": "0.1.0"
|
|
23
|
+
}
|
|
24
|
+
}
|