Skip to content

Commit

Permalink
feat: adds same{Unit} functions, closes #25
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
justin-schroeder and hrynevychroman authored Feb 26, 2024
1 parent 2b8b95e commit 5ef8705
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 95 deletions.
8 changes: 2 additions & 6 deletions docs/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ onMounted(async () => {

<template>
<TheHeader />
<div
class="docs-layout flex w-full max-w-full mt-20 border-t border-t-slate-300 dark:border-t-purple-950"
>
<div class="docs-layout flex w-full max-w-full mt-20 border-t border-t-slate-300 dark:border-t-purple-950">
<TheSidebar />
<NuxtPage
class="min-w-0 pr-4 mr-auto pt-20 w-full max-w-[1000px] ml-6 min-[1400px]:ml-10"
/>
<NuxtPage class="min-w-0 pr-4 mr-auto pt-20 w-full max-w-[1000px] ml-6 min-[1400px]:ml-10" />
</div>
<TheFooter />
</template>
20 changes: 16 additions & 4 deletions docs/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ html.dark body {
@apply selection:bg-fuchsia-600;
}
html body::before {
@apply opacity-100;
@apply h-lvh w-screen opacity-100;
@apply contrast-[300%];
@apply mix-blend-overlay;
@apply brightness-[100%];
@apply inset-0;
content: "";
position: fixed;
inset: 0;
z-index: -1;
width: 100vw;
height: 100vh;
background-size: cover;
background-image: radial-gradient(
circle at 50% 40%,
Expand All @@ -42,6 +41,19 @@ html.dark body::before {
@apply mix-blend-multiply;
@apply contrast-[150%];
@apply brightness-[70%];
@apply inset-0;
}

.DocSearch-Reset {
@apply text-white;
}

.DocSearch-SearchBar {
@apply grid grid-cols-[minmax(0,1fr)_auto];
}

.DocSearch-SearchBar form {
@apply grid grid-cols-[auto_0_minmax(0,1fr)_auto];
}

.monaco-editor,
Expand Down Expand Up @@ -137,7 +149,7 @@ html.dark body::before {
}

.page-section table code {
@apply rounded bg-slate-100 p-1 font-mono min-[1400px]:text-base;
@apply me-2 rounded bg-slate-100 p-1 font-mono min-[1400px]:text-base;
@apply dark:bg-purple-950 dark:text-slate-100;
}
.page-section table tr:nth-child(odd) code {
Expand Down
16 changes: 8 additions & 8 deletions docs/components/CodeExample.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ const stopWatch = watch(el, () => {
min-[1600px]:-mr-64
shadow-sm
bg-[#f9f9f9] ${'' /* --vs-editor-background */}
after:-z-10
after:absolute
after:-inset-px
after:bg-sky-600/50
after:rounded-lg
after:-z-10
after:absolute
after:-inset-px
after:bg-sky-600/50
after:rounded-lg
dark:bg-[#180626] ${'' /* --vs-editor-background */}
dark:bg-[#180626] ${'' /* --vs-editor-background */}
dark:after:-inset-px
dark:after:bg-purple-900
`">
Expand Down Expand Up @@ -190,7 +190,7 @@ const stopWatch = watch(el, () => {
`">
<ul v-if="result">
<li v-for="logs in result"
class="text-nowrap h-[21px] text-slate-800 text-sm empty:hidden md:empty:block dark:text-purple-300">
class="text-nowrap h-[21px] text-slate-800 text-sm empty:hidden md:empty:block dark:text-purple-300 whitespace-nowrap">
{{ logs ? logs.join(", ") : "" }}
</li>
</ul>
Expand All @@ -199,7 +199,7 @@ const stopWatch = watch(el, () => {
</div>
</div>
<div
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"
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"
v-if="sensibleError">
{{ sensibleError }}
</div>
Expand Down
5 changes: 3 additions & 2 deletions docs/components/CodeExample.server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ code.value = value.default
</script>

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

<style scoped>
.chrome {
width: 500px;
height: 300px;
}
</style>
4 changes: 2 additions & 2 deletions docs/components/TheSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ onMounted(() => {
document.querySelectorAll("h3:not([data-sidebar-exclude=true])")
) as HTMLElement[]) || []
// add ids to all headings based on their text content
// add ids to all headings based on their text content if id is not already present
const headings = Array.from(document.querySelectorAll("h2, h3"))
headings.forEach((heading) => {
const id = heading.textContent?.toLowerCase().replace(/\s/g, "-")
const id = heading?.id ?? heading.textContent?.toLowerCase().replace(/\s/g, "-")
if (id) {
heading.id = id
}
Expand Down
43 changes: 17 additions & 26 deletions docs/components/content/Data.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FunctionRef, ObjectRef } from "../../src/types"
const fns: Record<
string,
{
name: string
description: string
return: string
arguments: FunctionRef["arguments"]
Expand All @@ -12,6 +13,7 @@ const fns: Record<
}
> = {
ap: {
name: "ap",
description: "Returns either am or pm but in any given locale.",
return: "Date",
arguments: [
Expand All @@ -27,6 +29,7 @@ const fns: Record<
example: "ap",
},
dayOfYear: {
name: "day-of-year",
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.`,
arguments: [
{
Expand All @@ -37,6 +40,7 @@ const fns: Record<
return: "number",
},
formatStr: {
name: "format-str",
description:
"This little gem of a function returns the token format for a given format style.",
arguments: [
Expand All @@ -53,6 +57,7 @@ const fns: Record<
example: "format-str",
},
fourDigitYear: {
name: "four-digit-year",
description:
"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.",
arguments: [
Expand All @@ -64,6 +69,7 @@ const fns: Record<
return: "number",
},
iso8601: {
name: "iso-8601",
description:
"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.",
arguments: [
Expand All @@ -75,6 +81,7 @@ const fns: Record<
return: "string",
},
monthDays: {
name: "month-days",
description: "Returns the number of days in a given month.",
arguments: [
{
Expand All @@ -85,6 +92,7 @@ const fns: Record<
return: "number",
},
nearestDay: {
name: "nearest-day",
description:
"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).",
arguments: [
Expand All @@ -104,6 +112,7 @@ const fns: Record<
return: "Date | null",
},
offset: {
name: "offset",
description:
"Returns the offset between two (IANA) timezones on a given date. The results are ISO 8601 compatible string offsets like -0800 or +0530.",
arguments: [
Expand All @@ -125,6 +134,7 @@ const fns: Record<
return: "string",
},
parseParts: {
name: "parse-parts",
description:
'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.',
arguments: [
Expand All @@ -151,6 +161,7 @@ const fns: Record<
example: "parseParts",
},
parts: {
name: "parts",
description:
'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.',
arguments: [
Expand Down Expand Up @@ -209,6 +220,7 @@ const fns: Record<
return: "Part[]",
},
range: {
name: "range",
description:
"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>.",
arguments: [
Expand All @@ -230,22 +242,8 @@ const fns: Record<
return: "string[]",
example: "range",
},
sameDay: {
description:
"Checks if two dates are the same day. This function is useful for comparing dates but ignoring the time.",
arguments: [
{
name: "dateA",
type: "Date",
},
{
name: "dateB",
type: "Date",
},
],
return: "boolean",
},
yearDays: {
name: "year-days",
description:
"Returns the number of days in a given year. Leap years and century years cause this to not always be 365.",
arguments: [
Expand All @@ -268,20 +266,13 @@ const fns: Record<
data that is commonly needed to build applications.
</p>
<div v-for="(def, fn) in fns">
<h3 :id="fn">{{ fn }}</h3>
<FunctionReference
:function="fn"
:arguments="def.arguments"
:return="def.return"
/>
<h3 :id="def?.name">{{ fn }}</h3>
<FunctionReference :function="fn" :arguments="def.arguments" :return="def.return" />
<p v-html="def.description" />
<CodeExample v-if="def.example" :file="def.example" />
<CalloutInfo v-if="def.tip" v-html="def.tip" />
<ObjectReference
v-if="def.objectReference"
:type="def.objectReference.type"
:properties="def.objectReference.properties"
/>
<ObjectReference v-if="def.objectReference" :type="def.objectReference.type"
:properties="def.objectReference.properties" />
</div>
</PageSection>
</template>
75 changes: 75 additions & 0 deletions docs/components/content/Helpers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,81 @@ const fns: Record<
tip?: string
}
> = {
sameSecond: {
description:
"Checks if two dates are the same second. This function is useful for comparing dates but ignoring the milliseconds.",
arguments: [
{
name: "dateA",
type: "Date",
},
{
name: "dateB",
type: "Date",
},
],
return: "boolean",
},
sameMinute: {
description:
"Checks if two dates are the same minute. This function is useful for comparing dates but ignoring the seconds and milliseconds.",
arguments: [
{
name: "dateA",
type: "Date",
},
{
name: "dateB",
type: "Date",
},
],
return: "boolean",
},
sameHour: {
description:
"Checks if two dates are the same hour. This function is useful for comparing dates but ignoring the minutes, seconds, and milliseconds.",
arguments: [
{
name: "dateA",
type: "Date",
},
{
name: "dateB",
type: "Date",
},
],
return: "boolean",
},
sameDay: {
description:
"Checks if two dates are the same day. This function is useful for comparing dates but ignoring the time.",
arguments: [
{
name: "dateA",
type: "Date",
},
{
name: "dateB",
type: "Date",
},
],
return: "boolean",
},
sameYear: {
description:
"Checks if two dates are the same year. This function is useful for comparing dates but ignoring the month, day, and time.",
arguments: [
{
name: "dateA",
type: "Date",
},
{
name: "dateB",
type: "Date",
},
],
return: "boolean",
},
isBefore: {
description:
"Returns true if the first date is before the second date, otherwise false.",
Expand Down
Loading

0 comments on commit 5ef8705

Please sign in to comment.