Skip to content

Commit 5ef8705

Browse files
feat: adds same{Unit} functions, closes #25
* feat: adds same{Unit} functions (#25) * feat: add `sameSecond` function * feat: add `sameMinute` function * feat: add `sameHour` function * feat: add `sameYear` function * docs: add new functions to docs * fix: fixed styling issues in Safari (#19) * fix: fixed styling issues in Safari * fix: add margin-end to code block for spacing * docs: update `id` for correct anchoring * chore: revert `nuxt.config.ts` nitro configuration * chore: remove `debug` mode --------- Co-authored-by: Justin Schroeder <[email protected]> --------- Co-authored-by: Roman Hrynevych <[email protected]>
1 parent 2b8b95e commit 5ef8705

20 files changed

+315
-95
lines changed

Diff for: docs/app.vue

+2-6
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ onMounted(async () => {
2626

2727
<template>
2828
<TheHeader />
29-
<div
30-
class="docs-layout flex w-full max-w-full mt-20 border-t border-t-slate-300 dark:border-t-purple-950"
31-
>
29+
<div class="docs-layout flex w-full max-w-full mt-20 border-t border-t-slate-300 dark:border-t-purple-950">
3230
<TheSidebar />
33-
<NuxtPage
34-
class="min-w-0 pr-4 mr-auto pt-20 w-full max-w-[1000px] ml-6 min-[1400px]:ml-10"
35-
/>
31+
<NuxtPage class="min-w-0 pr-4 mr-auto pt-20 w-full max-w-[1000px] ml-6 min-[1400px]:ml-10" />
3632
</div>
3733
<TheFooter />
3834
</template>

Diff for: docs/assets/css/main.css

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ html.dark body {
1919
@apply selection:bg-fuchsia-600;
2020
}
2121
html body::before {
22-
@apply opacity-100;
22+
@apply h-lvh w-screen opacity-100;
2323
@apply contrast-[300%];
2424
@apply mix-blend-overlay;
2525
@apply brightness-[100%];
26+
@apply inset-0;
2627
content: "";
2728
position: fixed;
2829
inset: 0;
2930
z-index: -1;
30-
width: 100vw;
31-
height: 100vh;
3231
background-size: cover;
3332
background-image: radial-gradient(
3433
circle at 50% 40%,
@@ -42,6 +41,19 @@ html.dark body::before {
4241
@apply mix-blend-multiply;
4342
@apply contrast-[150%];
4443
@apply brightness-[70%];
44+
@apply inset-0;
45+
}
46+
47+
.DocSearch-Reset {
48+
@apply text-white;
49+
}
50+
51+
.DocSearch-SearchBar {
52+
@apply grid grid-cols-[minmax(0,1fr)_auto];
53+
}
54+
55+
.DocSearch-SearchBar form {
56+
@apply grid grid-cols-[auto_0_minmax(0,1fr)_auto];
4557
}
4658

4759
.monaco-editor,
@@ -137,7 +149,7 @@ html.dark body::before {
137149
}
138150

139151
.page-section table code {
140-
@apply rounded bg-slate-100 p-1 font-mono min-[1400px]:text-base;
152+
@apply me-2 rounded bg-slate-100 p-1 font-mono min-[1400px]:text-base;
141153
@apply dark:bg-purple-950 dark:text-slate-100;
142154
}
143155
.page-section table tr:nth-child(odd) code {

Diff for: docs/components/CodeExample.client.vue

+8-8
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ const stopWatch = watch(el, () => {
155155
min-[1600px]:-mr-64
156156
shadow-sm
157157
bg-[#f9f9f9] ${'' /* --vs-editor-background */}
158-
after:-z-10
159-
after:absolute
160-
after:-inset-px
161-
after:bg-sky-600/50
162-
after:rounded-lg
158+
after:-z-10
159+
after:absolute
160+
after:-inset-px
161+
after:bg-sky-600/50
162+
after:rounded-lg
163163
164-
dark:bg-[#180626] ${'' /* --vs-editor-background */}
164+
dark:bg-[#180626] ${'' /* --vs-editor-background */}
165165
dark:after:-inset-px
166166
dark:after:bg-purple-900
167167
`">
@@ -190,7 +190,7 @@ const stopWatch = watch(el, () => {
190190
`">
191191
<ul v-if="result">
192192
<li v-for="logs in result"
193-
class="text-nowrap h-[21px] text-slate-800 text-sm empty:hidden md:empty:block dark:text-purple-300">
193+
class="text-nowrap h-[21px] text-slate-800 text-sm empty:hidden md:empty:block dark:text-purple-300 whitespace-nowrap">
194194
{{ logs ? logs.join(", ") : "" }}
195195
</li>
196196
</ul>
@@ -199,7 +199,7 @@ const stopWatch = watch(el, () => {
199199
</div>
200200
</div>
201201
<div
202-
class="sensible-error bg-red-600 text-white font-mono font-sm p-2 text-xs relative -top-3 -mb-10 h-9 leading-0 z-50 w-auto rounded-lg border border-red-400 shadow-md"
202+
class="sensible-error bg-red-600 text-white font-mono font-sm p-2 text-xs relative -top-3 -mb-10 min-h-9 leading-0 z-50 w-auto rounded-lg border border-red-400 shadow-md flex items-center"
203203
v-if="sensibleError">
204204
{{ sensibleError }}
205205
</div>

Diff for: docs/components/CodeExample.server.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ code.value = value.default
66
</script>
77

88
<template>
9-
<div class="chrome"></div>
9+
<div class="chrome" :style="{
10+
height: `${Math.min(1000, code.split('\n').length * 21)}px`
11+
}"></div>
1012
</template>
1113

1214
<style scoped>
1315
.chrome {
1416
width: 500px;
15-
height: 300px;
1617
}
1718
</style>

Diff for: docs/components/TheSidebar.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ onMounted(() => {
1515
document.querySelectorAll("h3:not([data-sidebar-exclude=true])")
1616
) as HTMLElement[]) || []
1717
18-
// add ids to all headings based on their text content
18+
// add ids to all headings based on their text content if id is not already present
1919
const headings = Array.from(document.querySelectorAll("h2, h3"))
2020
headings.forEach((heading) => {
21-
const id = heading.textContent?.toLowerCase().replace(/\s/g, "-")
21+
const id = heading?.id ?? heading.textContent?.toLowerCase().replace(/\s/g, "-")
2222
if (id) {
2323
heading.id = id
2424
}

Diff for: docs/components/content/Data.vue

+17-26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { FunctionRef, ObjectRef } from "../../src/types"
33
const fns: Record<
44
string,
55
{
6+
name: string
67
description: string
78
return: string
89
arguments: FunctionRef["arguments"]
@@ -12,6 +13,7 @@ const fns: Record<
1213
}
1314
> = {
1415
ap: {
16+
name: "ap",
1517
description: "Returns either am or pm but in any given locale.",
1618
return: "Date",
1719
arguments: [
@@ -27,6 +29,7 @@ const fns: Record<
2729
example: "ap",
2830
},
2931
dayOfYear: {
32+
name: "day-of-year",
3033
description: `Gets the day of the year a given date is. For example, August 1st is the 213th day of the year on non-leap years and 214th on leap years.`,
3134
arguments: [
3235
{
@@ -37,6 +40,7 @@ const fns: Record<
3740
return: "number",
3841
},
3942
formatStr: {
43+
name: "format-str",
4044
description:
4145
"This little gem of a function returns the token format for a given format style.",
4246
arguments: [
@@ -53,6 +57,7 @@ const fns: Record<
5357
example: "format-str",
5458
},
5559
fourDigitYear: {
60+
name: "four-digit-year",
5661
description:
5762
"Converts a 2 digit year into a 4 digit year. This function assumes years 20 years into the future belong to the current century, and the past 80 are in the past century.",
5863
arguments: [
@@ -64,6 +69,7 @@ const fns: Record<
6469
return: "number",
6570
},
6671
iso8601: {
72+
name: "iso-8601",
6773
description:
6874
"Validates that a given date passes “acceptable” levels of ISO 8601 compatibility and can be utilized within Tempo. This allows incomplete dates but must include at least the year and month. Does not require the <code>T</code> separator.",
6975
arguments: [
@@ -75,6 +81,7 @@ const fns: Record<
7581
return: "string",
7682
},
7783
monthDays: {
84+
name: "month-days",
7885
description: "Returns the number of days in a given month.",
7986
arguments: [
8087
{
@@ -85,6 +92,7 @@ const fns: Record<
8592
return: "number",
8693
},
8794
nearestDay: {
95+
name: "nearest-day",
8896
description:
8997
"Performs a bidirectional search for the nearest date that passes a given search function. It stops searching when it finds a result or when it reaches the constraint bounds (on both sides).",
9098
arguments: [
@@ -104,6 +112,7 @@ const fns: Record<
104112
return: "Date | null",
105113
},
106114
offset: {
115+
name: "offset",
107116
description:
108117
"Returns the offset between two (IANA) timezones on a given date. The results are ISO 8601 compatible string offsets like -0800 or +0530.",
109118
arguments: [
@@ -125,6 +134,7 @@ const fns: Record<
125134
return: "string",
126135
},
127136
parseParts: {
137+
name: "parse-parts",
128138
description:
129139
'Given a date string like "2019/12/31" and the parts (like those returned from the <a href="#parts"><code>parts</code> function</a>) this function returns the parts with the appropriate values extracted from the date string and added to a <code>value</code> property.',
130140
arguments: [
@@ -151,6 +161,7 @@ const fns: Record<
151161
example: "parseParts",
152162
},
153163
parts: {
164+
name: "parts",
154165
description:
155166
'Given a format and locale, this function produces an array of "parts". Similar to <code>Intl.DateTimeFormat.formatToParts()</code> but it accepts style formats and token formats and returns parts with granular data such as the part’s token and a regex to match for it.',
156167
arguments: [
@@ -209,6 +220,7 @@ const fns: Record<
209220
return: "Part[]",
210221
},
211222
range: {
223+
name: "range",
212224
description:
213225
"Returns an array of options for a given token in a given locale. For example, the token <code>MMMM</code> in the locale <code>en-US</code> would return <code>['January', 'February', 'March', ...]</code>.",
214226
arguments: [
@@ -230,22 +242,8 @@ const fns: Record<
230242
return: "string[]",
231243
example: "range",
232244
},
233-
sameDay: {
234-
description:
235-
"Checks if two dates are the same day. This function is useful for comparing dates but ignoring the time.",
236-
arguments: [
237-
{
238-
name: "dateA",
239-
type: "Date",
240-
},
241-
{
242-
name: "dateB",
243-
type: "Date",
244-
},
245-
],
246-
return: "boolean",
247-
},
248245
yearDays: {
246+
name: "year-days",
249247
description:
250248
"Returns the number of days in a given year. Leap years and century years cause this to not always be 365.",
251249
arguments: [
@@ -268,20 +266,13 @@ const fns: Record<
268266
data that is commonly needed to build applications.
269267
</p>
270268
<div v-for="(def, fn) in fns">
271-
<h3 :id="fn">{{ fn }}</h3>
272-
<FunctionReference
273-
:function="fn"
274-
:arguments="def.arguments"
275-
:return="def.return"
276-
/>
269+
<h3 :id="def?.name">{{ fn }}</h3>
270+
<FunctionReference :function="fn" :arguments="def.arguments" :return="def.return" />
277271
<p v-html="def.description" />
278272
<CodeExample v-if="def.example" :file="def.example" />
279273
<CalloutInfo v-if="def.tip" v-html="def.tip" />
280-
<ObjectReference
281-
v-if="def.objectReference"
282-
:type="def.objectReference.type"
283-
:properties="def.objectReference.properties"
284-
/>
274+
<ObjectReference v-if="def.objectReference" :type="def.objectReference.type"
275+
:properties="def.objectReference.properties" />
285276
</div>
286277
</PageSection>
287278
</template>

Diff for: docs/components/content/Helpers.vue

+75
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,81 @@ const fns: Record<
1010
tip?: string
1111
}
1212
> = {
13+
sameSecond: {
14+
description:
15+
"Checks if two dates are the same second. This function is useful for comparing dates but ignoring the milliseconds.",
16+
arguments: [
17+
{
18+
name: "dateA",
19+
type: "Date",
20+
},
21+
{
22+
name: "dateB",
23+
type: "Date",
24+
},
25+
],
26+
return: "boolean",
27+
},
28+
sameMinute: {
29+
description:
30+
"Checks if two dates are the same minute. This function is useful for comparing dates but ignoring the seconds and milliseconds.",
31+
arguments: [
32+
{
33+
name: "dateA",
34+
type: "Date",
35+
},
36+
{
37+
name: "dateB",
38+
type: "Date",
39+
},
40+
],
41+
return: "boolean",
42+
},
43+
sameHour: {
44+
description:
45+
"Checks if two dates are the same hour. This function is useful for comparing dates but ignoring the minutes, seconds, and milliseconds.",
46+
arguments: [
47+
{
48+
name: "dateA",
49+
type: "Date",
50+
},
51+
{
52+
name: "dateB",
53+
type: "Date",
54+
},
55+
],
56+
return: "boolean",
57+
},
58+
sameDay: {
59+
description:
60+
"Checks if two dates are the same day. This function is useful for comparing dates but ignoring the time.",
61+
arguments: [
62+
{
63+
name: "dateA",
64+
type: "Date",
65+
},
66+
{
67+
name: "dateB",
68+
type: "Date",
69+
},
70+
],
71+
return: "boolean",
72+
},
73+
sameYear: {
74+
description:
75+
"Checks if two dates are the same year. This function is useful for comparing dates but ignoring the month, day, and time.",
76+
arguments: [
77+
{
78+
name: "dateA",
79+
type: "Date",
80+
},
81+
{
82+
name: "dateB",
83+
type: "Date",
84+
},
85+
],
86+
return: "boolean",
87+
},
1388
isBefore: {
1489
description:
1590
"Returns true if the first date is before the second date, otherwise false.",

0 commit comments

Comments
 (0)