[READ-ONLY] Mirror of https://github.com/probablykasper/date-picker-svelte. Date and time picker for Svelte date-picker-svelte.kasper.space
calendar date date-picker date-time-picker datepicker package svelte time
0

Configure Feed

Select the types of activity you want to include in your feed.

Replace all `any` types

Kasper (Oct 5, 2021, 11:50 PM +0200) a9e9be04 1d628129

+41 -12
+7 -2
src/lib/DateInput.svelte
··· 49 49 } 50 50 $: textUpdate(text, formatTokens) 51 51 52 - function input(e: any) { 53 - if (e.inputType === 'insertText' && text === textHistory[0] + e.data) { 52 + function input(e: unknown) { 53 + if ( 54 + e instanceof InputEvent && 55 + e.inputType === 'insertText' && 56 + typeof e.data === 'string' && 57 + text === textHistory[0] + e.data 58 + ) { 54 59 let result = parse(textHistory[0], formatTokens, value) 55 60 if (result.missingPunctuation !== '' && !result.missingPunctuation.startsWith(e.data)) { 56 61 text = textHistory[0] + result.missingPunctuation + e.data
+24 -6
src/lib/locale.ts
··· 3 3 months?: string[] 4 4 weekStartsOn?: number 5 5 } 6 - export function getLocaleDefaults() { 6 + type InnerLocale = { 7 + weekdays: string[] 8 + months: string[] 9 + weekStartsOn: number 10 + } 11 + export function getLocaleDefaults(): InnerLocale { 7 12 return { 8 13 weekdays: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 9 14 months: [ ··· 23 28 weekStartsOn: 1, 24 29 } 25 30 } 26 - export function getInnerLocale(locale: Locale = {}) { 27 - let innerLocale = getLocaleDefaults() 31 + export function getInnerLocale(locale: Locale = {}): { 32 + weekdays: string[] 33 + months: string[] 34 + weekStartsOn: number 35 + } { 36 + const innerLocale = getLocaleDefaults() 28 37 if (typeof locale.weekStartsOn === 'number') { 29 38 innerLocale.weekStartsOn = locale.weekStartsOn 30 39 } ··· 33 42 return innerLocale 34 43 } 35 44 45 + type DateFnsLocale = { 46 + options?: { 47 + weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 48 + } 49 + localize?: { 50 + month: (n: number, options?: { width?: string }) => string 51 + day: (i: number, options?: { width?: string }) => string 52 + } 53 + } 36 54 /** Create a Locale from a date-fns locale */ 37 - export function localeFromDateFnsLocale(dateFnsLocale: any) { 38 - let locale = getLocaleDefaults() 39 - if (typeof dateFnsLocale.options.weekStartsOn === 'number') { 55 + export function localeFromDateFnsLocale(dateFnsLocale: DateFnsLocale): InnerLocale { 56 + const locale = getLocaleDefaults() 57 + if (typeof dateFnsLocale?.options?.weekStartsOn === 'number') { 40 58 locale.weekStartsOn = dateFnsLocale.options.weekStartsOn 41 59 } 42 60 if (dateFnsLocale.localize) {
+6 -2
src/lib/parse.ts
··· 7 7 8 8 export type FormatToken = string | RuleToken 9 9 10 - export function parse(str: string, tokens: FormatToken[], baseDate?: Date) { 11 - let missingPunctuation: string = '' 10 + type ParseResult = { 11 + date: Date | null 12 + missingPunctuation: string 13 + } 14 + export function parse(str: string, tokens: FormatToken[], baseDate?: Date): ParseResult { 15 + let missingPunctuation = '' 12 16 let valid = true 13 17 14 18 baseDate = baseDate || new Date(2020, 0, 1, 0, 0, 0, 0)
+4 -2
src/routes/_prop.svelte
··· 1 1 <script lang="ts"> 2 2 import DateInput from '$lib/DateInput.svelte' 3 3 4 - export let value: any = null 4 + export let value: unknown = null 5 5 export let label: string 6 6 let jsonValue = '' 7 7 $: if (value instanceof Object) { ··· 10 10 function jsonInput() { 11 11 try { 12 12 value = JSON.parse(jsonValue) 13 - } catch (e) {} 13 + } catch (e) { 14 + console.error(e) 15 + } 14 16 } 15 17 </script> 16 18