1.0.0 • Published 6 months ago
@patrten/eos-dicta v1.0.0
🕉 @patrten/eos-dicta
💎 Install
pnpm add @patrten/eos-dicta
🤓 Unit Tests
🙏 Description
- First function accepts a
Date
object and returns a string that may be used as avalue
in an input that has a type of datetime-local -YYYY-MM-DDTHH:mm
- Second function accepts a
datetime-local
input'svalue
and returns a date time string format based on ISO 8601 -YYYY-MM-DDTHH:mm:ss.sssZ
💚 toInputValue()
- Accepts a
Date
object and returns a string that may be used as avalue
in an input that has a type of datetime-local -YYYY-MM-DDTHH:mm
toInputValue(date: Date): string
- Example:
import { toInputValue } from '@patrten/eos-dicta'
const date = new Date((new Date()).getTime() + (3 * 60000)) // now + 3 minutes
const value = toInputValue(date)
<input bind:value={ value } type="datetime-local">
- 🔥 Errors we may throw
if (!(date instanceof Date) || date.toString() === 'Invalid Date') throw { id: 'fln__datetime-local__invalid-date', message: 'Please pass toInputValue() a valid Date object', _errorData: { date } }
💛 toISOString()
- Accepts a datetime-local input's value and returns a date time string format based on ISO 8601 -
YYYY-MM-DDTHH:mm:ss.sssZ
toISOString(date: string): string
- Example:
import { toInputValue, toISOString } from '@patrten/eos-dicta'
const date = new Date()
date.setDate(date.getDate() - 7) // now - 7 days
const iso = toISOString(toInputValue(date)) // ready for db insert
- 🔥 Errors we may throw
if (!date || typeof date !== 'string') throw { id: 'fln__datetime-local__empty-date', message: 'Please pass toISOString() a not empty string', _errorData: { date } }
if (date.toString() === 'Invalid Date') throw { id: 'fln__datetime-local__invalid-date', message: 'Please pass toISOString() a valid date string', _errorData: { date } }
🎁 All Our Packages
- @patrten/eos-dicta: NPM ⋅ Github
- @feelinglovelynow/dgraph: NPM ⋅ Github
- @feelinglovelynow/env-write: NPM ⋅ Github
- @feelinglovelynow/get-form-entries: NPM ⋅ Github
- @feelinglovelynow/get-relative-time: NPM ⋅ Github
- @feelinglovelynow/global-style: NPM ⋅ Github
- @feelinglovelynow/jwt: NPM ⋅ Github
- @feelinglovelynow/loop-backwards: NPM ⋅ Github
- @feelinglovelynow/slug: NPM ⋅ Github
- @feelinglovelynow/svelte-catch: NPM ⋅ Github
- @feelinglovelynow/svelte-kv: NPM ⋅ Github
- @feelinglovelynow/svelte-loading-anchor: NPM ⋅ Github
- @feelinglovelynow/svelte-modal: NPM ⋅ Github
- @feelinglovelynow/svelte-turnstile: NPM ⋅ Github
- @feelinglovelynow/toast: NPM ⋅ Github
1.0.0
6 months ago