From 48275b8b449b453b5579d9d5c51616340edaabc0 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Thu, 9 Dec 2021 14:33:56 +0100 Subject: [PATCH 1/5] feat: add class manipulation --- src/__tests__/mergeClasses.test.ts | 15 +- .../parseVariantWithClassesList.test.ts | 370 +++++++++--------- src/helpers/isObject.ts | 17 + src/mergeClasses.ts | 65 ++- src/parseVariantWithClassesList.ts | 269 ++++++++----- src/types/CSSClass.ts | 24 +- 6 files changed, 460 insertions(+), 300 deletions(-) create mode 100644 src/helpers/isObject.ts diff --git a/src/__tests__/mergeClasses.test.ts b/src/__tests__/mergeClasses.test.ts index a260e47..63bdc81 100644 --- a/src/__tests__/mergeClasses.test.ts +++ b/src/__tests__/mergeClasses.test.ts @@ -13,6 +13,19 @@ describe('merge classes function', () => { expect(mergeClasses(['hello'], ['world'])).toBe('hello world'); }); + it('allows functions that can manipulate the classes interactively', () => { + expect(mergeClasses(['hello'], ({ clear, add }) => { + clear() + add('no') + }, ['world'], ({ remove }) => { + remove('world') + })).toBe('no'); + }); + + it('does not allowe duplicates', () => { + expect(mergeClasses(['hello'], ['hello'])).toBe('hello'); + }); + it('merges the truthy values from an object format', () => { expect( mergeClasses( @@ -23,7 +36,7 @@ describe('merge classes function', () => { { world: 1, universe: null, - }, + } as any, ), ).toBe('hello world'); }); diff --git a/src/__tests__/parseVariantWithClassesList.test.ts b/src/__tests__/parseVariantWithClassesList.test.ts index 3c9c24c..827f36e 100644 --- a/src/__tests__/parseVariantWithClassesList.test.ts +++ b/src/__tests__/parseVariantWithClassesList.test.ts @@ -1,15 +1,15 @@ -import { parseVariantWithClassesList } from '../index'; -import { ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types'; +import { parseVariantWithClassesList } from '../index' +import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types' describe('parse variants with classes list function', () => { it('returns the same object if no variants passed', () => { const props = { class: 'text-red-500', type: 'number', - }; + } - expect(parseVariantWithClassesList(props, [])).toEqual(props); - }); + expect(parseVariantWithClassesList(props, [])).toEqual(props) + }) it('returns the variant props if a variant is added', () => { const props = { @@ -22,13 +22,13 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - }; - expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt); - }); + } + expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt) + }) it('returns the default configuration', () => { - const props = {}; - const globalConfiguration = {}; + const props = {} + const globalConfiguration = {} const defaultConfiguration = { type: 'text', fixedClasses: { @@ -37,20 +37,20 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }); - }); + }) + }) it('returns the global configuration', () => { - const props = {}; + const props = {} const globalConfiguration = { type: 'text', fixedClasses: { @@ -59,7 +59,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } const defaultConfiguration = { type: 'button', @@ -69,17 +69,17 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-blue-500', }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }); - }); + }) + }) it('returns the prop configuration from the variant', () => { const props = { @@ -95,7 +95,7 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } const globalConfiguration = { type: 'text', @@ -105,7 +105,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } const defaultConfiguration = { variants: { @@ -119,22 +119,22 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }); - }); + }) + }) it('returns the global configuration from the variant', () => { const props = { variant: 'error', - }; + } const globalConfiguration = { type: 'text', @@ -155,7 +155,7 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } const defaultConfiguration = { variants: { @@ -169,22 +169,22 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }); - }); + }) + }) it('returns the default configuration from the variant', () => { const props = { variant: 'error', - }; + } const globalConfiguration = { type: 'text', fixedClasses: { @@ -193,7 +193,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } const defaultConfiguration = { variants: { @@ -207,17 +207,17 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }); - }); + }) + }) it('merge the variant props with the default props', () => { const props = { @@ -231,71 +231,79 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - }; + } expect(parseVariantWithClassesList(props, [])).toEqual({ ...props.variants.alt, ...{ placeholder: props.placeholder, }, - }); - }); + }) + }) it('use the props over the configuration', () => { const props = { class: 'text-red-500', type: 'number', placeholder: 'Hello world', - }; + } const configuration = { class: 'text-blue-500', - }; + } - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props); - }); + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props) + }) - it('uses the props over the configuration for classes list', () => { - const props = { + it('respects the props for classes list', () => { + const props: CSSClass = { classes: { - wrapper: 'p-3', - body: 'text-gray-500', + wrapper: 'm-3', + body: ({ clear, add }) => { + clear() + add('text-gray-500') + }, }, - }; + } const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ - classesList: props.classes, - }); - }); + classesList: { + wrapper: 'p-4 m-3', + body: 'text-gray-500', + }, + }) + }) - it('overrides only the props defined from the configuration', () => { + it('respects only the props defined from the configuration', () => { const props = { classes: { - wrapper: 'p-3', + wrapper: 'm-3', + inner: 'p-2', }, - }; + } const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { body: 'text-red-500', - wrapper: 'p-3', + wrapper: 'p-4 m-3', + inner: undefined, }, - }); - }); + }) + }) it('accepts undefined values', () => { const props = { @@ -303,58 +311,58 @@ describe('parse variants with classes list function', () => { wrapper: undefined, body: 'text-gray-500', }, - }; + } const configuration = { classes: { wrapper: 'p-4', - body: 'text-red-500', + body: 'bg-red-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], {}, configuration)).toEqual({ classesList: { wrapper: undefined, - body: 'text-gray-500', + body: 'bg-red-500 text-gray-500', }, - }); - }); + }) + }) it('pass `undefined` in the classes props clear any value', () => { const props = { classes: undefined, - }; + } const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('pass `undefined` in the fixedClasses props clear any value', () => { const props = { fixedClasses: undefined, - }; + } const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('pass `undefined` in the variant classes props clear any value', () => { const props = { @@ -364,20 +372,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - }; + } const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('pass `undefined` in the variant fixedClasses props clear any value', () => { const props = { @@ -387,25 +395,25 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - }; + } const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('considers not defined values from the configuration variant', () => { const props = { variant: 'error', - }; + } const configuration = { variants: { @@ -418,27 +426,25 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } - const defaultConfiguration = { + const defaultConfiguration = {} - }; - - expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration)).toEqual({ + expect( + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) + ).toEqual({ classesList: { wrapper: 'border p-3', }, - }); - }); + }) + }) it('considers not defined values from the defaultConfiguration variant', () => { const props = { variant: 'error', - }; - - const configuration = { + } - }; + const configuration = {} const defaultConfiguration = { variants: { @@ -451,19 +457,21 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } - expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration)).toEqual({ + expect( + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) + ).toEqual({ classesList: { wrapper: 'border p-3', }, - }); - }); + }) + }) it('use the variant from the configuration', () => { const props = { variant: 'alt', - }; + } const configuration = { class: 'text-blue-500', @@ -473,23 +481,23 @@ describe('parse variants with classes list function', () => { type: 'text', }, }, - }; + } expect(parseVariantWithClassesList(props, [], configuration)).toEqual( - configuration.variants.alt, - ); - }); + configuration.variants.alt + ) + }) it('use the configuration if no props sent', () => { - const props = {}; + const props = {} const configuration = { class: 'text-blue-500', type: 'text', - }; + } - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration); - }); + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration) + }) it('merges className and fixedClasses', () => { const props = { @@ -500,20 +508,20 @@ describe('parse variants with classes list function', () => { fixedClasses: { wrapper: { 'border-2': true }, }, - }; + } - const config = parseVariantWithClassesList(props, ['wrapper']); + const config = parseVariantWithClassesList(props, ['wrapper']) expect(config).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-red-500 border-2', }, - }); - }); + }) + }) it('merges fixedClasses and variant classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { class: 'text-red-500', @@ -531,20 +539,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - }; + } expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-blue-500 border-2', }, - }); - }); + }) + }) it('uses the classes from the configuration', () => { const props = { variant: 'error', - }; + } const configuration = { classes: { @@ -557,25 +565,25 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper'], configuration)).toEqual({ classesList: { wrapper: 'text-red-500', }, - }); - }); + }) + }) it('handles undefined classes for a variant', () => { const props = { variant: 'error', - }; + } - expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}); - }); + expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}) + }) it('merges only the attributes that are defined from the variant', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { @@ -593,10 +601,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - }; + } expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -604,11 +612,11 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500', input: 'shadow', }, - }); - }); + }) + }) it('merges only the attributes that are defined from the variant and keep the fixed classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { fixedClasses: { @@ -632,10 +640,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - }; + } expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) ).toEqual({ classesList: { wrapper: 'space-x-2 flex items-center', @@ -643,33 +651,34 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500 semibold', input: 'shadow', }, - }); - }); + }) + }) it('merges the only the new attributes to the global configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', }, - }; + } - const globalConfiguration: WithVariantPropsAndClassesList = { - classes: { - wrapper: 'flex items-center space-x-2', - inputWrapper: 'inline-flex', - label: 'uppercase text-gray-500', - input: '', - }, - }; + const globalConfiguration: WithVariantPropsAndClassesList = + { + classes: { + wrapper: 'flex items-center space-x-2', + inputWrapper: 'inline-flex', + label: 'uppercase text-gray-500', + input: '', + }, + } expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], - globalConfiguration, - ), + globalConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -677,17 +686,18 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }); - }); + }) + }) it('it merges the new attributes from the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' - const globalConfiguration: WithVariantPropsAndClassesList = { - classes: { - input: 'border-1', - }, - }; + const globalConfiguration: WithVariantPropsAndClassesList = + { + classes: { + input: 'border-1', + }, + } const defaultConfiguration = { classes: { @@ -696,15 +706,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - }; + } expect( parseVariantWithClassesList( {}, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration, - ), + defaultConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -712,17 +722,20 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }); - }); + }) + }) it('it merges the props with the the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', + label: ({ add }) => { + add('bg-green-500') + }, }, - }; + } const defaultConfiguration = { classes: { @@ -731,39 +744,44 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - }; + } expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], {}, - defaultConfiguration, - ), + defaultConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', inputWrapper: 'inline-flex', - label: 'uppercase text-gray-500', + label: 'uppercase text-gray-500 bg-green-500', input: 'border-1', }, - }); - }); + }) + }) it('it merges the global configuration, the props, and the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { - wrapper: 'flex items-center space-x-2', + wrapper: [ + ({ clear }) => { + clear() + }, + 'flex items-center space-x-2', + ], }, - }; + } const globalConfiguration = { classes: { input: 'border-1', }, - }; + } const defaultConfiguration = { classes: { @@ -772,15 +790,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - }; + } expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration, - ), + defaultConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -788,6 +806,6 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }); - }); -}); + }) + }) +}) diff --git a/src/helpers/isObject.ts b/src/helpers/isObject.ts new file mode 100644 index 0000000..890b70b --- /dev/null +++ b/src/helpers/isObject.ts @@ -0,0 +1,17 @@ +const isObject = , U>(value: T | U): value is T => { + if (!value) { + return false + } + + if (typeof value !== 'object') { + return false + } + + if (Array.isArray(value)) { + return false + } + + return true +}; + +export default isObject; diff --git a/src/mergeClasses.ts b/src/mergeClasses.ts index 8cea21d..243af06 100644 --- a/src/mergeClasses.ts +++ b/src/mergeClasses.ts @@ -1,21 +1,54 @@ -import { CSSClass, CSSClasses, CSSClassKeyValuePair } from './types/CSSClass'; +import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass' -export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => Object.keys(classesObject).filter((className: string) => !!classesObject[className]); +export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => + Object.keys(classesObject).filter((className: string) => !!classesObject[className]) -const mergeClasses = (...classes: CSSClasses): string => classes - .map((className: CSSClass): string => { - if (typeof className === 'string' || className === undefined) { - return className || ''; - } +const mergeClasses = (...classes: CSSClasses): string => { + const mergedClasses = new Set() - if (Array.isArray(className)) { - return mergeClasses(...className); - } + // We use a local function to iterate over the classes so we can pass the + // currently mergeed classes to functional definitions + const merge = (...nestedClasses: CSSClasses) => { + nestedClasses.forEach((className) => { + if (!className) { + return + } - return mergeClasses(...selectClasses(className)); - }) - .join(' ') - .replace(/ +/g, ' ') - .trim(); + if (typeof className === 'boolean') { + return + } -export default mergeClasses; + if (typeof className === 'string' || typeof className === 'undefined') { + mergedClasses.add(`${className || ''}`.replace(/ +/g, ' ').trim()) + return + } + + if (Array.isArray(className)) { + merge(...className) + return + } + + if (typeof className === 'function') { + className({ + clear() { + mergedClasses.clear() + }, + add(cssClass: string) { + merge(...cssClass.split(' ')) + }, + remove(cssClass: string) { + mergedClasses.delete(cssClass) + }, + }) + return + } + + merge(...selectClasses(className)) + }) + } + merge(...classes) + + return Array.from(mergedClasses).join(' ') +} + +export default mergeClasses diff --git a/src/parseVariantWithClassesList.ts b/src/parseVariantWithClassesList.ts index 3b5ac19..65918a9 100644 --- a/src/parseVariantWithClassesList.ts +++ b/src/parseVariantWithClassesList.ts @@ -3,172 +3,241 @@ import { VariantsWithClassesList, WithVariantPropsAndClassesList, WithVariantProps, -} from './types/Variants'; -import pick from './helpers/pick'; - -import mergeClasses from './mergeClasses'; -import { CSSClassesList, CSSRawClassesList } from './types'; -import hasProperty from './helpers/hasProperty'; - -const getCustomPropsFromVariant = < - P extends ObjectWithClassesList, - ClassesKeys extends string, ->( - variants?: VariantsWithClassesList, - variant?: string, - ): WithVariantPropsAndClassesList | undefined => { +} from './types/Variants' +import pick from './helpers/pick' + +import mergeClasses from './mergeClasses' +import { CSSClassesList, CSSRawClassesList } from './types' +import hasProperty from './helpers/hasProperty' +import isObject from './helpers/isObject' + +const getCustomPropsFromVariant =

( + variants?: VariantsWithClassesList, + variant?: string +): WithVariantPropsAndClassesList | undefined => { if (variant !== undefined && variants) { - return variants[variant]; + return variants[variant] } - return undefined; -}; + return undefined +} -const getShouldClearClasses = < - P extends ObjectWithClassesList, - ClassesKeys extends string, ->(props: WithVariantPropsAndClassesList, key: string, variant: string | undefined): boolean => { +const getShouldClearClasses =

( + props: WithVariantPropsAndClassesList, + key: string, + variant: string | undefined +): boolean => { if (variant === undefined) { - return hasProperty(props, key) && (props[key] === undefined || props[key] === null); + return hasProperty(props, key) && (props[key] === undefined || props[key] === null) } if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

; + const propsVariant = props.variants[variant] as WithVariantProps

- return hasProperty(propsVariant, key) && (propsVariant[key] === undefined || propsVariant[key] === null); + return ( + hasProperty(propsVariant, key) && + (propsVariant[key] === undefined || propsVariant[key] === null) + ) } - return false; -}; - -const parseVariantWithClassesList = < - P extends ObjectWithClassesList, - ClassesKeys extends string, ->( - props: WithVariantPropsAndClassesList, - classesListKeys: Readonly>, - globalConfiguration?: WithVariantPropsAndClassesList, - defaultConfiguration?: WithVariantPropsAndClassesList, - ): P => { + return false +} + +const parseVariantWithClassesList =

( + props: WithVariantPropsAndClassesList, + classesListKeys: Readonly>, + globalConfiguration?: WithVariantPropsAndClassesList, + defaultConfiguration?: WithVariantPropsAndClassesList +): P => { const { variants, variant, ...mainProps } = { ...defaultConfiguration, ...globalConfiguration, ...props, - }; + } - const classes: Partial> = {}; - const fixedClasses: Partial> = {}; + const classes: Partial> = {} + const fixedClasses: Partial> = {} - const clearClasses = getShouldClearClasses(props, 'classes', variant); + const clearClasses = getShouldClearClasses(props, 'classes', variant) - const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant); + const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant) if (clearClasses) { classesListKeys.forEach((classItemKey) => { - classes[classItemKey] = undefined; - }); + classes[classItemKey] = undefined + }) } else { classesListKeys.forEach((classItemKey) => { - if (props.classes !== undefined && hasProperty(props.classes, classItemKey)) { - classes[classItemKey] = props.classes[classItemKey]; - } else if (globalConfiguration !== undefined && globalConfiguration.classes !== undefined && hasProperty(globalConfiguration.classes, classItemKey)) { - classes[classItemKey] = globalConfiguration.classes[classItemKey]; - } else if (defaultConfiguration !== undefined && defaultConfiguration.classes !== undefined && hasProperty(defaultConfiguration.classes, classItemKey)) { - classes[classItemKey] = defaultConfiguration.classes[classItemKey]; + // Get classes from global configuration or alternatively from library configuration + if ( + globalConfiguration && + isObject(globalConfiguration.classes) && + classItemKey in globalConfiguration.classes + ) { + classes[classItemKey] = globalConfiguration.classes[classItemKey] + } else if ( + defaultConfiguration && + isObject(defaultConfiguration.classes) && + classItemKey in defaultConfiguration.classes + ) { + classes[classItemKey] = defaultConfiguration.classes[classItemKey] + } + + // Get classes from props and merge them with the previous ones + if (isObject(props.classes) && classItemKey in props.classes) { + if (typeof props.classes[classItemKey] !== 'undefined') { + classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]] + } else { + classes[classItemKey] = undefined + } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

; + const propsVariant = props.variants[variant] as WithVariantProps

- if (propsVariant.classes && hasProperty(propsVariant.classes, classItemKey)) { - classes[classItemKey] = propsVariant.classes[classItemKey]; + if (isObject(propsVariant.classes) && classItemKey in propsVariant.classes) { + classes[classItemKey] = propsVariant.classes[classItemKey] } - } else if (globalConfiguration !== undefined && globalConfiguration.variants !== undefined && globalConfiguration.variants[variant] !== undefined) { - const globalConfigurationVariant = globalConfiguration.variants[variant] as WithVariantProps

; - - if (globalConfigurationVariant.classes && hasProperty(globalConfigurationVariant.classes, classItemKey)) { - classes[classItemKey] = globalConfigurationVariant.classes[classItemKey]; + } else if ( + globalConfiguration && + isObject(globalConfiguration.variants) && + variant in globalConfiguration.variants + ) { + const globalConfigurationVariant = globalConfiguration.variants[ + variant + ] as WithVariantProps

+ + if ( + globalConfigurationVariant.classes && + isObject(globalConfigurationVariant.classes) && + classItemKey in globalConfigurationVariant.classes + ) { + classes[classItemKey] = globalConfigurationVariant.classes[classItemKey] } - } else if (defaultConfiguration !== undefined && defaultConfiguration.variants !== undefined && defaultConfiguration.variants[variant] !== undefined) { - const defaultConfigurationVariant = defaultConfiguration.variants[variant] as WithVariantProps

; - - if (defaultConfigurationVariant.classes && hasProperty(defaultConfigurationVariant.classes, classItemKey)) { - classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey]; + } else if ( + defaultConfiguration !== undefined && + defaultConfiguration.variants !== undefined && + defaultConfiguration.variants[variant] !== undefined + ) { + const defaultConfigurationVariant = defaultConfiguration.variants[ + variant + ] as WithVariantProps

+ + if ( + defaultConfigurationVariant.classes && + isObject(defaultConfigurationVariant.classes) && + classItemKey in defaultConfigurationVariant.classes + ) { + classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey] } } } - }); + }) } if (clearFixedClasses) { classesListKeys.forEach((classItemKey) => { - fixedClasses[classItemKey] = undefined; - }); + fixedClasses[classItemKey] = undefined + }) } else { classesListKeys.forEach((classItemKey) => { - if (props.fixedClasses !== undefined && hasProperty(props.fixedClasses, classItemKey)) { - fixedClasses[classItemKey] = props.fixedClasses[classItemKey]; - } else if (globalConfiguration !== undefined && globalConfiguration.fixedClasses !== undefined && hasProperty(globalConfiguration.fixedClasses, classItemKey)) { - fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey]; - } else if (defaultConfiguration !== undefined && defaultConfiguration.fixedClasses !== undefined && hasProperty(defaultConfiguration.fixedClasses, classItemKey)) { - fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey]; + // Get classes from global configuration or alternatively from library configuration + if ( + globalConfiguration && + isObject(globalConfiguration.fixedClasses) && + classItemKey in globalConfiguration.fixedClasses + ) { + fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey] + } else if ( + defaultConfiguration && + isObject(defaultConfiguration.fixedClasses) && + classItemKey in defaultConfiguration.fixedClasses + ) { + fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey] + } + + // Get classes from props and merge them with the previous ones + if (isObject(props.fixedClasses) && classItemKey in props.fixedClasses) { + if (typeof props.fixedClasses[classItemKey] !== 'undefined') { + fixedClasses[classItemKey] = [fixedClasses[classItemKey], props.fixedClasses[classItemKey]] + } else { + classes[classItemKey] = undefined + } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

; + const propsVariant = props.variants[variant] as WithVariantProps

- if (propsVariant.fixedClasses && hasProperty(propsVariant.fixedClasses, classItemKey)) { - fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey]; + if (isObject(propsVariant.fixedClasses) && classItemKey in propsVariant.fixedClasses) { + fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey] } - } else if (globalConfiguration !== undefined && globalConfiguration.variants !== undefined && globalConfiguration.variants[variant] !== undefined) { - const globalConfigurationVariant = globalConfiguration.variants[variant] as WithVariantProps

; - - if (globalConfigurationVariant.fixedClasses && hasProperty(globalConfigurationVariant.fixedClasses, classItemKey)) { - fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey]; + } else if ( + globalConfiguration !== undefined && + globalConfiguration.variants !== undefined && + globalConfiguration.variants[variant] !== undefined + ) { + const globalConfigurationVariant = globalConfiguration.variants[ + variant + ] as WithVariantProps

+ + if ( + isObject(globalConfigurationVariant.fixedClasses) && + classItemKey in globalConfigurationVariant.fixedClasses + ) { + fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey] } - } else if (defaultConfiguration !== undefined && defaultConfiguration.variants !== undefined && defaultConfiguration.variants[variant] !== undefined) { - const defaultConfigurationVariant = defaultConfiguration.variants[variant] as WithVariantProps

; - - if (defaultConfigurationVariant.fixedClasses && hasProperty(defaultConfigurationVariant.fixedClasses, classItemKey)) { - fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey]; + } else if ( + defaultConfiguration !== undefined && + defaultConfiguration.variants !== undefined && + defaultConfiguration.variants[variant] !== undefined + ) { + const defaultConfigurationVariant = defaultConfiguration.variants[ + variant + ] as WithVariantProps

+ + if ( + isObject(defaultConfigurationVariant.fixedClasses) && + classItemKey in defaultConfigurationVariant.fixedClasses + ) { + fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey] } } } - }); + }) } - const customProps = getCustomPropsFromVariant(variants, variant); + const customProps = getCustomPropsFromVariant(variants, variant) const mergedProps = { ...mainProps, ...customProps, - }; + } - delete mergedProps.fixedClasses; + delete mergedProps.fixedClasses - delete mergedProps.classes; + delete mergedProps.classes - const mergedClasses: CSSClassesList = {}; + const mergedClasses: CSSClassesList = {} classesListKeys.forEach((classItemKey) => { - const classesForTheCurrentKey = classes[classItemKey]; - const fixedClassesForTheCurrentKey = fixedClasses[classItemKey]; + const classesForTheCurrentKey = classes[classItemKey] + const fixedClassesForTheCurrentKey = fixedClasses[classItemKey] mergedClasses[classItemKey as string] = mergeClasses( classesForTheCurrentKey, - fixedClassesForTheCurrentKey, - ); - }); + fixedClassesForTheCurrentKey + ) + }) - const result = pick(mergedClasses); + const result = pick(mergedClasses) if (Object.keys(result).length > 0) { - (mergedProps as P).classesList = result; + ;(mergedProps as P).classesList = result } - return mergedProps as P; -}; + return mergedProps as P +} -export default parseVariantWithClassesList; +export default parseVariantWithClassesList diff --git a/src/types/CSSClass.ts b/src/types/CSSClass.ts index 96f07f5..fc76c8c 100644 --- a/src/types/CSSClass.ts +++ b/src/types/CSSClass.ts @@ -1,16 +1,26 @@ export type CSSClassKeyValuePair = { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [key: string]: any -}; + [key: string]: CSSClass +} -export type CSSClasses = CSSClass[]; +export type CSSClasses = CSSClass[] -export type CSSClass = CSSClassKeyValuePair | string | CSSClasses | undefined; +export type CSSClass = + | CSSClassKeyValuePair + | string + | CSSClasses + | undefined + | null + | boolean + | ((modifiers: { + clear: () => void + add: (cssClass: string) => void + remove: (cssClass: string) => void + }) => void) export type CSSRawClassesList = { [key in ClassesKeys]?: CSSClass -}; +} export type CSSClassesList = { [key in ClassesKeys]?: CSSClass -}; +} From bb19e9c1a986fa2378ab7807d2d6fc4ee4bffeba Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Thu, 9 Dec 2021 14:37:20 +0100 Subject: [PATCH 2/5] style: lint --- src/__tests__/mergeClasses.test.ts | 10 +- .../parseVariantWithClassesList.test.ts | 330 +++++++++--------- src/helpers/isObject.ts | 10 +- src/mergeClasses.ts | 43 ++- src/parseVariantWithClassesList.ts | 202 +++++------ src/types/CSSClass.ts | 16 +- 6 files changed, 304 insertions(+), 307 deletions(-) diff --git a/src/__tests__/mergeClasses.test.ts b/src/__tests__/mergeClasses.test.ts index 63bdc81..7dcd3a6 100644 --- a/src/__tests__/mergeClasses.test.ts +++ b/src/__tests__/mergeClasses.test.ts @@ -15,10 +15,10 @@ describe('merge classes function', () => { it('allows functions that can manipulate the classes interactively', () => { expect(mergeClasses(['hello'], ({ clear, add }) => { - clear() - add('no') - }, ['world'], ({ remove }) => { - remove('world') + clear(); + add('no'); + }, ['world'], ({ remove }) => { + remove('world'); })).toBe('no'); }); @@ -36,7 +36,7 @@ describe('merge classes function', () => { { world: 1, universe: null, - } as any, + } as unknown, ), ).toBe('hello world'); }); diff --git a/src/__tests__/parseVariantWithClassesList.test.ts b/src/__tests__/parseVariantWithClassesList.test.ts index 827f36e..37f4674 100644 --- a/src/__tests__/parseVariantWithClassesList.test.ts +++ b/src/__tests__/parseVariantWithClassesList.test.ts @@ -1,15 +1,15 @@ -import { parseVariantWithClassesList } from '../index' -import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types' +import { parseVariantWithClassesList } from '../index'; +import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types'; describe('parse variants with classes list function', () => { it('returns the same object if no variants passed', () => { const props = { class: 'text-red-500', type: 'number', - } + }; - expect(parseVariantWithClassesList(props, [])).toEqual(props) - }) + expect(parseVariantWithClassesList(props, [])).toEqual(props); + }); it('returns the variant props if a variant is added', () => { const props = { @@ -22,13 +22,13 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - } - expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt) - }) + }; + expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt); + }); it('returns the default configuration', () => { - const props = {} - const globalConfiguration = {} + const props = {}; + const globalConfiguration = {}; const defaultConfiguration = { type: 'text', fixedClasses: { @@ -37,20 +37,20 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }) - }) + }); + }); it('returns the global configuration', () => { - const props = {} + const props = {}; const globalConfiguration = { type: 'text', fixedClasses: { @@ -59,7 +59,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; const defaultConfiguration = { type: 'button', @@ -69,17 +69,17 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-blue-500', }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }) - }) + }); + }); it('returns the prop configuration from the variant', () => { const props = { @@ -95,7 +95,7 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; const globalConfiguration = { type: 'text', @@ -105,7 +105,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; const defaultConfiguration = { variants: { @@ -119,22 +119,22 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }) - }) + }); + }); it('returns the global configuration from the variant', () => { const props = { variant: 'error', - } + }; const globalConfiguration = { type: 'text', @@ -155,7 +155,7 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; const defaultConfiguration = { variants: { @@ -169,22 +169,22 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }) - }) + }); + }); it('returns the default configuration from the variant', () => { const props = { variant: 'error', - } + }; const globalConfiguration = { type: 'text', fixedClasses: { @@ -193,7 +193,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; const defaultConfiguration = { variants: { @@ -207,17 +207,17 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }) - }) + }); + }); it('merge the variant props with the default props', () => { const props = { @@ -231,55 +231,55 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - } + }; expect(parseVariantWithClassesList(props, [])).toEqual({ ...props.variants.alt, ...{ placeholder: props.placeholder, }, - }) - }) + }); + }); it('use the props over the configuration', () => { const props = { class: 'text-red-500', type: 'number', placeholder: 'Hello world', - } + }; const configuration = { class: 'text-blue-500', - } + }; - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props) - }) + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props); + }); it('respects the props for classes list', () => { const props: CSSClass = { classes: { wrapper: 'm-3', body: ({ clear, add }) => { - clear() - add('text-gray-500') + clear(); + add('text-gray-500'); }, }, - } + }; const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { wrapper: 'p-4 m-3', body: 'text-gray-500', }, - }) - }) + }); + }); it('respects only the props defined from the configuration', () => { const props = { @@ -287,14 +287,14 @@ describe('parse variants with classes list function', () => { wrapper: 'm-3', inner: 'p-2', }, - } + }; const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { @@ -302,8 +302,8 @@ describe('parse variants with classes list function', () => { wrapper: 'p-4 m-3', inner: undefined, }, - }) - }) + }); + }); it('accepts undefined values', () => { const props = { @@ -311,58 +311,58 @@ describe('parse variants with classes list function', () => { wrapper: undefined, body: 'text-gray-500', }, - } + }; const configuration = { classes: { wrapper: 'p-4', body: 'bg-red-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], {}, configuration)).toEqual({ classesList: { wrapper: undefined, body: 'bg-red-500 text-gray-500', }, - }) - }) + }); + }); it('pass `undefined` in the classes props clear any value', () => { const props = { classes: undefined, - } + }; const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('pass `undefined` in the fixedClasses props clear any value', () => { const props = { fixedClasses: undefined, - } + }; const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('pass `undefined` in the variant classes props clear any value', () => { const props = { @@ -372,20 +372,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - } + }; const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('pass `undefined` in the variant fixedClasses props clear any value', () => { const props = { @@ -395,25 +395,25 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - } + }; const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('considers not defined values from the configuration variant', () => { const props = { variant: 'error', - } + }; const configuration = { variants: { @@ -426,25 +426,25 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; - const defaultConfiguration = {} + const defaultConfiguration = {}; expect( - parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration), ).toEqual({ classesList: { wrapper: 'border p-3', }, - }) - }) + }); + }); it('considers not defined values from the defaultConfiguration variant', () => { const props = { variant: 'error', - } + }; - const configuration = {} + const configuration = {}; const defaultConfiguration = { variants: { @@ -457,21 +457,21 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration), ).toEqual({ classesList: { wrapper: 'border p-3', }, - }) - }) + }); + }); it('use the variant from the configuration', () => { const props = { variant: 'alt', - } + }; const configuration = { class: 'text-blue-500', @@ -481,23 +481,23 @@ describe('parse variants with classes list function', () => { type: 'text', }, }, - } + }; expect(parseVariantWithClassesList(props, [], configuration)).toEqual( - configuration.variants.alt - ) - }) + configuration.variants.alt, + ); + }); it('use the configuration if no props sent', () => { - const props = {} + const props = {}; const configuration = { class: 'text-blue-500', type: 'text', - } + }; - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration) - }) + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration); + }); it('merges className and fixedClasses', () => { const props = { @@ -508,20 +508,20 @@ describe('parse variants with classes list function', () => { fixedClasses: { wrapper: { 'border-2': true }, }, - } + }; - const config = parseVariantWithClassesList(props, ['wrapper']) + const config = parseVariantWithClassesList(props, ['wrapper']); expect(config).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-red-500 border-2', }, - }) - }) + }); + }); it('merges fixedClasses and variant classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { class: 'text-red-500', @@ -539,20 +539,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - } + }; expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-blue-500 border-2', }, - }) - }) + }); + }); it('uses the classes from the configuration', () => { const props = { variant: 'error', - } + }; const configuration = { classes: { @@ -565,25 +565,25 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper'], configuration)).toEqual({ classesList: { wrapper: 'text-red-500', }, - }) - }) + }); + }); it('handles undefined classes for a variant', () => { const props = { variant: 'error', - } + }; - expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}) - }) + expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}); + }); it('merges only the attributes that are defined from the variant', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { @@ -601,10 +601,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - } + }; expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -612,11 +612,11 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500', input: 'shadow', }, - }) - }) + }); + }); it('merges only the attributes that are defined from the variant and keep the fixed classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { fixedClasses: { @@ -640,10 +640,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - } + }; expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), ).toEqual({ classesList: { wrapper: 'space-x-2 flex items-center', @@ -651,34 +651,33 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500 semibold', input: 'shadow', }, - }) - }) + }); + }); it('merges the only the new attributes to the global configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', }, - } + }; - const globalConfiguration: WithVariantPropsAndClassesList = - { - classes: { - wrapper: 'flex items-center space-x-2', - inputWrapper: 'inline-flex', - label: 'uppercase text-gray-500', - input: '', - }, - } + const globalConfiguration: WithVariantPropsAndClassesList = { + classes: { + wrapper: 'flex items-center space-x-2', + inputWrapper: 'inline-flex', + label: 'uppercase text-gray-500', + input: '', + }, + }; expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], - globalConfiguration - ) + globalConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -686,18 +685,17 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }) - }) + }); + }); it('it merges the new attributes from the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; - const globalConfiguration: WithVariantPropsAndClassesList = - { - classes: { - input: 'border-1', - }, - } + const globalConfiguration: WithVariantPropsAndClassesList = { + classes: { + input: 'border-1', + }, + }; const defaultConfiguration = { classes: { @@ -706,15 +704,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - } + }; expect( parseVariantWithClassesList( {}, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration - ) + defaultConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -722,20 +720,20 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }) - }) + }); + }); it('it merges the props with the the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', label: ({ add }) => { - add('bg-green-500') + add('bg-green-500'); }, }, - } + }; const defaultConfiguration = { classes: { @@ -744,15 +742,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - } + }; expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], {}, - defaultConfiguration - ) + defaultConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -760,28 +758,28 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500 bg-green-500', input: 'border-1', }, - }) - }) + }); + }); it('it merges the global configuration, the props, and the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { wrapper: [ ({ clear }) => { - clear() + clear(); }, 'flex items-center space-x-2', ], }, - } + }; const globalConfiguration = { classes: { input: 'border-1', }, - } + }; const defaultConfiguration = { classes: { @@ -790,15 +788,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - } + }; expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration - ) + defaultConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -806,6 +804,6 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }) - }) -}) + }); + }); +}); diff --git a/src/helpers/isObject.ts b/src/helpers/isObject.ts index 890b70b..75ff499 100644 --- a/src/helpers/isObject.ts +++ b/src/helpers/isObject.ts @@ -1,17 +1,17 @@ const isObject = , U>(value: T | U): value is T => { if (!value) { - return false + return false; } - + if (typeof value !== 'object') { - return false + return false; } if (Array.isArray(value)) { - return false + return false; } - return true + return true; }; export default isObject; diff --git a/src/mergeClasses.ts b/src/mergeClasses.ts index 243af06..22776d5 100644 --- a/src/mergeClasses.ts +++ b/src/mergeClasses.ts @@ -1,54 +1,53 @@ -import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass' +import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass'; -export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => - Object.keys(classesObject).filter((className: string) => !!classesObject[className]) +export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => Object.keys(classesObject).filter((className: string) => !!classesObject[className]); const mergeClasses = (...classes: CSSClasses): string => { - const mergedClasses = new Set() + const mergedClasses = new Set(); // We use a local function to iterate over the classes so we can pass the // currently mergeed classes to functional definitions const merge = (...nestedClasses: CSSClasses) => { nestedClasses.forEach((className) => { if (!className) { - return + return; } if (typeof className === 'boolean') { - return + return; } if (typeof className === 'string' || typeof className === 'undefined') { - mergedClasses.add(`${className || ''}`.replace(/ +/g, ' ').trim()) - return + mergedClasses.add(`${className || ''}`.replace(/ +/g, ' ').trim()); + return; } if (Array.isArray(className)) { - merge(...className) - return + merge(...className); + return; } if (typeof className === 'function') { className({ clear() { - mergedClasses.clear() + mergedClasses.clear(); }, add(cssClass: string) { - merge(...cssClass.split(' ')) + merge(...cssClass.split(' ')); }, remove(cssClass: string) { - mergedClasses.delete(cssClass) + mergedClasses.delete(cssClass); }, - }) - return + }); + return; } - merge(...selectClasses(className)) - }) - } - merge(...classes) + merge(...selectClasses(className)); + }); + }; + merge(...classes); - return Array.from(mergedClasses).join(' ') -} + return Array.from(mergedClasses).join(' '); +}; -export default mergeClasses +export default mergeClasses; diff --git a/src/parseVariantWithClassesList.ts b/src/parseVariantWithClassesList.ts index 65918a9..9fe014d 100644 --- a/src/parseVariantWithClassesList.ts +++ b/src/parseVariantWithClassesList.ts @@ -3,241 +3,241 @@ import { VariantsWithClassesList, WithVariantPropsAndClassesList, WithVariantProps, -} from './types/Variants' -import pick from './helpers/pick' +} from './types/Variants'; +import pick from './helpers/pick'; -import mergeClasses from './mergeClasses' -import { CSSClassesList, CSSRawClassesList } from './types' -import hasProperty from './helpers/hasProperty' -import isObject from './helpers/isObject' +import mergeClasses from './mergeClasses'; +import { CSSClassesList, CSSRawClassesList } from './types'; +import hasProperty from './helpers/hasProperty'; +import isObject from './helpers/isObject'; const getCustomPropsFromVariant =

( variants?: VariantsWithClassesList, - variant?: string + variant?: string, ): WithVariantPropsAndClassesList | undefined => { if (variant !== undefined && variants) { - return variants[variant] + return variants[variant]; } - return undefined -} + return undefined; +}; const getShouldClearClasses =

( props: WithVariantPropsAndClassesList, key: string, - variant: string | undefined + variant: string | undefined, ): boolean => { if (variant === undefined) { - return hasProperty(props, key) && (props[key] === undefined || props[key] === null) + return hasProperty(props, key) && (props[key] === undefined || props[key] === null); } if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

+ const propsVariant = props.variants[variant] as WithVariantProps

; return ( - hasProperty(propsVariant, key) && - (propsVariant[key] === undefined || propsVariant[key] === null) - ) + hasProperty(propsVariant, key) + && (propsVariant[key] === undefined || propsVariant[key] === null) + ); } - return false -} + return false; +}; const parseVariantWithClassesList =

( props: WithVariantPropsAndClassesList, classesListKeys: Readonly>, globalConfiguration?: WithVariantPropsAndClassesList, - defaultConfiguration?: WithVariantPropsAndClassesList + defaultConfiguration?: WithVariantPropsAndClassesList, ): P => { const { variants, variant, ...mainProps } = { ...defaultConfiguration, ...globalConfiguration, ...props, - } + }; - const classes: Partial> = {} - const fixedClasses: Partial> = {} + const classes: Partial> = {}; + const fixedClasses: Partial> = {}; - const clearClasses = getShouldClearClasses(props, 'classes', variant) + const clearClasses = getShouldClearClasses(props, 'classes', variant); - const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant) + const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant); if (clearClasses) { classesListKeys.forEach((classItemKey) => { - classes[classItemKey] = undefined - }) + classes[classItemKey] = undefined; + }); } else { classesListKeys.forEach((classItemKey) => { // Get classes from global configuration or alternatively from library configuration if ( - globalConfiguration && - isObject(globalConfiguration.classes) && - classItemKey in globalConfiguration.classes + globalConfiguration + && isObject(globalConfiguration.classes) + && classItemKey in globalConfiguration.classes ) { - classes[classItemKey] = globalConfiguration.classes[classItemKey] + classes[classItemKey] = globalConfiguration.classes[classItemKey]; } else if ( - defaultConfiguration && - isObject(defaultConfiguration.classes) && - classItemKey in defaultConfiguration.classes + defaultConfiguration + && isObject(defaultConfiguration.classes) + && classItemKey in defaultConfiguration.classes ) { - classes[classItemKey] = defaultConfiguration.classes[classItemKey] + classes[classItemKey] = defaultConfiguration.classes[classItemKey]; } // Get classes from props and merge them with the previous ones if (isObject(props.classes) && classItemKey in props.classes) { if (typeof props.classes[classItemKey] !== 'undefined') { - classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]] + classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]]; } else { - classes[classItemKey] = undefined + classes[classItemKey] = undefined; } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

+ const propsVariant = props.variants[variant] as WithVariantProps

; if (isObject(propsVariant.classes) && classItemKey in propsVariant.classes) { - classes[classItemKey] = propsVariant.classes[classItemKey] + classes[classItemKey] = propsVariant.classes[classItemKey]; } } else if ( - globalConfiguration && - isObject(globalConfiguration.variants) && - variant in globalConfiguration.variants + globalConfiguration + && isObject(globalConfiguration.variants) + && variant in globalConfiguration.variants ) { const globalConfigurationVariant = globalConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - globalConfigurationVariant.classes && - isObject(globalConfigurationVariant.classes) && - classItemKey in globalConfigurationVariant.classes + globalConfigurationVariant.classes + && isObject(globalConfigurationVariant.classes) + && classItemKey in globalConfigurationVariant.classes ) { - classes[classItemKey] = globalConfigurationVariant.classes[classItemKey] + classes[classItemKey] = globalConfigurationVariant.classes[classItemKey]; } } else if ( - defaultConfiguration !== undefined && - defaultConfiguration.variants !== undefined && - defaultConfiguration.variants[variant] !== undefined + defaultConfiguration !== undefined + && defaultConfiguration.variants !== undefined + && defaultConfiguration.variants[variant] !== undefined ) { const defaultConfigurationVariant = defaultConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - defaultConfigurationVariant.classes && - isObject(defaultConfigurationVariant.classes) && - classItemKey in defaultConfigurationVariant.classes + defaultConfigurationVariant.classes + && isObject(defaultConfigurationVariant.classes) + && classItemKey in defaultConfigurationVariant.classes ) { - classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey] + classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey]; } } } - }) + }); } if (clearFixedClasses) { classesListKeys.forEach((classItemKey) => { - fixedClasses[classItemKey] = undefined - }) + fixedClasses[classItemKey] = undefined; + }); } else { classesListKeys.forEach((classItemKey) => { // Get classes from global configuration or alternatively from library configuration if ( - globalConfiguration && - isObject(globalConfiguration.fixedClasses) && - classItemKey in globalConfiguration.fixedClasses + globalConfiguration + && isObject(globalConfiguration.fixedClasses) + && classItemKey in globalConfiguration.fixedClasses ) { - fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey] + fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey]; } else if ( - defaultConfiguration && - isObject(defaultConfiguration.fixedClasses) && - classItemKey in defaultConfiguration.fixedClasses + defaultConfiguration + && isObject(defaultConfiguration.fixedClasses) + && classItemKey in defaultConfiguration.fixedClasses ) { - fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey] + fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey]; } // Get classes from props and merge them with the previous ones if (isObject(props.fixedClasses) && classItemKey in props.fixedClasses) { if (typeof props.fixedClasses[classItemKey] !== 'undefined') { - fixedClasses[classItemKey] = [fixedClasses[classItemKey], props.fixedClasses[classItemKey]] - } else { - classes[classItemKey] = undefined - } + fixedClasses[classItemKey] = [fixedClasses[classItemKey], props.fixedClasses[classItemKey]]; + } else { + classes[classItemKey] = undefined; + } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

+ const propsVariant = props.variants[variant] as WithVariantProps

; if (isObject(propsVariant.fixedClasses) && classItemKey in propsVariant.fixedClasses) { - fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey] + fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey]; } } else if ( - globalConfiguration !== undefined && - globalConfiguration.variants !== undefined && - globalConfiguration.variants[variant] !== undefined + globalConfiguration !== undefined + && globalConfiguration.variants !== undefined + && globalConfiguration.variants[variant] !== undefined ) { const globalConfigurationVariant = globalConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - isObject(globalConfigurationVariant.fixedClasses) && - classItemKey in globalConfigurationVariant.fixedClasses + isObject(globalConfigurationVariant.fixedClasses) + && classItemKey in globalConfigurationVariant.fixedClasses ) { - fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey] + fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey]; } } else if ( - defaultConfiguration !== undefined && - defaultConfiguration.variants !== undefined && - defaultConfiguration.variants[variant] !== undefined + defaultConfiguration !== undefined + && defaultConfiguration.variants !== undefined + && defaultConfiguration.variants[variant] !== undefined ) { const defaultConfigurationVariant = defaultConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - isObject(defaultConfigurationVariant.fixedClasses) && - classItemKey in defaultConfigurationVariant.fixedClasses + isObject(defaultConfigurationVariant.fixedClasses) + && classItemKey in defaultConfigurationVariant.fixedClasses ) { - fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey] + fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey]; } } } - }) + }); } - const customProps = getCustomPropsFromVariant(variants, variant) + const customProps = getCustomPropsFromVariant(variants, variant); const mergedProps = { ...mainProps, ...customProps, - } + }; - delete mergedProps.fixedClasses + delete mergedProps.fixedClasses; - delete mergedProps.classes + delete mergedProps.classes; - const mergedClasses: CSSClassesList = {} + const mergedClasses: CSSClassesList = {}; classesListKeys.forEach((classItemKey) => { - const classesForTheCurrentKey = classes[classItemKey] - const fixedClassesForTheCurrentKey = fixedClasses[classItemKey] + const classesForTheCurrentKey = classes[classItemKey]; + const fixedClassesForTheCurrentKey = fixedClasses[classItemKey]; mergedClasses[classItemKey as string] = mergeClasses( classesForTheCurrentKey, - fixedClassesForTheCurrentKey - ) - }) + fixedClassesForTheCurrentKey, + ); + }); - const result = pick(mergedClasses) + const result = pick(mergedClasses); if (Object.keys(result).length > 0) { - ;(mergedProps as P).classesList = result + (mergedProps as P).classesList = result; } - return mergedProps as P -} + return mergedProps as P; +}; -export default parseVariantWithClassesList +export default parseVariantWithClassesList; diff --git a/src/types/CSSClass.ts b/src/types/CSSClass.ts index fc76c8c..418811f 100644 --- a/src/types/CSSClass.ts +++ b/src/types/CSSClass.ts @@ -1,8 +1,8 @@ export type CSSClassKeyValuePair = { [key: string]: CSSClass -} +}; -export type CSSClasses = CSSClass[] +export type CSSClasses = CSSClass[]; export type CSSClass = | CSSClassKeyValuePair @@ -12,15 +12,15 @@ export type CSSClass = | null | boolean | ((modifiers: { - clear: () => void - add: (cssClass: string) => void - remove: (cssClass: string) => void - }) => void) + clear: () => void + add: (cssClass: string) => void + remove: (cssClass: string) => void + }) => void); export type CSSRawClassesList = { [key in ClassesKeys]?: CSSClass -} +}; export type CSSClassesList = { [key in ClassesKeys]?: CSSClass -} +}; From dde5b2e0f1fcf580fb3587864c4f36f854574ec4 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Thu, 9 Dec 2021 14:38:40 +0100 Subject: [PATCH 3/5] style: prettier --- package.json | 1 + src/__tests__/addToArray.test.ts | 27 +- src/__tests__/clone.test.ts | 55 +-- src/__tests__/config.test.ts | 12 +- src/__tests__/dateIsPartOfTheRange.test.ts | 94 ++--- src/__tests__/dates/addDays.test.ts | 46 +-- src/__tests__/dates/addMonths.test.ts | 58 +-- src/__tests__/dates/addYears.test.ts | 42 +-- .../dates/buildDateFormatter.test.ts | 26 +- src/__tests__/dates/buildDateParser.test.ts | 26 +- .../dates/dayIsPartOfTheConditions.test.ts | 94 +++-- src/__tests__/dates/formatDate.test.ts | 187 +++++----- .../dates/getDateInDayNumber.test.ts | 20 +- .../dates/getFirstDayOfMonth.test.ts | 26 +- .../dates/getFirstDayOfNextMonth.test.ts | 32 +- .../dates/getFirstDayOfPrevMonth.test.ts | 32 +- src/__tests__/dates/getLastDayOfMonth.test.ts | 44 +-- .../dates/getLastDayOfPrevMonth.test.ts | 32 +- src/__tests__/dates/isSameDay.test.ts | 60 ++-- src/__tests__/dates/isSameMonth.test.ts | 60 ++-- src/__tests__/dates/isToday.test.ts | 26 +- src/__tests__/dates/parseDate.test.ts | 230 ++++++------ .../dates/visibleDaysInMonthView.test.ts | 100 +++--- src/__tests__/debounce.test.ts | 82 ++--- .../elementIsTargetOrTargetChild.test.ts | 50 +-- src/__tests__/filterOptions.test.ts | 24 +- src/__tests__/flattenOptions.test.ts | 28 +- src/__tests__/get.test.ts | 86 ++--- src/__tests__/getFocusableElements.test.ts | 159 ++++----- src/__tests__/hasProperty.test.ts | 36 +- src/__tests__/index.test.ts | 74 ++-- src/__tests__/isEqual.test.ts | 180 ++++++---- src/__tests__/isPrimitive.test.ts | 40 +-- src/__tests__/isTouchOnlyDevice.test.ts | 30 +- src/__tests__/mergeClasses.test.ts | 49 +-- src/__tests__/normalizeMeasure.test.ts | 36 +- src/__tests__/normalizeOptions.test.ts | 178 +++++----- .../normalizedOptionIsDisabled.test.ts | 30 +- src/__tests__/parseVariant.test.ts | 88 ++--- .../parseVariantWithClassesList.test.ts | 330 +++++++++--------- src/__tests__/pick.test.ts | 22 +- src/__tests__/promisify.test.ts | 28 +- src/__tests__/promisifyFunctionResult.test.ts | 83 ++--- src/__tests__/substractFromArray.test.ts | 30 +- src/__tests__/throttle.test.ts | 52 +-- src/config/TAlertConfig.ts | 16 +- src/config/TButtonConfig.ts | 4 +- src/config/TCardConfig.ts | 8 +- src/config/TCheckboxConfig.ts | 4 +- src/config/TDatepickerConfig.ts | 71 ++-- src/config/TDialogConfig.ts | 70 ++-- src/config/TDropdownConfig.ts | 14 +- src/config/TInputConfig.ts | 4 +- src/config/TInputGroupConfig.ts | 8 +- src/config/TModalConfig.ts | 15 +- src/config/TRadioConfig.ts | 4 +- src/config/TRichSelectConfig.ts | 22 +- src/config/TSelectConfig.ts | 4 +- src/config/TTagConfig.ts | 4 +- src/config/TTextareaConfig.ts | 4 +- src/config/TToggleConfig.ts | 44 ++- src/config/TWrappedCheckboxConfig.ts | 27 +- src/config/TWrappedRadioConfig.ts | 27 +- src/config/index.ts | 93 +++-- src/config/transitions.ts | 2 +- src/dates/addDays.ts | 14 +- src/dates/addMonths.ts | 16 +- src/dates/addYears.ts | 16 +- src/dates/buildDateFormatter.ts | 20 +- src/dates/buildDateParser.ts | 20 +- src/dates/dateIsPartOfTheRange.ts | 30 +- src/dates/dayIsPartOfTheConditions.ts | 29 +- src/dates/formatDate.ts | 81 ++--- src/dates/getDateInDayNumber.ts | 5 +- src/dates/getFirstDayOfMonth.ts | 5 +- src/dates/getFirstDayOfNextMonth.ts | 5 +- src/dates/getFirstDayOfPrevMonth.ts | 5 +- src/dates/getLastDayOfMonth.ts | 5 +- src/dates/getLastDayOfPrevMonth.ts | 5 +- src/dates/index.ts | 28 +- src/dates/isSameDay.ts | 14 +- src/dates/isSameMonth.ts | 8 +- src/dates/isToday.ts | 6 +- src/dates/l10n/ar.ts | 16 +- src/dates/l10n/at.ts | 31 +- src/dates/l10n/az.ts | 21 +- src/dates/l10n/be.ts | 33 +- src/dates/l10n/bg.ts | 16 +- src/dates/l10n/bn.ts | 16 +- src/dates/l10n/bs.ts | 31 +- src/dates/l10n/cat.ts | 30 +- src/dates/l10n/cs.ts | 33 +- src/dates/l10n/cy.ts | 39 +-- src/dates/l10n/da.ts | 31 +- src/dates/l10n/de.ts | 31 +- src/dates/l10n/default.ts | 41 +-- src/dates/l10n/eo.ts | 31 +- src/dates/l10n/es.ts | 31 +- src/dates/l10n/et.ts | 18 +- src/dates/l10n/fa.ts | 16 +- src/dates/l10n/fi.ts | 6 +- src/dates/l10n/fo.ts | 21 +- src/dates/l10n/fr.ts | 20 +- src/dates/l10n/ga.ts | 21 +- src/dates/l10n/gr.ts | 33 +- src/dates/l10n/he.ts | 6 +- src/dates/l10n/hi.ts | 16 +- src/dates/l10n/hr.ts | 16 +- src/dates/l10n/hu.ts | 18 +- src/dates/l10n/id.ts | 21 +- src/dates/l10n/index.ts | 126 +++---- src/dates/l10n/is.ts | 21 +- src/dates/l10n/it.ts | 31 +- src/dates/l10n/ja.ts | 16 +- src/dates/l10n/ka.ts | 33 +- src/dates/l10n/km.ts | 16 +- src/dates/l10n/ko.ts | 16 +- src/dates/l10n/kz.ts | 33 +- src/dates/l10n/lt.ts | 23 +- src/dates/l10n/lv.ts | 21 +- src/dates/l10n/mk.ts | 31 +- src/dates/l10n/mn.ts | 6 +- src/dates/l10n/ms.ts | 31 +- src/dates/l10n/my.ts | 16 +- src/dates/l10n/nl.ts | 20 +- src/dates/l10n/no.ts | 31 +- src/dates/l10n/pa.ts | 31 +- src/dates/l10n/pl.ts | 31 +- src/dates/l10n/pt.ts | 21 +- src/dates/l10n/ro.ts | 31 +- src/dates/l10n/ru.ts | 18 +- src/dates/l10n/si.ts | 16 +- src/dates/l10n/sk.ts | 33 +- src/dates/l10n/sl.ts | 33 +- src/dates/l10n/sq.ts | 31 +- src/dates/l10n/sr-cyr.ts | 31 +- src/dates/l10n/sr.ts | 31 +- src/dates/l10n/sv.ts | 31 +- src/dates/l10n/th.ts | 16 +- src/dates/l10n/tr.ts | 31 +- src/dates/l10n/uk.ts | 31 +- src/dates/l10n/uz.ts | 33 +- src/dates/l10n/uz_latn.ts | 18 +- src/dates/l10n/vn.ts | 16 +- src/dates/l10n/zh-tw.ts | 16 +- src/dates/l10n/zh.ts | 16 +- src/dates/parseDate.ts | 179 +++++----- src/dates/visibleDaysInMonthView.ts | 78 +++-- src/filterOptions.ts | 25 +- src/flattenOptions.ts | 17 +- src/helpers/addToArray.ts | 8 +- src/helpers/clone.ts | 10 +- src/helpers/debounce.ts | 30 +- src/helpers/elementIsTargetOrTargetChild.ts | 13 +- src/helpers/get.ts | 18 +- src/helpers/getFocusableElements.ts | 13 +- src/helpers/hasProperty.ts | 8 +- src/helpers/index.ts | 34 +- src/helpers/isEqual.ts | 4 +- src/helpers/isObject.ts | 12 +- src/helpers/isPrimitive.ts | 8 +- src/helpers/isTouchOnlyDevice.ts | 10 +- src/helpers/normalizeMeasure.ts | 14 +- src/helpers/normalizedOptionIsDisabled.ts | 7 +- src/helpers/pick.ts | 15 +- src/helpers/promisify.ts | 10 +- src/helpers/promisifyFunctionResult.ts | 15 +- src/helpers/substractFromArray.ts | 18 +- src/helpers/throttle.ts | 18 +- src/index.ts | 20 +- src/mergeClasses.ts | 43 +-- src/normalizeOptions.ts | 56 +-- src/parseVariant.ts | 34 +- src/parseVariantWithClassesList.ts | 201 +++++------ src/types/CSSClass.ts | 16 +- src/types/Dates.ts | 120 +++---- src/types/InputOptions.ts | 14 +- src/types/Misc.ts | 8 +- src/types/Modify.ts | 2 +- src/types/Variants.ts | 10 +- src/types/index.ts | 12 +- yarn.lock | 5 + 182 files changed, 2954 insertions(+), 3582 deletions(-) diff --git a/package.json b/package.json index 9d2b9c6..6070623 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "eslint-config-airbnb-typescript": "^12.3.1", "eslint-plugin-import": "^2.24.0", "jest": "^27.0.6", + "prettier": "^2.5.1", "release-it": "^14.11.3", "ts-jest": "^27.0.4", "typescript": "^4.4.3", diff --git a/src/__tests__/addToArray.test.ts b/src/__tests__/addToArray.test.ts index 2a758c7..f75631c 100644 --- a/src/__tests__/addToArray.test.ts +++ b/src/__tests__/addToArray.test.ts @@ -1,19 +1,22 @@ -import addToArray from '../helpers/addToArray'; +import addToArray from '../helpers/addToArray' describe('addToArray', () => { it('adds a new item ', () => { - const arr = [1, 2, 3]; - expect(addToArray(arr, 4)).toEqual([1, 2, 3, 4]); - }); + const arr = [1, 2, 3] + expect(addToArray(arr, 4)).toEqual([1, 2, 3, 4]) + }) it('adds a new item for objects', () => { - const arr = [{ a: 1 }, { b: '2' }, { three: '3' }]; - expect(addToArray(arr, { 'some-thing': { test: 1 } })) - .toEqual([{ a: 1 }, { b: '2' }, { three: '3' }, { 'some-thing': { test: 1 } }]); - }); + const arr = [{ a: 1 }, { b: '2' }, { three: '3' }] + expect(addToArray(arr, { 'some-thing': { test: 1 } })).toEqual([ + { a: 1 }, + { b: '2' }, + { three: '3' }, + { 'some-thing': { test: 1 } }, + ]) + }) it('returns an array with the item if parameter is not an array', () => { - expect(addToArray(null, 'whatever')) - .toEqual(['whatever']); - }); -}); + expect(addToArray(null, 'whatever')).toEqual(['whatever']) + }) +}) diff --git a/src/__tests__/clone.test.ts b/src/__tests__/clone.test.ts index 0ffbf2d..4b30e8d 100644 --- a/src/__tests__/clone.test.ts +++ b/src/__tests__/clone.test.ts @@ -1,22 +1,22 @@ -import clone from '../helpers/clone'; +import clone from '../helpers/clone' describe('clone', () => { it('clones an array', () => { - const arr = [1, 2, 3]; - expect(clone(arr)).toEqual(arr); - }); + const arr = [1, 2, 3] + expect(clone(arr)).toEqual(arr) + }) it('clones a date', () => { - const originalDate = new Date(2020, 3, 15, 11, 30, 59); - const date = new Date(2020, 3, 15, 11, 30, 59); - expect(clone(date)).toEqual(originalDate); - expect(date).toEqual(originalDate); - }); + const originalDate = new Date(2020, 3, 15, 11, 30, 59) + const date = new Date(2020, 3, 15, 11, 30, 59) + expect(clone(date)).toEqual(originalDate) + expect(date).toEqual(originalDate) + }) it('clones an array with mixed values', () => { - const arr = [1, '2', null, '', { a: 1 }]; - expect(clone(arr)).toEqual(arr); - }); + const arr = [1, '2', null, '', { a: 1 }] + expect(clone(arr)).toEqual(arr) + }) it('clones an object with mixed values', () => { const obj = { @@ -25,21 +25,26 @@ describe('clone', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - }; - expect(clone(obj)).toEqual(obj); - }); + } + expect(clone(obj)).toEqual(obj) + }) it('makes a deep clone', () => { - const obj = [{ - a: 1, - test: 2, - something: { + const obj = [ + { a: 1, - hola: 'Mundo', - 'an-array': [1, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + test: 2, + something: { + a: 1, + hola: 'Mundo', + 'an-array': [1, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + }, }, - }, null, [], { a: 1, b: 2, c: 3 }]; + null, + [], + { a: 1, b: 2, c: 3 }, + ] - expect(clone(obj)).toEqual(obj); - }); -}); + expect(clone(obj)).toEqual(obj) + }) +}) diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index 81d4890..e0feb0d 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -1,4 +1,4 @@ -import * as config from '../config/index'; +import * as config from '../config/index' it('exports all the configs and keys', () => { const keys = [ @@ -36,12 +36,12 @@ it('exports all the configs and keys', () => { 'TWrappedRadioClassesKeys', 'TWrappedCheckboxConfig', 'TWrappedCheckboxClassesKeys', - ]; + ] - expect(Object.keys(config)).toEqual(keys); + expect(Object.keys(config)).toEqual(keys) keys.forEach((key) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - expect((config as any)[key]).toBeTruthy(); - }); -}); + expect((config as any)[key]).toBeTruthy() + }) +}) diff --git a/src/__tests__/dateIsPartOfTheRange.test.ts b/src/__tests__/dateIsPartOfTheRange.test.ts index fce6ada..48d74d1 100644 --- a/src/__tests__/dateIsPartOfTheRange.test.ts +++ b/src/__tests__/dateIsPartOfTheRange.test.ts @@ -1,75 +1,75 @@ -import dateIsPartOfTheRange from '../dates/dateIsPartOfTheRange'; +import dateIsPartOfTheRange from '../dates/dateIsPartOfTheRange' describe('dateIsPartOfTheRange', () => { it('returns true if date is exactly the same date as the min date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0); - const min = new Date(2010, 0, 1, 0, 0, 0, 0); - const max = new Date(2010, 0, 1, 0, 0, 0, 1); + const date = new Date(2010, 0, 1, 0, 0, 0, 0) + const min = new Date(2010, 0, 1, 0, 0, 0, 0) + const max = new Date(2010, 0, 1, 0, 0, 0, 1) - expect(dateIsPartOfTheRange(date, min, max)).toBe(true); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(true) + }) it('returns true if date is exactly the same date as the min date and max date is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0); - const min = new Date(2010, 0, 1, 0, 0, 0, 0); - const max = undefined; + const date = new Date(2010, 0, 1, 0, 0, 0, 0) + const min = new Date(2010, 0, 1, 0, 0, 0, 0) + const max = undefined - expect(dateIsPartOfTheRange(date, min, max)).toBe(true); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(true) + }) it('returns true if date is exactly the max date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1); - const min = new Date(2010, 0, 1, 0, 0, 0, 0); - const max = new Date(2010, 0, 1, 0, 0, 0, 1); + const date = new Date(2010, 0, 1, 0, 0, 0, 1) + const min = new Date(2010, 0, 1, 0, 0, 0, 0) + const max = new Date(2010, 0, 1, 0, 0, 0, 1) - expect(dateIsPartOfTheRange(date, min, max)).toBe(true); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(true) + }) it('returns true if date is exactly the max date and min date is undefined', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1); - const min = undefined; - const max = new Date(2010, 0, 1, 0, 0, 0, 1); + const date = new Date(2010, 0, 1, 0, 0, 0, 1) + const min = undefined + const max = new Date(2010, 0, 1, 0, 0, 0, 1) - expect(dateIsPartOfTheRange(date, min, max)).toBe(true); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(true) + }) it('returns false if date is before the min date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0); - const min = new Date(2010, 0, 1, 0, 0, 0, 1); - const max = new Date(2010, 0, 1, 0, 0, 0, 2); + const date = new Date(2010, 0, 1, 0, 0, 0, 0) + const min = new Date(2010, 0, 1, 0, 0, 0, 1) + const max = new Date(2010, 0, 1, 0, 0, 0, 2) - expect(dateIsPartOfTheRange(date, min, max)).toBe(false); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(false) + }) it('returns false if date is before the min date and max date is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0); - const min = new Date(2010, 0, 1, 0, 0, 0, 1); - const max = undefined; + const date = new Date(2010, 0, 1, 0, 0, 0, 0) + const min = new Date(2010, 0, 1, 0, 0, 0, 1) + const max = undefined - expect(dateIsPartOfTheRange(date, min, max)).toBe(false); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(false) + }) it('returns false if date is after the max date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 2); - const min = new Date(2010, 0, 1, 0, 0, 0, 1); - const max = new Date(2010, 0, 1, 0, 0, 0, 1); + const date = new Date(2010, 0, 1, 0, 0, 0, 2) + const min = new Date(2010, 0, 1, 0, 0, 0, 1) + const max = new Date(2010, 0, 1, 0, 0, 0, 1) - expect(dateIsPartOfTheRange(date, min, max)).toBe(false); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(false) + }) it('returns false if date is after the max date and min is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1); - const min = undefined; - const max = new Date(2010, 0, 1, 0, 0, 0, 0); + const date = new Date(2010, 0, 1, 0, 0, 0, 1) + const min = undefined + const max = new Date(2010, 0, 1, 0, 0, 0, 0) - expect(dateIsPartOfTheRange(date, min, max)).toBe(false); - }); + expect(dateIsPartOfTheRange(date, min, max)).toBe(false) + }) it('returns true if max and min is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1); - const min = undefined; - const max = undefined; + const date = new Date(2010, 0, 1, 0, 0, 0, 1) + const min = undefined + const max = undefined - expect(dateIsPartOfTheRange(date, min, max)).toBe(true); - }); -}); + expect(dateIsPartOfTheRange(date, min, max)).toBe(true) + }) +}) diff --git a/src/__tests__/dates/addDays.test.ts b/src/__tests__/dates/addDays.test.ts index 41d2861..6e567e4 100644 --- a/src/__tests__/dates/addDays.test.ts +++ b/src/__tests__/dates/addDays.test.ts @@ -1,39 +1,39 @@ -import addDays from '../../dates/addDays'; +import addDays from '../../dates/addDays' describe('addDays', () => { it('adds 1 day by default', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2020, 0, 16); + const date = new Date(2020, 0, 15) + const expected = new Date(2020, 0, 16) - expect(addDays(date)).toEqual(expected); - }); + expect(addDays(date)).toEqual(expected) + }) it('changes the month if last day of month', () => { - const date = new Date(2021, 9, 31); - const expected = new Date(2021, 10, 1); + const date = new Date(2021, 9, 31) + const expected = new Date(2021, 10, 1) - expect(addDays(date)).toEqual(expected); - }); + expect(addDays(date)).toEqual(expected) + }) it('accepts a custom amount of days', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2020, 0, 18); + const date = new Date(2020, 0, 15) + const expected = new Date(2020, 0, 18) - expect(addDays(date, 3)).toEqual(expected); - }); + expect(addDays(date, 3)).toEqual(expected) + }) it('accepts a negative amount of days', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2020, 0, 12); + const date = new Date(2020, 0, 15) + const expected = new Date(2020, 0, 12) - expect(addDays(date, -3)).toEqual(expected); - }); + expect(addDays(date, -3)).toEqual(expected) + }) it('doesnt affect the original date', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2020, 0, 16); + const date = new Date(2020, 0, 15) + const expected = new Date(2020, 0, 16) - expect(addDays(date)).toEqual(expected); - expect(date).toEqual(new Date(2020, 0, 15)); - }); -}); + expect(addDays(date)).toEqual(expected) + expect(date).toEqual(new Date(2020, 0, 15)) + }) +}) diff --git a/src/__tests__/dates/addMonths.test.ts b/src/__tests__/dates/addMonths.test.ts index a4d30c5..f157824 100644 --- a/src/__tests__/dates/addMonths.test.ts +++ b/src/__tests__/dates/addMonths.test.ts @@ -1,51 +1,51 @@ -import addMonths from '../../dates/addMonths'; +import addMonths from '../../dates/addMonths' describe('addMonths', () => { it('adds 1 month by default', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2020, 1, 15); + const date = new Date(2020, 0, 15) + const expected = new Date(2020, 1, 15) - expect(addMonths(date)).toEqual(expected); - }); + expect(addMonths(date)).toEqual(expected) + }) it('changes the year if last month', () => { - const date = new Date(2021, 11, 15); - const expected = new Date(2022, 0, 15); + const date = new Date(2021, 11, 15) + const expected = new Date(2022, 0, 15) - expect(addMonths(date)).toEqual(expected); - }); + expect(addMonths(date)).toEqual(expected) + }) it('uses the last day of next month if doesnt have an equivalent', () => { - const date = new Date(2021, 9, 31); - const expected = new Date(2021, 10, 30); + const date = new Date(2021, 9, 31) + const expected = new Date(2021, 10, 30) - expect(addMonths(date)).toEqual(expected); - }); + expect(addMonths(date)).toEqual(expected) + }) it('uses the last day of next month if doesnt have an equivalent for a month with 28 days', () => { - const date = new Date(2021, 0, 31); - const expected = new Date(2021, 1, 28); + const date = new Date(2021, 0, 31) + const expected = new Date(2021, 1, 28) - expect(addMonths(date)).toEqual(expected); - }); + expect(addMonths(date)).toEqual(expected) + }) it('accepts a custom amount of months', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2020, 3, 15); + const date = new Date(2020, 0, 15) + const expected = new Date(2020, 3, 15) - expect(addMonths(date, 3)).toEqual(expected); - }); + expect(addMonths(date, 3)).toEqual(expected) + }) it('accepts a negative amount of months', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2019, 9, 15); + const date = new Date(2020, 0, 15) + const expected = new Date(2019, 9, 15) - expect(addMonths(date, -3)).toEqual(expected); - }); + expect(addMonths(date, -3)).toEqual(expected) + }) it('doesnt affect the original date', () => { - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(date).toEqual(new Date(2020, 0, 15)); - }); -}); + expect(date).toEqual(new Date(2020, 0, 15)) + }) +}) diff --git a/src/__tests__/dates/addYears.test.ts b/src/__tests__/dates/addYears.test.ts index 37ed012..9a193e2 100644 --- a/src/__tests__/dates/addYears.test.ts +++ b/src/__tests__/dates/addYears.test.ts @@ -1,37 +1,37 @@ -import addYears from '../../dates/addYears'; +import addYears from '../../dates/addYears' describe('addYears', () => { it('adds 1 year by default', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2021, 0, 15); + const date = new Date(2020, 0, 15) + const expected = new Date(2021, 0, 15) - expect(addYears(date)).toEqual(expected); - }); + expect(addYears(date)).toEqual(expected) + }) it('uses the last day of same month if doesnt have an equivalent', () => { - const date = new Date(2024, 1, 29); - const expected = new Date(2025, 1, 28); + const date = new Date(2024, 1, 29) + const expected = new Date(2025, 1, 28) - expect(addYears(date)).toEqual(expected); - }); + expect(addYears(date)).toEqual(expected) + }) it('accepts a custom amount of years', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2023, 0, 15); + const date = new Date(2020, 0, 15) + const expected = new Date(2023, 0, 15) - expect(addYears(date, 3)).toEqual(expected); - }); + expect(addYears(date, 3)).toEqual(expected) + }) it('accepts a negative amount of years', () => { - const date = new Date(2020, 0, 15); - const expected = new Date(2017, 0, 15); + const date = new Date(2020, 0, 15) + const expected = new Date(2017, 0, 15) - expect(addYears(date, -3)).toEqual(expected); - }); + expect(addYears(date, -3)).toEqual(expected) + }) it('doesnt affect the original date', () => { - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(date).toEqual(new Date(2020, 0, 15)); - }); -}); + expect(date).toEqual(new Date(2020, 0, 15)) + }) +}) diff --git a/src/__tests__/dates/buildDateFormatter.test.ts b/src/__tests__/dates/buildDateFormatter.test.ts index f6a596c..d5ae967 100644 --- a/src/__tests__/dates/buildDateFormatter.test.ts +++ b/src/__tests__/dates/buildDateFormatter.test.ts @@ -1,18 +1,18 @@ -import { DateFormatter } from '../../types/Dates'; -import buildDateFormatter from '../../dates/buildDateFormatter'; -import { English } from '../../dates/l10n/default'; +import { DateFormatter } from '../../types/Dates' +import buildDateFormatter from '../../dates/buildDateFormatter' +import { English } from '../../dates/l10n/default' describe('buildDateFormatter', () => { it('it returns the default formatter', () => { - const date = new Date(2021, 1, 3, 4, 5, 6); - const expected = '2021-02-03 04:05:06'; - expect(buildDateFormatter(English)(date)).toEqual(expected); - }); + const date = new Date(2021, 1, 3, 4, 5, 6) + const expected = '2021-02-03 04:05:06' + expect(buildDateFormatter(English)(date)).toEqual(expected) + }) it('it returns the custom formatter', () => { - const date = new Date(2021, 1, 3, 4, 5, 6); - const expected = 'format-like-this'; - const customFormatter: DateFormatter = () => expected; - expect(buildDateFormatter(English, customFormatter)(date)).toEqual(expected); - }); -}); + const date = new Date(2021, 1, 3, 4, 5, 6) + const expected = 'format-like-this' + const customFormatter: DateFormatter = () => expected + expect(buildDateFormatter(English, customFormatter)(date)).toEqual(expected) + }) +}) diff --git a/src/__tests__/dates/buildDateParser.test.ts b/src/__tests__/dates/buildDateParser.test.ts index 708a5c3..3fb1773 100644 --- a/src/__tests__/dates/buildDateParser.test.ts +++ b/src/__tests__/dates/buildDateParser.test.ts @@ -1,18 +1,18 @@ -import { DateParser } from '../../types/Dates'; -import buildDateParser from '../../dates/buildDateParser'; -import { English } from '../../dates/l10n/default'; +import { DateParser } from '../../types/Dates' +import buildDateParser from '../../dates/buildDateParser' +import { English } from '../../dates/l10n/default' describe('buildDateParser', () => { it('it returns the default parser', () => { - const date = '2021-02-03 04:05:06'; - const expected = new Date(2021, 1, 3, 4, 5, 6); - expect(buildDateParser(English)(date)).toEqual(expected); - }); + const date = '2021-02-03 04:05:06' + const expected = new Date(2021, 1, 3, 4, 5, 6) + expect(buildDateParser(English)(date)).toEqual(expected) + }) it('it returns the a custom parser', () => { - const date = '2021-02-03 04:05:06'; - const expected = new Date(2021, 1, 3, 4, 5, 6); - const customParser: DateParser = () => expected; - expect(buildDateParser(English, customParser)(date)).toEqual(expected); - }); -}); + const date = '2021-02-03 04:05:06' + const expected = new Date(2021, 1, 3, 4, 5, 6) + const customParser: DateParser = () => expected + expect(buildDateParser(English, customParser)(date)).toEqual(expected) + }) +}) diff --git a/src/__tests__/dates/dayIsPartOfTheConditions.test.ts b/src/__tests__/dates/dayIsPartOfTheConditions.test.ts index ef64342..e46c840 100644 --- a/src/__tests__/dates/dayIsPartOfTheConditions.test.ts +++ b/src/__tests__/dates/dayIsPartOfTheConditions.test.ts @@ -1,80 +1,68 @@ -import dayIsPartOfTheConditions from '../../dates/dayIsPartOfTheConditions'; -import dateParser from '../../dates/parseDate'; +import dayIsPartOfTheConditions from '../../dates/dayIsPartOfTheConditions' +import dateParser from '../../dates/parseDate' describe('dayIsPartOfTheConditions', () => { it('returns false for a null values', () => { - const condition = ''; - expect(dayIsPartOfTheConditions(null, condition, dateParser)).toBe(false); - }); + const condition = '' + expect(dayIsPartOfTheConditions(null, condition, dateParser)).toBe(false) + }) it('returns false for undefined value', () => { - const condition = ''; - expect(dayIsPartOfTheConditions(undefined, condition, dateParser)).toBe(false); - }); + const condition = '' + expect(dayIsPartOfTheConditions(undefined, condition, dateParser)).toBe(false) + }) it('accept a custom condition to check the date', () => { - const date = new Date(2019, 1, 1); - const condition = (d: Date) => d.getFullYear() === 2019; - expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(true); - }); + const date = new Date(2019, 1, 1) + const condition = (d: Date) => d.getFullYear() === 2019 + expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(true) + }) it('accept a custom condition to check the date that return false', () => { - const date = new Date(2019, 1, 1); - const condition = (d: Date) => d.getFullYear() === 2018; - expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false); - }); + const date = new Date(2019, 1, 1) + const condition = (d: Date) => d.getFullYear() === 2018 + expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false) + }) it('returns true is date is in the same date as the condition', () => { - const date = new Date(2019, 1, 1, 10, 0, 0); - const conditonDate = new Date(2019, 1, 1, 10, 0, 0); + const date = new Date(2019, 1, 1, 10, 0, 0) + const conditonDate = new Date(2019, 1, 1, 10, 0, 0) - expect(dayIsPartOfTheConditions(date, conditonDate, dateParser)).toBe(true); - }); + expect(dayIsPartOfTheConditions(date, conditonDate, dateParser)).toBe(true) + }) it('returns true is date is in the same date as the condition using the date parser', () => { - const date = new Date(2019, 0, 1, 10, 0, 0); - const conditonDate = '2019-01-01'; + const date = new Date(2019, 0, 1, 10, 0, 0) + const conditonDate = '2019-01-01' - expect(dayIsPartOfTheConditions(date, conditonDate, dateParser, 'Y-m-d')).toBe(true); - }); + expect(dayIsPartOfTheConditions(date, conditonDate, dateParser, 'Y-m-d')).toBe(true) + }) it('handles an array of conditions', () => { - const date = new Date(2019, 0, 1); - const conditions = [ - (d: Date) => d.getFullYear() === 2019, - '2019-01-01', - new Date(2019, 0, 1), - ]; + const date = new Date(2019, 0, 1) + const conditions = [(d: Date) => d.getFullYear() === 2019, '2019-01-01', new Date(2019, 0, 1)] - expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true); - }); + expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true) + }) it('handles an array of conditions if one condition is false', () => { - const date = new Date(2019, 0, 1); - const conditions = [ - (d: Date) => d.getFullYear() !== 2019, - '2019-01-01', - new Date(2019, 0, 1), - ]; + const date = new Date(2019, 0, 1) + const conditions = [(d: Date) => d.getFullYear() !== 2019, '2019-01-01', new Date(2019, 0, 1)] - expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true); - }); + expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true) + }) it('handles an array of conditions if all condition are false', () => { - const date = new Date(2019, 0, 1); - const conditions = [ - (d: Date) => d.getFullYear() !== 2019, - '2019-02-01', - new Date(2010, 0, 1), - ]; + const date = new Date(2019, 0, 1) + const conditions = [(d: Date) => d.getFullYear() !== 2019, '2019-02-01', new Date(2010, 0, 1)] - expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(false); - }); + expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(false) + }) it('returns false if invalid condition', () => { - const date = new Date(2019, 0, 1); - const condition = 1; + const date = new Date(2019, 0, 1) + const condition = 1 - expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false); - }); -}); + expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false) + }) +}) diff --git a/src/__tests__/dates/formatDate.test.ts b/src/__tests__/dates/formatDate.test.ts index 844267f..58ede07 100644 --- a/src/__tests__/dates/formatDate.test.ts +++ b/src/__tests__/dates/formatDate.test.ts @@ -1,166 +1,189 @@ -import { DateLocale } from '../../types/Dates'; -import formatDate from '../../dates/formatDate'; -import { English as defaultLocale } from '../../dates/l10n/default'; -import { Spanish } from '../../dates/l10n/es'; +import { DateLocale } from '../../types/Dates' +import formatDate from '../../dates/formatDate' +import { English as defaultLocale } from '../../dates/l10n/default' +import { Spanish } from '../../dates/l10n/es' describe('formatDate', () => { - const format = 'Y-m-d H:i:S'; + const format = 'Y-m-d H:i:S' it('returns an empty string if for null values', () => { - expect(formatDate(null, format)).toBe(''); - }); + expect(formatDate(null, format)).toBe('') + }) it('formats the date', () => { - const date = new Date(2021, 6, 1, 12, 30, 45); - expect(formatDate(date, format)).toBe('2021-07-01 12:30:45'); - }); + const date = new Date(2021, 6, 1, 12, 30, 45) + expect(formatDate(date, format)).toBe('2021-07-01 12:30:45') + }) it('formats considering an escaped token', () => { - const date = new Date(2021, 6, 1, 12, 30, 45); - expect(formatDate(date, '\\Y-m-d H:i:S')).toBe('Y-07-01 12:30:45'); - }); + const date = new Date(2021, 6, 1, 12, 30, 45) + expect(formatDate(date, '\\Y-m-d H:i:S')).toBe('Y-07-01 12:30:45') + }) describe('format a single token', () => { - const date = new Date(2021, 6, 1, 20, 11, 8); + const date = new Date(2021, 6, 1, 20, 11, 8) // d / Day of the month, 2 digits with leading zeros / 01 to 31 it('d', () => { - expect(formatDate(date, 'd')).toEqual('01'); - }); + expect(formatDate(date, 'd')).toEqual('01') + }) // D / A textual representation of a day / Mon through Sun it('D', () => { // Doesnt affect the date when parsing - expect(formatDate(date, 'D')).toEqual('Thu'); - }); + expect(formatDate(date, 'D')).toEqual('Thu') + }) // l (lowercase 'L') / A full textual representation of the day of the week / Sunday through Saturday it('l', () => { // Doesnt affect the date when parsing - expect(formatDate(date, 'l')).toEqual('Thursday'); - }); + expect(formatDate(date, 'l')).toEqual('Thursday') + }) // j / Day of the month without leading zeros / 1 to 31 it('j', () => { - expect(formatDate(date, 'j')).toEqual('1'); - }); + expect(formatDate(date, 'j')).toEqual('1') + }) // J / Day of the month without leading zeros and ordinal suffix / 1st, 2nd, to 31st it('J', () => { - expect(formatDate(date, 'J')).toEqual('1st'); - }); + expect(formatDate(date, 'J')).toEqual('1st') + }) it('J nd', () => { - const date2d = new Date(2021, 6, 2); - expect(formatDate(date2d, 'J')).toEqual('2nd'); - }); + const date2d = new Date(2021, 6, 2) + expect(formatDate(date2d, 'J')).toEqual('2nd') + }) it('J rd', () => { - const date3d = new Date(2021, 6, 3); - expect(formatDate(date3d, 'J')).toEqual('3rd'); - }); + const date3d = new Date(2021, 6, 3) + expect(formatDate(date3d, 'J')).toEqual('3rd') + }) it('J th', () => { - const date3d = new Date(2021, 6, 4); - expect(formatDate(date3d, 'J')).toEqual('4th'); - }); + const date3d = new Date(2021, 6, 4) + expect(formatDate(date3d, 'J')).toEqual('4th') + }) // w / Numeric representation of the day of the week / 0 (for Sunday) through 6 (for Saturday) it('w', () => { // Doesnt affect the date when parsing - expect(formatDate(date, 'w')).toEqual('4'); - }); + expect(formatDate(date, 'w')).toEqual('4') + }) // W / Numeric representation of the week / 0 (first week of the year) through 52 (last week of the year) it('W', () => { - expect(formatDate(date, 'W')).toEqual('26'); - }); + expect(formatDate(date, 'W')).toEqual('26') + }) // F / A full textual representation of a month / January through December it('F', () => { - expect(formatDate(date, 'F')).toEqual('July'); - }); + expect(formatDate(date, 'F')).toEqual('July') + }) // m / Numeric representation of a month, with leading zero / 01 through 12 it('m', () => { - expect(formatDate(date, 'm')).toEqual('07'); - }); + expect(formatDate(date, 'm')).toEqual('07') + }) // n / Numeric representation of a month, without leading zeros / 1 through 12 it('n', () => { // Timezone affected because the daylight saving - expect(formatDate(date, 'n')).toEqual('7'); - }); + expect(formatDate(date, 'n')).toEqual('7') + }) // M / A short textual representation of a month / Jan through Dec it('M', () => { - expect(formatDate(date, 'M')).toEqual('Jul'); - }); + expect(formatDate(date, 'M')).toEqual('Jul') + }) // U / The number of seconds since the Unix Epoch / 1413704993 it('U', () => { - expect(formatDate(date, 'U')).toEqual('1625188268'); - }); + expect(formatDate(date, 'U')).toEqual('1625188268') + }) // y / A two digit representation of a year / 99 or 03 it('y', () => { - expect(formatDate(date, 'y')).toEqual('21'); - }); + expect(formatDate(date, 'y')).toEqual('21') + }) // Y / A full numeric representation of a year, 4 digits / 1999 or 2003 it('Y', () => { - expect(formatDate(date, 'Y')).toEqual('2021'); - }); + expect(formatDate(date, 'Y')).toEqual('2021') + }) // Z / ISO Date format / 2017-03-04T01:23:43.000Z it('Z', () => { - expect(formatDate(date, 'Z')).toEqual('2021-07-02T01:11:08.000Z'); - }); + expect(formatDate(date, 'Z')).toEqual('2021-07-02T01:11:08.000Z') + }) // H / Hours (24 hours) / 00 to 23 it('H', () => { - expect(formatDate(date, 'H')).toEqual('20'); - }); + expect(formatDate(date, 'H')).toEqual('20') + }) // h / Hours / 1 to 12 it('h', () => { - expect(formatDate(date, 'h')).toEqual('8'); - }); + expect(formatDate(date, 'h')).toEqual('8') + }) it('h at 12', () => { - const dateAfter12 = new Date(2021, 6, 1, 12); - expect(formatDate(dateAfter12, 'h')).toEqual('12'); - }); + const dateAfter12 = new Date(2021, 6, 1, 12) + expect(formatDate(dateAfter12, 'h')).toEqual('12') + }) // G / Hours, 2 digits with leading zeros / 1 to 12 it('G', () => { - expect(formatDate(date, 'G')).toEqual('08'); - }); + expect(formatDate(date, 'G')).toEqual('08') + }) // i / Minutes / 00 to 59 it('i', () => { - expect(formatDate(date, 'i')).toEqual('11'); - }); + expect(formatDate(date, 'i')).toEqual('11') + }) // S / Seconds, 2 digits / 00 to 59 it('S', () => { - expect(formatDate(date, 'S')).toEqual('08'); - }); + expect(formatDate(date, 'S')).toEqual('08') + }) // s / Seconds / 0, 1 to 59 it('s', () => { - expect(formatDate(date, 's')).toEqual('8'); - }); + expect(formatDate(date, 's')).toEqual('8') + }) // K / AM/PM / AM or PM it('K', () => { - expect(formatDate(date, 'K')).toEqual('PM'); - }); + expect(formatDate(date, 'K')).toEqual('PM') + }) it('K for AM', () => { - const dateAM = new Date(2021, 6, 1, 10, 11, 8); - expect(formatDate(dateAM, 'K')).toEqual('AM'); - }); - }); + const dateAM = new Date(2021, 6, 1, 10, 11, 8) + expect(formatDate(dateAM, 'K')).toEqual('AM') + }) + }) describe('Custom locale', () => { const allTokens = [ - 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'S', 'U', 'W', 'Y', 'Z', 'd', 'h', 'i', 'j', 'l', 'm', 'n', 's', 'w', 'y', - ]; + 'D', + 'F', + 'G', + 'H', + 'J', + 'K', + 'M', + 'S', + 'U', + 'W', + 'Y', + 'Z', + 'd', + 'h', + 'i', + 'j', + 'l', + 'm', + 'n', + 's', + 'w', + 'y', + ] it('Spanish', () => { - const date = new Date(2021, 6, 2, 8, 11, 8); + const date = new Date(2021, 6, 2, 8, 11, 8) const customLocale: DateLocale = { ...defaultLocale, ...Spanish, - }; - expect(formatDate(date, allTokens.join('-'), customLocale)).toEqual('Vie-Julio-08-08-2º-AM-Jul-08-1625231468-26-2021-2021-07-02T13:11:08.000Z-02-8-11-2-Viernes-07-7-8-5-21'); - }); - }); -}); + } + expect(formatDate(date, allTokens.join('-'), customLocale)).toEqual( + 'Vie-Julio-08-08-2º-AM-Jul-08-1625231468-26-2021-2021-07-02T13:11:08.000Z-02-8-11-2-Viernes-07-7-8-5-21' + ) + }) + }) +}) diff --git a/src/__tests__/dates/getDateInDayNumber.test.ts b/src/__tests__/dates/getDateInDayNumber.test.ts index 5f00657..cd6153c 100644 --- a/src/__tests__/dates/getDateInDayNumber.test.ts +++ b/src/__tests__/dates/getDateInDayNumber.test.ts @@ -1,19 +1,19 @@ -import getDateInDayNumber from '../../dates/getDateInDayNumber'; +import getDateInDayNumber from '../../dates/getDateInDayNumber' describe('getDateInDayNumber', () => { it('gets the same date in a day number', () => { // 2020-01-15 - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(getDateInDayNumber(date, 10)).toEqual(new Date(2020, 0, 10)); - }); + expect(getDateInDayNumber(date, 10)).toEqual(new Date(2020, 0, 10)) + }) it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12); - const date = new Date(2020, 0, 15, 10, 11, 12); + const originalDate = new Date(2020, 0, 15, 10, 11, 12) + const date = new Date(2020, 0, 15, 10, 11, 12) - getDateInDayNumber(date, 12); + getDateInDayNumber(date, 12) - expect(date).toEqual(originalDate); - }); -}); + expect(date).toEqual(originalDate) + }) +}) diff --git a/src/__tests__/dates/getFirstDayOfMonth.test.ts b/src/__tests__/dates/getFirstDayOfMonth.test.ts index 5c30ebb..199fbbe 100644 --- a/src/__tests__/dates/getFirstDayOfMonth.test.ts +++ b/src/__tests__/dates/getFirstDayOfMonth.test.ts @@ -1,26 +1,26 @@ -import getFirstDayOfMonth from '../../dates/getFirstDayOfMonth'; +import getFirstDayOfMonth from '../../dates/getFirstDayOfMonth' describe('getFirstDayOfMonth', () => { it('gets the first day of a month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 0, 1)); - }); + expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 0, 1)) + }) it('gets the first day of a month if pass the first day', () => { // 2020-04-01 - const date = new Date(2020, 3, 1); + const date = new Date(2020, 3, 1) - expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 3, 1)); - }); + expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 3, 1)) + }) it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12); - const date = new Date(2020, 0, 15, 10, 11, 12); + const originalDate = new Date(2020, 0, 15, 10, 11, 12) + const date = new Date(2020, 0, 15, 10, 11, 12) - getFirstDayOfMonth(date); + getFirstDayOfMonth(date) - expect(date).toEqual(originalDate); - }); -}); + expect(date).toEqual(originalDate) + }) +}) diff --git a/src/__tests__/dates/getFirstDayOfNextMonth.test.ts b/src/__tests__/dates/getFirstDayOfNextMonth.test.ts index f0c01d8..7bf35fa 100644 --- a/src/__tests__/dates/getFirstDayOfNextMonth.test.ts +++ b/src/__tests__/dates/getFirstDayOfNextMonth.test.ts @@ -1,33 +1,33 @@ -import getFirstDayOfNextMonth from '../../dates/getFirstDayOfNextMonth'; +import getFirstDayOfNextMonth from '../../dates/getFirstDayOfNextMonth' describe('getFirstDayOfNextMonth', () => { it('gets the first day of next month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)); - }); + expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)) + }) it('gets the first day of next month for last month', () => { // 2020-12-15 - const date = new Date(2020, 11, 15); + const date = new Date(2020, 11, 15) - expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2021, 0, 1)); - }); + expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2021, 0, 1)) + }) it('gets the first day of next month if last day', () => { // 2020-01-31 - const date = new Date(2020, 0, 31); + const date = new Date(2020, 0, 31) - expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)); - }); + expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)) + }) it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12); - const date = new Date(2020, 0, 15, 10, 11, 12); + const originalDate = new Date(2020, 0, 15, 10, 11, 12) + const date = new Date(2020, 0, 15, 10, 11, 12) - getFirstDayOfNextMonth(date); + getFirstDayOfNextMonth(date) - expect(date).toEqual(originalDate); - }); -}); + expect(date).toEqual(originalDate) + }) +}) diff --git a/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts b/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts index 815c35c..acb8266 100644 --- a/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts +++ b/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts @@ -1,33 +1,33 @@ -import getFirstDayOfPrevMonth from '../../dates/getFirstDayOfPrevMonth'; +import getFirstDayOfPrevMonth from '../../dates/getFirstDayOfPrevMonth' describe('getFirstDayOfPrevMonth', () => { it('gets the first day of prev month if is first month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 1)); - }); + expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 1)) + }) it('gets the first day of prev month if is last month', () => { // 2020-01-15 - const date = new Date(2020, 11, 15); + const date = new Date(2020, 11, 15) - expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)); - }); + expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)) + }) it('gets the first day of prev month when first day', () => { // 2020-01-1 - const date = new Date(2020, 11, 1); + const date = new Date(2020, 11, 1) - expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)); - }); + expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)) + }) it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12); - const date = new Date(2020, 0, 15, 10, 11, 12); + const originalDate = new Date(2020, 0, 15, 10, 11, 12) + const date = new Date(2020, 0, 15, 10, 11, 12) - getFirstDayOfPrevMonth(date); + getFirstDayOfPrevMonth(date) - expect(date).toEqual(originalDate); - }); -}); + expect(date).toEqual(originalDate) + }) +}) diff --git a/src/__tests__/dates/getLastDayOfMonth.test.ts b/src/__tests__/dates/getLastDayOfMonth.test.ts index 825e3d3..88f0b78 100644 --- a/src/__tests__/dates/getLastDayOfMonth.test.ts +++ b/src/__tests__/dates/getLastDayOfMonth.test.ts @@ -1,47 +1,47 @@ -import getLastDayOfMonth from '../../dates/getLastDayOfMonth'; +import getLastDayOfMonth from '../../dates/getLastDayOfMonth' describe('getLastDayOfMonth', () => { it('gets the last day of a month that have 31 days', () => { // 2020-01-15 - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 0, 31)); - }); + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 0, 31)) + }) it('gets the last day of a month that have 28 days', () => { // 2020-02-15 - const date = new Date(2020, 1, 15); + const date = new Date(2020, 1, 15) - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 1, 29)); - }); + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 1, 29)) + }) it('gets the last day of a month that have 30 days', () => { // 2020-04-15 - const date = new Date(2020, 3, 15); + const date = new Date(2020, 3, 15) - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)); - }); + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)) + }) it('gets the last day of a month if pass the last day', () => { // 2020-04-30 - const date = new Date(2020, 3, 30); + const date = new Date(2020, 3, 30) - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)); - }); + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)) + }) it('gets the last day of a month if pass the first day', () => { // 2020-04-30 - const date = new Date(2020, 3, 1); + const date = new Date(2020, 3, 1) - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)); - }); + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)) + }) it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12); - const date = new Date(2020, 0, 15, 10, 11, 12); + const originalDate = new Date(2020, 0, 15, 10, 11, 12) + const date = new Date(2020, 0, 15, 10, 11, 12) - getLastDayOfMonth(date); + getLastDayOfMonth(date) - expect(date).toEqual(originalDate); - }); -}); + expect(date).toEqual(originalDate) + }) +}) diff --git a/src/__tests__/dates/getLastDayOfPrevMonth.test.ts b/src/__tests__/dates/getLastDayOfPrevMonth.test.ts index 92ee9d7..278e799 100644 --- a/src/__tests__/dates/getLastDayOfPrevMonth.test.ts +++ b/src/__tests__/dates/getLastDayOfPrevMonth.test.ts @@ -1,33 +1,33 @@ -import getLastDayOfPrevMonth from '../../dates/getLastDayOfPrevMonth'; +import getLastDayOfPrevMonth from '../../dates/getLastDayOfPrevMonth' describe('getLastDayOfPrevMonth', () => { it('gets the last day of prev month if is first month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15); + const date = new Date(2020, 0, 15) - expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 31)); - }); + expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 31)) + }) it('gets the last day of prev month if has 29 days', () => { // 2020-03-15 - const date = new Date(2020, 2, 15); + const date = new Date(2020, 2, 15) - expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 1, 29)); - }); + expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 1, 29)) + }) it('gets the last day of prev month if has 30 days', () => { // 2020-07-15 - const date = new Date(2020, 6, 15); + const date = new Date(2020, 6, 15) - expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 5, 30)); - }); + expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 5, 30)) + }) it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12); - const date = new Date(2020, 0, 15, 10, 11, 12); + const originalDate = new Date(2020, 0, 15, 10, 11, 12) + const date = new Date(2020, 0, 15, 10, 11, 12) - getLastDayOfPrevMonth(date); + getLastDayOfPrevMonth(date) - expect(date).toEqual(originalDate); - }); -}); + expect(date).toEqual(originalDate) + }) +}) diff --git a/src/__tests__/dates/isSameDay.test.ts b/src/__tests__/dates/isSameDay.test.ts index 781f2c4..2e5c69b 100644 --- a/src/__tests__/dates/isSameDay.test.ts +++ b/src/__tests__/dates/isSameDay.test.ts @@ -1,51 +1,51 @@ -import isSameDay from '../../dates/isSameDay'; +import isSameDay from '../../dates/isSameDay' describe('isSameDay', () => { it('determines that is same day for the same date', () => { - const date1 = new Date(2020, 0, 15); - const date2 = new Date(2020, 0, 15); + const date1 = new Date(2020, 0, 15) + const date2 = new Date(2020, 0, 15) - expect(isSameDay(date1, date2)).toBe(true); - }); + expect(isSameDay(date1, date2)).toBe(true) + }) it('determines that is same day if different minute', () => { - const date1 = new Date(2020, 0, 15, 12); - const date2 = new Date(2020, 0, 15, 11); + const date1 = new Date(2020, 0, 15, 12) + const date2 = new Date(2020, 0, 15, 11) - expect(isSameDay(date1, date2)).toBe(true); - }); + expect(isSameDay(date1, date2)).toBe(true) + }) it('determines that a date is not the same if different month', () => { - const date1 = new Date(2020, 0, 15); - const date2 = new Date(2020, 1, 15); + const date1 = new Date(2020, 0, 15) + const date2 = new Date(2020, 1, 15) - expect(isSameDay(date1, date2)).toBe(false); - }); + expect(isSameDay(date1, date2)).toBe(false) + }) it('determines that a date is not in the same day if year is different', () => { - const date1 = new Date(2021, 0, 15); - const date2 = new Date(2020, 0, 15); + const date1 = new Date(2021, 0, 15) + const date2 = new Date(2020, 0, 15) - expect(isSameDay(date1, date2)).toBe(false); - }); + expect(isSameDay(date1, date2)).toBe(false) + }) it('determines that a date is not in the same day if second one is undefined', () => { - const date1 = new Date(2021, 0, 15); - const date2 = undefined; + const date1 = new Date(2021, 0, 15) + const date2 = undefined - expect(isSameDay(date1, date2)).toBe(false); - }); + expect(isSameDay(date1, date2)).toBe(false) + }) it('determines that a date is not in the same day if first one is undefined', () => { - const date1 = undefined; - const date2 = new Date(2021, 0, 15); + const date1 = undefined + const date2 = new Date(2021, 0, 15) - expect(isSameDay(date1, date2)).toBe(false); - }); + expect(isSameDay(date1, date2)).toBe(false) + }) it('determines that a date is not in the same day if both undefined', () => { - const date1 = undefined; - const date2 = undefined; + const date1 = undefined + const date2 = undefined - expect(isSameDay(date1, date2)).toBe(false); - }); -}); + expect(isSameDay(date1, date2)).toBe(false) + }) +}) diff --git a/src/__tests__/dates/isSameMonth.test.ts b/src/__tests__/dates/isSameMonth.test.ts index efed2f4..bdf8584 100644 --- a/src/__tests__/dates/isSameMonth.test.ts +++ b/src/__tests__/dates/isSameMonth.test.ts @@ -1,52 +1,52 @@ -import isSameMonth from '../../dates/isSameMonth'; +import isSameMonth from '../../dates/isSameMonth' describe('isSameMonth', () => { it('determines that the same date is in the same month', () => { - const date1 = new Date(2020, 0, 15); - const date2 = new Date(2020, 0, 15); + const date1 = new Date(2020, 0, 15) + const date2 = new Date(2020, 0, 15) - expect(isSameMonth(date1, date2)).toBe(true); - }); + expect(isSameMonth(date1, date2)).toBe(true) + }) it('determines that a date is in the same month if day is different', () => { - const date1 = new Date(2020, 0, 15); - const date2 = new Date(2020, 0, 15); + const date1 = new Date(2020, 0, 15) + const date2 = new Date(2020, 0, 15) - expect(isSameMonth(date1, date2)).toBe(true); - }); + expect(isSameMonth(date1, date2)).toBe(true) + }) it('determines that a date is not in the same month if year is different', () => { - const date1 = new Date(2021, 0, 15); - const date2 = new Date(2020, 0, 15); + const date1 = new Date(2021, 0, 15) + const date2 = new Date(2020, 0, 15) - expect(isSameMonth(date1, date2)).toBe(false); - }); + expect(isSameMonth(date1, date2)).toBe(false) + }) it('determines that a date is not in the same month', () => { - const date1 = new Date(2021, 0, 15); - const date2 = new Date(2021, 1, 15); + const date1 = new Date(2021, 0, 15) + const date2 = new Date(2021, 1, 15) - expect(isSameMonth(date1, date2)).toBe(false); - }); + expect(isSameMonth(date1, date2)).toBe(false) + }) it('determines that a date is not in the same month if second one is undefined', () => { - const date1 = new Date(2021, 0, 15); - const date2 = undefined; + const date1 = new Date(2021, 0, 15) + const date2 = undefined - expect(isSameMonth(date1, date2)).toBe(false); - }); + expect(isSameMonth(date1, date2)).toBe(false) + }) it('determines that a date is not in the same month if first one is undefined', () => { - const date1 = undefined; - const date2 = new Date(2021, 0, 15); + const date1 = undefined + const date2 = new Date(2021, 0, 15) - expect(isSameMonth(date1, date2)).toBe(false); - }); + expect(isSameMonth(date1, date2)).toBe(false) + }) it('determines that a date is not in the same month if both undefined', () => { - const date1 = undefined; - const date2 = undefined; + const date1 = undefined + const date2 = undefined - expect(isSameMonth(date1, date2)).toBe(false); - }); -}); + expect(isSameMonth(date1, date2)).toBe(false) + }) +}) diff --git a/src/__tests__/dates/isToday.test.ts b/src/__tests__/dates/isToday.test.ts index a8622d2..6b80472 100644 --- a/src/__tests__/dates/isToday.test.ts +++ b/src/__tests__/dates/isToday.test.ts @@ -1,22 +1,22 @@ -import isToday from '../../dates/isToday'; +import isToday from '../../dates/isToday' describe('isToday', () => { it('determines that is same day for current date', () => { - const date = new Date(); + const date = new Date() - expect(isToday(date)).toBe(true); - }); + expect(isToday(date)).toBe(true) + }) it('determines that is same day for a date at the end of the day', () => { - const date = new Date(); - const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999); + const date = new Date() + const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999) - expect(isToday(today)).toBe(true); - }); + expect(isToday(today)).toBe(true) + }) it('determines that is same day for a date at the start of the day', () => { - const date = new Date(); - const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0); + const date = new Date() + const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0) - expect(isToday(today)).toBe(true); - }); -}); + expect(isToday(today)).toBe(true) + }) +}) diff --git a/src/__tests__/dates/parseDate.test.ts b/src/__tests__/dates/parseDate.test.ts index 68602e0..6755bb6 100644 --- a/src/__tests__/dates/parseDate.test.ts +++ b/src/__tests__/dates/parseDate.test.ts @@ -1,218 +1,232 @@ -import parseDate from '../../dates/parseDate'; +import parseDate from '../../dates/parseDate' describe('parseDate', () => { - const defaultFormat = 'Y-m-d H:i:S'; - const timeless = true; + const defaultFormat = 'Y-m-d H:i:S' + const timeless = true describe('String parsing', () => { it('returns undefined if empty date string', () => { - expect(parseDate('')).toBeUndefined(); - }); + expect(parseDate('')).toBeUndefined() + }) it('returns undefined if NaN', () => { - expect(parseDate(NaN)).toBeUndefined(); - }); + expect(parseDate(NaN)).toBeUndefined() + }) it('returns undefined if passes a function', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const fn = (() => {}) as any; + const fn = (() => {}) as any - const parser = () => parseDate(fn); - expect(parser).toThrow(new Error('Invalid date provided: () => { }')); - }); + const parser = () => parseDate(fn) + expect(parser).toThrow(new Error('Invalid date provided: () => { }')) + }) it('returns today date if passed `today`', () => { - const today = new Date(new Date().getFullYear(), (new Date()).getMonth(), (new Date()).getDate(), 0, 0, 0, 0); - expect(parseDate('today')).toEqual(today); - }); + const today = new Date( + new Date().getFullYear(), + new Date().getMonth(), + new Date().getDate(), + 0, + 0, + 0, + 0 + ) + expect(parseDate('today')).toEqual(today) + }) it('parses gmt dates', () => { - expect(parseDate('Sat, 23 Oct 2021 20:58:00 GMT')) - .toEqual(new Date(Date.UTC(2021, 9, 23, 20, 58, 0, 0))); - }); + expect(parseDate('Sat, 23 Oct 2021 20:58:00 GMT')).toEqual( + new Date(Date.UTC(2021, 9, 23, 20, 58, 0, 0)) + ) + }) it('parses iso dates', () => { - expect(parseDate('2021-10-23T20:58:11.733Z')) - .toEqual(new Date(Date.UTC(2021, 9, 23, 20, 58, 11, 733))); - }); + expect(parseDate('2021-10-23T20:58:11.733Z')).toEqual( + new Date(Date.UTC(2021, 9, 23, 20, 58, 11, 733)) + ) + }) it('parses a date in the default format', () => { - expect(parseDate('2020-02-18 12:34:56')).toEqual(new Date(2020, 1, 18, 12, 34, 56)); - }); + expect(parseDate('2020-02-18 12:34:56')).toEqual(new Date(2020, 1, 18, 12, 34, 56)) + }) it('parses a date ignoring time', () => { - expect(parseDate('2020-02-18 12:34:56', defaultFormat, timeless)).toEqual(new Date(2020, 1, 18, 0, 0, 0)); - }); + expect(parseDate('2020-02-18 12:34:56', defaultFormat, timeless)).toEqual( + new Date(2020, 1, 18, 0, 0, 0) + ) + }) it('escapes the token', () => { - expect(parseDate('2020Y-02-18 12m:34:56', 'Y\\Y-m-d H\\m:i:S')).toEqual(new Date(2020, 1, 18, 12, 34, 56)); - }); + expect(parseDate('2020Y-02-18 12m:34:56', 'Y\\Y-m-d H\\m:i:S')).toEqual( + new Date(2020, 1, 18, 12, 34, 56) + ) + }) it('returns undefined if using an invalid format', () => { - const parser = () => parseDate('2020-11-12', 'X'); + const parser = () => parseDate('2020-11-12', 'X') - expect(parser).toThrow(new Error('Invalid date provided: 2020-11-12')); - }); + expect(parser).toThrow(new Error('Invalid date provided: 2020-11-12')) + }) it('returns undefined if dates doesnt matchs the format', () => { - const parser = () => parseDate('18021987', 'K'); + const parser = () => parseDate('18021987', 'K') - expect(parser).toThrow(new Error('Invalid date provided: 18021987')); - }); + expect(parser).toThrow(new Error('Invalid date provided: 18021987')) + }) describe('parse a single token', () => { - let baseDate: Date; + let baseDate: Date beforeEach(() => { - baseDate = new Date('2021-01-01T06:00:00.000Z'); + baseDate = new Date('2021-01-01T06:00:00.000Z') - jest - .useFakeTimers() - .setSystemTime(baseDate.getTime()); - }); + jest.useFakeTimers().setSystemTime(baseDate.getTime()) + }) afterEach(() => { - jest.useRealTimers(); - }); + jest.useRealTimers() + }) // d / Day of the month, 2 digits with leading zeros / 01 to 31 it('d', () => { - expect(parseDate('05', 'd')).toEqual(new Date('2021-01-05T06:00:00.000Z')); - }); + expect(parseDate('05', 'd')).toEqual(new Date('2021-01-05T06:00:00.000Z')) + }) // D / A textual representation of a day / Mon through Sun it('D', () => { // Doesnt affect the date when parsing - expect(parseDate('Tue', 'D')).toEqual(new Date('2021-01-01T06:00:00.000Z')); - }); + expect(parseDate('Tue', 'D')).toEqual(new Date('2021-01-01T06:00:00.000Z')) + }) // l (lowercase 'L') / A full textual representation of the day of the week / Sunday through Saturday it('l', () => { // Doesnt affect the date when parsing - expect(parseDate('Saturday', 'l')).toEqual(new Date('2021-01-01T06:00:00.000Z')); - }); + expect(parseDate('Saturday', 'l')).toEqual(new Date('2021-01-01T06:00:00.000Z')) + }) // j / Day of the month without leading zeros / 1 to 31 it('j', () => { - expect(parseDate('10', 'j')).toEqual(new Date('2021-01-10T06:00:00.000Z')); - }); + expect(parseDate('10', 'j')).toEqual(new Date('2021-01-10T06:00:00.000Z')) + }) // J / Day of the month without leading zeros and ordinal suffix / 1st, 2nd, to 31st it('J', () => { - expect(parseDate('22nd', 'J')).toEqual(new Date('2021-01-22T06:00:00.000Z')); - }); + expect(parseDate('22nd', 'J')).toEqual(new Date('2021-01-22T06:00:00.000Z')) + }) // w / Numeric representation of the day of the week / 0 (for Sunday) through 6 (for Saturday) it('w', () => { // Doesnt affect the date when parsing - expect(parseDate('4', 'w')).toEqual(new Date('2021-01-01T06:00:00.000Z')); - }); + expect(parseDate('4', 'w')).toEqual(new Date('2021-01-01T06:00:00.000Z')) + }) // W / Numeric representation of the week / 0 (first week of the year) through 52 (last week of the year) it('W', () => { - expect(parseDate('32', 'W')).toEqual(new Date('2021-08-01T05:00:00.000Z')); - }); + expect(parseDate('32', 'W')).toEqual(new Date('2021-08-01T05:00:00.000Z')) + }) // F / A full textual representation of a month / January through December it('F', () => { - expect(parseDate('November', 'F')).toEqual(new Date('2021-11-01T06:00:00.000Z')); - }); + expect(parseDate('November', 'F')).toEqual(new Date('2021-11-01T06:00:00.000Z')) + }) // m / Numeric representation of a month, with leading zero / 01 through 12 it('m', () => { - expect(parseDate('11', 'm')).toEqual(new Date('2021-11-01T06:00:00.000Z')); - }); + expect(parseDate('11', 'm')).toEqual(new Date('2021-11-01T06:00:00.000Z')) + }) // n / Numeric representation of a month, without leading zeros / 1 through 12 it('n', () => { // Timezone affected because the daylight saving - expect(parseDate('9', 'n')).toEqual(new Date('2021-09-01T05:00:00.000Z')); - }); + expect(parseDate('9', 'n')).toEqual(new Date('2021-09-01T05:00:00.000Z')) + }) // M / A short textual representation of a month / Jan through Dec it('M', () => { - expect(parseDate('Feb', 'M')).toEqual(new Date('2021-02-01T06:00:00.000Z')); - }); + expect(parseDate('Feb', 'M')).toEqual(new Date('2021-02-01T06:00:00.000Z')) + }) // U / The number of seconds since the Unix Epoch / 1413704993 it('U', () => { - expect(parseDate('1635080656', 'U')).toEqual(new Date('2021-10-24T13:04:16.000Z')); - }); + expect(parseDate('1635080656', 'U')).toEqual(new Date('2021-10-24T13:04:16.000Z')) + }) // y / A two digit representation of a year / 99 or 03 it('y', () => { - expect(parseDate('20', 'y')).toEqual(new Date('2020-01-01T06:00:00.000Z')); - }); + expect(parseDate('20', 'y')).toEqual(new Date('2020-01-01T06:00:00.000Z')) + }) // Y / A full numeric representation of a year, 4 digits / 1999 or 2003 it('Y', () => { - expect(parseDate('2019', 'Y')).toEqual(new Date('2019-01-01T06:00:00.000Z')); - }); + expect(parseDate('2019', 'Y')).toEqual(new Date('2019-01-01T06:00:00.000Z')) + }) // Z / ISO Date format / 2017-03-04T01:23:43.000Z it('Z', () => { - expect(parseDate('2020-01-01T06:00:00.000', 'Z')).toEqual(new Date('2020-01-01T12:00:00.000Z')); - }); + expect(parseDate('2020-01-01T06:00:00.000', 'Z')).toEqual( + new Date('2020-01-01T12:00:00.000Z') + ) + }) // H / Hours (24 hours) / 00 to 23 it('H', () => { - expect(parseDate('14', 'H')).toEqual(new Date('2021-01-01T20:00:00.000Z')); - }); + expect(parseDate('14', 'H')).toEqual(new Date('2021-01-01T20:00:00.000Z')) + }) // h / Hours / 1 to 12 it('h', () => { - expect(parseDate('6', 'h')).toEqual(new Date('2021-01-01T12:00:00.000Z')); - }); + expect(parseDate('6', 'h')).toEqual(new Date('2021-01-01T12:00:00.000Z')) + }) // G / Hours, 2 digits with leading zeros / 1 to 12 it('G', () => { - expect(parseDate('10', 'G')).toEqual(new Date('2021-01-01T16:00:00.000Z')); - }); + expect(parseDate('10', 'G')).toEqual(new Date('2021-01-01T16:00:00.000Z')) + }) // i / Minutes / 00 to 59 it('i', () => { - expect(parseDate('35', 'i')).toEqual(new Date('2021-01-01T06:35:00.000Z')); - }); + expect(parseDate('35', 'i')).toEqual(new Date('2021-01-01T06:35:00.000Z')) + }) // S / Seconds, 2 digits / 00 to 59 it('S', () => { - expect(parseDate('42', 'S')).toEqual(new Date('2021-01-01T06:00:42.000Z')); - }); + expect(parseDate('42', 'S')).toEqual(new Date('2021-01-01T06:00:42.000Z')) + }) // s / Seconds / 0, 1 to 59 it('s', () => { - expect(parseDate('18', 's')).toEqual(new Date('2021-01-01T06:00:18.000Z')); - }); + expect(parseDate('18', 's')).toEqual(new Date('2021-01-01T06:00:18.000Z')) + }) // K / AM/PM / AM or PM it('K', () => { - expect(parseDate('PM', 'K')).toEqual(new Date('2021-01-01T18:00:00.000Z')); - }); + expect(parseDate('PM', 'K')).toEqual(new Date('2021-01-01T18:00:00.000Z')) + }) it('K for AM', () => { - expect(parseDate('AM', 'K')).toEqual(new Date('2021-01-01T06:00:00.000Z')); - }); - }); - }); + expect(parseDate('AM', 'K')).toEqual(new Date('2021-01-01T06:00:00.000Z')) + }) + }) + }) describe('Numeric values parsing', () => { it('returns a 0 date if passed `0` as a param', () => { - expect(parseDate(0)).toEqual(new Date(0)); - }); - }); + expect(parseDate(0)).toEqual(new Date(0)) + }) + }) describe('Date instances parsing', () => { it('returns a clone of the date passed as a paramenter', () => { - const date = new Date(2020, 2, 15); + const date = new Date(2020, 2, 15) - expect(parseDate(date)).toEqual(new Date(2020, 2, 15)); - }); + expect(parseDate(date)).toEqual(new Date(2020, 2, 15)) + }) it('returns same date but with the time reset if timeless', () => { - const date = new Date(2020, 2, 15, 12, 30, 45); + const date = new Date(2020, 2, 15, 12, 30, 45) - expect(parseDate(date, defaultFormat, timeless)).toEqual(new Date(2020, 2, 15, 0, 0, 0, 0)); - }); - }); + expect(parseDate(date, defaultFormat, timeless)).toEqual(new Date(2020, 2, 15, 0, 0, 0, 0)) + }) + }) describe('Timestamp instances parsing', () => { it('returns a date when passing the timestamp ', () => { - const date = new Date(2020, 2, 15); + const date = new Date(2020, 2, 15) - expect(parseDate(date.getTime())).toEqual(new Date(2020, 2, 15)); - }); + expect(parseDate(date.getTime())).toEqual(new Date(2020, 2, 15)) + }) it('returns a date when passing the timestamp as number ', () => { - const date = new Date(2020, 2, 15); + const date = new Date(2020, 2, 15) - expect(parseDate(+date)).toEqual(new Date(2020, 2, 15)); - }); + expect(parseDate(+date)).toEqual(new Date(2020, 2, 15)) + }) it('returns a date when passing the timestamp as a regular number ', () => { - expect(parseDate(1584252000000)).toEqual(new Date(2020, 2, 15)); - }); - }); -}); + expect(parseDate(1584252000000)).toEqual(new Date(2020, 2, 15)) + }) + }) +}) diff --git a/src/__tests__/dates/visibleDaysInMonthView.test.ts b/src/__tests__/dates/visibleDaysInMonthView.test.ts index a453c9c..5e321e7 100644 --- a/src/__tests__/dates/visibleDaysInMonthView.test.ts +++ b/src/__tests__/dates/visibleDaysInMonthView.test.ts @@ -1,82 +1,82 @@ -import { WeekDay } from '../../types/Dates'; -import visibleDaysInMonthView from '../../dates/visibleDaysInMonthView'; +import { WeekDay } from '../../types/Dates' +import visibleDaysInMonthView from '../../dates/visibleDaysInMonthView' describe('visibleDaysInMonthView', () => { it('returns 42 items by adding the days on the next month and the prev month', () => { // 2021-10-23 - const date = new Date(2021, 9, 23); + const date = new Date(2021, 9, 23) - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(42); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 8, 26)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 8, 30)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[5]).toEqual(new Date(2021, 9, 1)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[35]).toEqual(new Date(2021, 9, 31)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[36]).toEqual(new Date(2021, 10, 1)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[41]).toEqual(new Date(2021, 10, 6)); - }); + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(42) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 8, 26)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 8, 30)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[5]).toEqual(new Date(2021, 9, 1)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[35]).toEqual(new Date(2021, 9, 31)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[36]).toEqual(new Date(2021, 10, 1)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[41]).toEqual(new Date(2021, 10, 6)) + }) it('uses monday as default start of week', () => { // 2021-10-23 - const date = new Date(2021, 9, 23); + const date = new Date(2021, 9, 23) - expect(visibleDaysInMonthView(date).length).toBe(42); - expect(visibleDaysInMonthView(date)[0]).toEqual(new Date(2021, 8, 26)); - expect(visibleDaysInMonthView(date)[41]).toEqual(new Date(2021, 10, 6)); - }); + expect(visibleDaysInMonthView(date).length).toBe(42) + expect(visibleDaysInMonthView(date)[0]).toEqual(new Date(2021, 8, 26)) + expect(visibleDaysInMonthView(date)[41]).toEqual(new Date(2021, 10, 6)) + }) it('returns 35 items by adding the days on the next month and the prev month using a custom start of week', () => { // 2021-10-23 - const date = new Date(2021, 9, 23); + const date = new Date(2021, 9, 23) - expect(visibleDaysInMonthView(date, WeekDay.Tuesday).length).toBe(35); - expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[0]).toEqual(new Date(2021, 8, 28)); - expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[6]).toEqual(new Date(2021, 9, 4)); - expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[34]).toEqual(new Date(2021, 10, 1)); - }); + expect(visibleDaysInMonthView(date, WeekDay.Tuesday).length).toBe(35) + expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[0]).toEqual(new Date(2021, 8, 28)) + expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[6]).toEqual(new Date(2021, 9, 4)) + expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[34]).toEqual(new Date(2021, 10, 1)) + }) it('returns 42 items by adding the days on the next month and the prev month using a custom start of week', () => { // 2021-10-23 - const date = new Date(2021, 9, 23); + const date = new Date(2021, 9, 23) - expect(visibleDaysInMonthView(date, WeekDay.Saturday).length).toBe(42); - expect(visibleDaysInMonthView(date, WeekDay.Saturday)[0]).toEqual(new Date(2021, 8, 25)); - expect(visibleDaysInMonthView(date, WeekDay.Saturday)[41]).toEqual(new Date(2021, 10, 5)); - }); + expect(visibleDaysInMonthView(date, WeekDay.Saturday).length).toBe(42) + expect(visibleDaysInMonthView(date, WeekDay.Saturday)[0]).toEqual(new Date(2021, 8, 25)) + expect(visibleDaysInMonthView(date, WeekDay.Saturday)[41]).toEqual(new Date(2021, 10, 5)) + }) it('returns 35 items when month ends on last day of week', () => { // 2021-07-23 - const date = new Date(2021, 6, 23); + const date = new Date(2021, 6, 23) - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 5, 27)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 6, 1)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2021, 6, 31)); - }); + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 5, 27)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 6, 1)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2021, 6, 31)) + }) it('returns 35 items when month start on first day of week', () => { // 2020-11-23 - const date = new Date(2020, 10, 23); + const date = new Date(2020, 10, 23) - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2020, 10, 1)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[29]).toEqual(new Date(2020, 10, 30)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2020, 11, 5)); - }); + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2020, 10, 1)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[29]).toEqual(new Date(2020, 10, 30)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2020, 11, 5)) + }) it('get four rows for a month with 28 days that start on sunday', () => { // 2015-02-15 - const date = new Date(2015, 1, 15); + const date = new Date(2015, 1, 15) - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(28); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2015, 1, 1)); - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[27]).toEqual(new Date(2015, 1, 28)); - }); + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(28) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2015, 1, 1)) + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[27]).toEqual(new Date(2015, 1, 28)) + }) it('get four rows for a month with 28 days and first day matches a custom day of week', () => { - const date = new Date(2021, 1, 15); + const date = new Date(2021, 1, 15) - expect(visibleDaysInMonthView(date, WeekDay.Monday).length).toBe(28); - expect(visibleDaysInMonthView(date, WeekDay.Monday)[0]).toEqual(new Date(2021, 1, 1)); - expect(visibleDaysInMonthView(date, WeekDay.Monday)[27]).toEqual(new Date(2021, 1, 28)); - }); -}); + expect(visibleDaysInMonthView(date, WeekDay.Monday).length).toBe(28) + expect(visibleDaysInMonthView(date, WeekDay.Monday)[0]).toEqual(new Date(2021, 1, 1)) + expect(visibleDaysInMonthView(date, WeekDay.Monday)[27]).toEqual(new Date(2021, 1, 28)) + }) +}) diff --git a/src/__tests__/debounce.test.ts b/src/__tests__/debounce.test.ts index ce77ffa..135cb25 100644 --- a/src/__tests__/debounce.test.ts +++ b/src/__tests__/debounce.test.ts @@ -1,81 +1,81 @@ -import debounce from '../helpers/debounce'; +import debounce from '../helpers/debounce' describe('debounce', () => { it('runs the function after the default time', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - jest.useFakeTimers(); + jest.useFakeTimers() - debounce(mockFn)(); + debounce(mockFn)() - expect(mockFn).not.toHaveBeenCalled(); + expect(mockFn).not.toHaveBeenCalled() - jest.advanceTimersByTime(199); + jest.advanceTimersByTime(199) - expect(mockFn).not.toHaveBeenCalled(); + expect(mockFn).not.toHaveBeenCalled() - jest.advanceTimersByTime(1); + jest.advanceTimersByTime(1) - expect(mockFn).toHaveBeenCalled(); - }); + expect(mockFn).toHaveBeenCalled() + }) it('reset the time if function called again', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - jest.useFakeTimers(); + jest.useFakeTimers() - const func = debounce(mockFn, 200); + const func = debounce(mockFn, 200) - func(); + func() - expect(mockFn).not.toHaveBeenCalled(); + expect(mockFn).not.toHaveBeenCalled() - jest.advanceTimersByTime(199); + jest.advanceTimersByTime(199) - func(); + func() - jest.advanceTimersByTime(199); + jest.advanceTimersByTime(199) - expect(mockFn).not.toHaveBeenCalled(); + expect(mockFn).not.toHaveBeenCalled() - jest.advanceTimersByTime(1); + jest.advanceTimersByTime(1) - expect(mockFn).toHaveBeenCalled(); - }); + expect(mockFn).toHaveBeenCalled() + }) it('can cancel the call', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - jest.useFakeTimers(); + jest.useFakeTimers() - const func = debounce(mockFn, 200); + const func = debounce(mockFn, 200) - func(); + func() - func.cancel(); + func.cancel() - jest.advanceTimersByTime(300); + jest.advanceTimersByTime(300) - expect(mockFn).not.toHaveBeenCalled(); - }); + expect(mockFn).not.toHaveBeenCalled() + }) it('handle the function params ', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - jest.useFakeTimers(); + jest.useFakeTimers() - debounce(mockFn, 100)('test', 1); + debounce(mockFn, 100)('test', 1) - jest.advanceTimersByTime(100); + jest.advanceTimersByTime(100) - expect(mockFn).toHaveBeenLastCalledWith(['test', 1]); - }); + expect(mockFn).toHaveBeenLastCalledWith(['test', 1]) + }) it('runs the function inmediatly if wait is falsy value', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - debounce(mockFn, 0)(); + debounce(mockFn, 0)() - expect(mockFn).toHaveBeenCalled(); - }); -}); + expect(mockFn).toHaveBeenCalled() + }) +}) diff --git a/src/__tests__/elementIsTargetOrTargetChild.test.ts b/src/__tests__/elementIsTargetOrTargetChild.test.ts index 5037cd8..4b1b22b 100644 --- a/src/__tests__/elementIsTargetOrTargetChild.test.ts +++ b/src/__tests__/elementIsTargetOrTargetChild.test.ts @@ -1,45 +1,45 @@ -import elementIsTargetOrTargetChild from '../helpers/elementIsTargetOrTargetChild'; +import elementIsTargetOrTargetChild from '../helpers/elementIsTargetOrTargetChild' describe('elementIsTargetOrTargetChild', () => { it('returns `true` if the element is the same ', () => { - const div = document.createElement('div'); + const div = document.createElement('div') - const relatedTarget: EventTarget = div; + const relatedTarget: EventTarget = div - expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true); - }); + expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true) + }) it('returns `true` if the element is a child of the wrapper ', () => { - const div = document.createElement('div'); - const button = document.createElement('button'); - const span = document.createElement('span'); + const div = document.createElement('div') + const button = document.createElement('button') + const span = document.createElement('span') - div.appendChild(button); - button.appendChild(span); + div.appendChild(button) + button.appendChild(span) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const relatedTarget: EventTarget = div.querySelector('span')!; + const relatedTarget: EventTarget = div.querySelector('span')! - expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true); - }); + expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true) + }) it('returns `false` if the element is not a child of the wrapper ', () => { - const div = document.createElement('div'); - const button = document.createElement('button'); - const span = document.createElement('span'); + const div = document.createElement('div') + const button = document.createElement('button') + const span = document.createElement('span') - div.appendChild(button); - div.appendChild(span); + div.appendChild(button) + div.appendChild(span) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const relatedTarget: EventTarget = div.querySelector('span')!; + const relatedTarget: EventTarget = div.querySelector('span')! - expect(elementIsTargetOrTargetChild(relatedTarget, button)).toBe(false); - }); + expect(elementIsTargetOrTargetChild(relatedTarget, button)).toBe(false) + }) it('returns `false` if the element is null', () => { - const div = document.createElement('div'); + const div = document.createElement('div') - expect(elementIsTargetOrTargetChild(null, div)).toBe(false); - }); -}); + expect(elementIsTargetOrTargetChild(null, div)).toBe(false) + }) +}) diff --git a/src/__tests__/filterOptions.test.ts b/src/__tests__/filterOptions.test.ts index 22d87d2..07e9fa2 100644 --- a/src/__tests__/filterOptions.test.ts +++ b/src/__tests__/filterOptions.test.ts @@ -1,5 +1,5 @@ -import { filterOptions } from '../index'; -import { NormalizedOptions } from '../types'; +import { filterOptions } from '../index' +import { NormalizedOptions } from '../types' describe('filterOptions', () => { const options: NormalizedOptions = [ @@ -21,15 +21,15 @@ describe('filterOptions', () => { }, { value: 'C', text: 'C' }, { value: 'redy', text: 'Reddy' }, - ]; + ] it('returns the same options is no query', () => { - const filteredOptions = filterOptions(options, ''); - expect(filteredOptions).toEqual(options); - }); + const filteredOptions = filterOptions(options, '') + expect(filteredOptions).toEqual(options) + }) it('filters deep', () => { - const filteredOptions = filterOptions(options, 'red'); + const filteredOptions = filterOptions(options, 'red') expect(filteredOptions).toEqual([ { value: 'B', @@ -38,13 +38,11 @@ describe('filterOptions', () => { { value: 1, text: 'Option 1', - children: [ - { value: 'red', text: 'Red' }, - ], + children: [{ value: 'red', text: 'Red' }], }, ], }, { value: 'redy', text: 'Reddy' }, - ]); - }); -}); + ]) + }) +}) diff --git a/src/__tests__/flattenOptions.test.ts b/src/__tests__/flattenOptions.test.ts index 4e12985..d4bad3d 100644 --- a/src/__tests__/flattenOptions.test.ts +++ b/src/__tests__/flattenOptions.test.ts @@ -1,11 +1,11 @@ -import { flattenOptions } from '../index'; -import normalizeOptions from '../normalizeOptions'; +import { flattenOptions } from '../index' +import normalizeOptions from '../normalizeOptions' describe('flattenOptions', () => { it('returns the same array if no deep values', () => { - const options = normalizeOptions([1, 2, 4, 'A', 'B']); - expect(flattenOptions(options)).toEqual(options); - }); + const options = normalizeOptions([1, 2, 4, 'A', 'B']) + expect(flattenOptions(options)).toEqual(options) + }) it('returns the a flattened array of options', () => { const options = normalizeOptions([ @@ -19,16 +19,16 @@ describe('flattenOptions', () => { ], }, { value: 'C', text: 'C' }, - ]); + ]) const expcetedOptions = normalizeOptions([ { value: 'A', text: 'A' }, { value: 1, text: 'Option 1' }, { value: 2, text: 'Option 2' }, { value: 'C', text: 'C' }, - ]); + ]) - expect(flattenOptions(options)).toEqual(expcetedOptions); - }); + expect(flattenOptions(options)).toEqual(expcetedOptions) + }) it('flatten deep options', () => { const options = normalizeOptions([ @@ -49,15 +49,15 @@ describe('flattenOptions', () => { ], }, { value: 'C', text: 'C' }, - ]); + ]) const expcetedOptions = normalizeOptions([ { value: 'A', text: 'A' }, { value: 'red', text: 'Red' }, { value: 'blue', text: 'Blue' }, { value: 2, text: 'Option 2' }, { value: 'C', text: 'C' }, - ]); + ]) - expect(flattenOptions(options)).toEqual(expcetedOptions); - }); -}); + expect(flattenOptions(options)).toEqual(expcetedOptions) + }) +}) diff --git a/src/__tests__/get.test.ts b/src/__tests__/get.test.ts index 62a2c99..9ff6178 100644 --- a/src/__tests__/get.test.ts +++ b/src/__tests__/get.test.ts @@ -1,38 +1,38 @@ -import get from '../helpers/get'; +import get from '../helpers/get' describe('get', () => { it('get the value of an object', () => { const obj = { name: 'Alfonso', - }; - expect(get(obj, 'name')).toBe('Alfonso'); - }); + } + expect(get(obj, 'name')).toBe('Alfonso') + }) it('return the default value if the attribute is not found', () => { const obj = { name: 'Alfonso', - }; + } - const defaultValue = 'default'; - expect(get(obj, 'age', defaultValue)).toBe(defaultValue); - }); + const defaultValue = 'default' + expect(get(obj, 'age', defaultValue)).toBe(defaultValue) + }) it('return undefined if the attribute is not found', () => { const obj = { name: 'Alfonso', - }; + } - expect(get(obj, 'user')).toBeUndefined(); - }); + expect(get(obj, 'user')).toBeUndefined() + }) it('return null if the attribute is null', () => { const obj = { name: 'Alfonso', id: null, - }; + } - expect(get(obj, 'id')).toBeNull(); - }); + expect(get(obj, 'id')).toBeNull() + }) it('return null if the attribute is null deeply within an array', () => { const obj = { @@ -45,10 +45,10 @@ describe('get', () => { id: null, }, ], - }; + } - expect(get(obj, 'roles.1.id')).toBeNull(); - }); + expect(get(obj, 'roles.1.id')).toBeNull() + }) it('return null if the attribute is null deeply', () => { const obj = { @@ -56,28 +56,28 @@ describe('get', () => { role: { id: null, }, - }; + } - expect(get(obj, 'role.id')).toBeNull(); - }); + expect(get(obj, 'role.id')).toBeNull() + }) it('return undefined if the attribute is not found deeply', () => { const obj = { name: 'Alfonso', - }; + } - expect(get(obj, 'name.initials')).toBeUndefined(); - }); + expect(get(obj, 'name.initials')).toBeUndefined() + }) it('return the default value if the attribute is not found deeply', () => { const obj = { name: 'Alfonso', - }; + } - const defaultValue = { default: 'value ' }; + const defaultValue = { default: 'value ' } - expect(get(obj, 'name.initials', defaultValue)).toEqual(defaultValue); - }); + expect(get(obj, 'name.initials', defaultValue)).toEqual(defaultValue) + }) it('get a deep value of an object', () => { const obj = { @@ -89,16 +89,16 @@ describe('get', () => { edit: true, }, }, - }; + } - expect(get(obj, 'role.permissions.edit')).toBe(true); - }); + expect(get(obj, 'role.permissions.edit')).toBe(true) + }) it('get the value of an array by index', () => { - const arr = ['hello', 'world']; + const arr = ['hello', 'world'] - expect(get(arr, '1')).toBe('world'); - }); + expect(get(arr, '1')).toBe('world') + }) it('get the value of an array deeply', () => { const arr = [ @@ -107,10 +107,10 @@ describe('get', () => { ['hello', 'world'], ['hola', 'mundo'], ], - ]; + ] - expect(get(arr, '1.1.1')).toBe('mundo'); - }); + expect(get(arr, '1.1.1')).toBe('mundo') + }) it('get the value of an array inside an object', () => { const obj = { @@ -121,10 +121,10 @@ describe('get', () => { ['hola', 'mundo'], ], ], - }; + } - expect(get(obj, 'arr.1.1.1')).toBe('mundo'); - }); + expect(get(obj, 'arr.1.1.1')).toBe('mundo') + }) it('get the value of an object inside an array', () => { const arr = [ @@ -138,8 +138,8 @@ describe('get', () => { }, ], ], - ]; + ] - expect(get(arr, '1.1.1.name')).toBe('Alfonso'); - }); -}); + expect(get(arr, '1.1.1.name')).toBe('Alfonso') + }) +}) diff --git a/src/__tests__/getFocusableElements.test.ts b/src/__tests__/getFocusableElements.test.ts index 1b1e96c..43e7cbd 100644 --- a/src/__tests__/getFocusableElements.test.ts +++ b/src/__tests__/getFocusableElements.test.ts @@ -1,136 +1,129 @@ -import elementIsTargetOrTargetChild from '../helpers/getFocusableElements'; +import elementIsTargetOrTargetChild from '../helpers/getFocusableElements' describe('elementIsTargetOrTargetChild', () => { it('returns a link ', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('a'); + const focusable = document.createElement('a') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns a button', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('button'); + const focusable = document.createElement('button') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns a input', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('input'); + const focusable = document.createElement('input') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns a textarea', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('textarea'); + const focusable = document.createElement('textarea') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns a select', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('select'); + const focusable = document.createElement('select') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns a details', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('details'); + const focusable = document.createElement('details') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns a contenteditable div', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('div'); - focusable.setAttribute('contenteditable', 'true'); + const focusable = document.createElement('div') + focusable.setAttribute('contenteditable', 'true') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns an element with a tab index of 0', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('div'); - focusable.setAttribute('tabindex', '0'); + const focusable = document.createElement('div') + focusable.setAttribute('tabindex', '0') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('returns an element with a positive tab index ', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('div'); - focusable.setAttribute('tabindex', '1'); + const focusable = document.createElement('div') + focusable.setAttribute('tabindex', '1') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) + }) it('doesnt returns an element with a -1 tab index ', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const focusable = document.createElement('div'); - focusable.setAttribute('tabindex', '-1'); + const focusable = document.createElement('div') + focusable.setAttribute('tabindex', '-1') - el.appendChild(focusable); + el.appendChild(focusable) - expect(elementIsTargetOrTargetChild(el)).toEqual([]); - }); + expect(elementIsTargetOrTargetChild(el)).toEqual([]) + }) it('doesnt return any element that is disabled ', () => { - const el = document.createElement('div'); + const el = document.createElement('div') - const els = [ - 'a', - 'button', - 'input', - 'textarea', - 'select', - 'details', - ]; + const els = ['a', 'button', 'input', 'textarea', 'select', 'details'] els.forEach((tagName) => { - const focusable = document.createElement(tagName); - focusable.setAttribute('disabled', 'disabled'); - el.appendChild(focusable); - }); - - const tabIndex = document.createElement('div'); - tabIndex.setAttribute('tabindex', '0'); - tabIndex.setAttribute('disabled', 'disabled'); - el.appendChild(tabIndex); - - const contentEditable = document.createElement('div'); - contentEditable.setAttribute('contenteditable', 'true'); - contentEditable.setAttribute('tabindex', '0'); - contentEditable.setAttribute('disabled', 'disabled'); - el.appendChild(contentEditable); - - expect(elementIsTargetOrTargetChild(el).length).toBe(0); - }); -}); + const focusable = document.createElement(tagName) + focusable.setAttribute('disabled', 'disabled') + el.appendChild(focusable) + }) + + const tabIndex = document.createElement('div') + tabIndex.setAttribute('tabindex', '0') + tabIndex.setAttribute('disabled', 'disabled') + el.appendChild(tabIndex) + + const contentEditable = document.createElement('div') + contentEditable.setAttribute('contenteditable', 'true') + contentEditable.setAttribute('tabindex', '0') + contentEditable.setAttribute('disabled', 'disabled') + el.appendChild(contentEditable) + + expect(elementIsTargetOrTargetChild(el).length).toBe(0) + }) +}) diff --git a/src/__tests__/hasProperty.test.ts b/src/__tests__/hasProperty.test.ts index 5bd3ea7..0dcad29 100644 --- a/src/__tests__/hasProperty.test.ts +++ b/src/__tests__/hasProperty.test.ts @@ -1,43 +1,43 @@ -import hasProperty from '../helpers/hasProperty'; +import hasProperty from '../helpers/hasProperty' describe('hasProperty', () => { it('returns `true` if the object has the property ', () => { const obj = { foo: 'bar', - }; + } - expect(hasProperty(obj, 'foo')).toBe(true); - }); + expect(hasProperty(obj, 'foo')).toBe(true) + }) it('returns `true` if the object has the property even when it is null ', () => { const obj = { foo: null, - }; + } - expect(hasProperty(obj, 'foo')).toBe(true); - }); + expect(hasProperty(obj, 'foo')).toBe(true) + }) it('returns `true` if the object has the property even when it is `undefined` ', () => { const obj = { foo: undefined, - }; + } - expect(hasProperty(obj, 'foo')).toBe(true); - }); + expect(hasProperty(obj, 'foo')).toBe(true) + }) it('returns `false` if the object doesnt have the property ', () => { const obj = { bar: 'foo', - }; + } - expect(hasProperty(obj, 'foo')).toBe(false); - }); + expect(hasProperty(obj, 'foo')).toBe(false) + }) it('returns `false` if undefined object ', () => { - expect(hasProperty(undefined, 'foo')).toBe(false); - }); + expect(hasProperty(undefined, 'foo')).toBe(false) + }) it('returns `false` if passes `null`', () => { - expect(hasProperty(null, 'foo')).toBe(false); - }); -}); + expect(hasProperty(null, 'foo')).toBe(false) + }) +}) diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 0100f81..4429563 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -1,43 +1,43 @@ -import * as helpers from '../helpers/index'; -import * as dateHelpers from '../dates/index'; +import * as helpers from '../helpers/index' +import * as dateHelpers from '../dates/index' it('exports all the helpers', () => { - expect(Object.keys(helpers).length).toBe(17); + expect(Object.keys(helpers).length).toBe(17) - expect(typeof helpers.get).toBe('function'); - expect(typeof helpers.pick).toBe('function'); - expect(typeof helpers.clone).toBe('function'); - expect(typeof helpers.isPrimitive).toBe('function'); - expect(typeof helpers.isEqual).toBe('function'); - expect(typeof helpers.hasProperty).toBe('function'); - expect(typeof helpers.debounce).toBe('function'); - expect(typeof helpers.throttle).toBe('function'); - expect(typeof helpers.addToArray).toBe('function'); - expect(typeof helpers.substractFromArray).toBe('function'); - expect(typeof helpers.elementIsTargetOrTargetChild).toBe('function'); - expect(typeof helpers.getFocusableElements).toBe('function'); - expect(typeof helpers.isTouchOnlyDevice).toBe('function'); - expect(typeof helpers.normalizeMeasure).toBe('function'); - expect(typeof helpers.normalizedOptionIsDisabled).toBe('function'); - expect(typeof helpers.promisify).toBe('function'); - expect(typeof helpers.promisifyFunctionResult).toBe('function'); -}); + expect(typeof helpers.get).toBe('function') + expect(typeof helpers.pick).toBe('function') + expect(typeof helpers.clone).toBe('function') + expect(typeof helpers.isPrimitive).toBe('function') + expect(typeof helpers.isEqual).toBe('function') + expect(typeof helpers.hasProperty).toBe('function') + expect(typeof helpers.debounce).toBe('function') + expect(typeof helpers.throttle).toBe('function') + expect(typeof helpers.addToArray).toBe('function') + expect(typeof helpers.substractFromArray).toBe('function') + expect(typeof helpers.elementIsTargetOrTargetChild).toBe('function') + expect(typeof helpers.getFocusableElements).toBe('function') + expect(typeof helpers.isTouchOnlyDevice).toBe('function') + expect(typeof helpers.normalizeMeasure).toBe('function') + expect(typeof helpers.normalizedOptionIsDisabled).toBe('function') + expect(typeof helpers.promisify).toBe('function') + expect(typeof helpers.promisifyFunctionResult).toBe('function') +}) it('exports all the date-related helpers', () => { - expect(Object.keys(dateHelpers).length).toBe(14); + expect(Object.keys(dateHelpers).length).toBe(14) - expect(typeof dateHelpers.dateEnglishLocale).toBe('object'); - expect(typeof dateHelpers.visibleDaysInMonthView).toBe('function'); - expect(typeof dateHelpers.isSameDay).toBe('function'); - expect(typeof dateHelpers.isSameMonth).toBe('function'); - expect(typeof dateHelpers.isToday).toBe('function'); - expect(typeof dateHelpers.addDays).toBe('function'); - expect(typeof dateHelpers.addMonths).toBe('function'); - expect(typeof dateHelpers.addYears).toBe('function'); - expect(typeof dateHelpers.dateIsPartOfTheRange).toBe('function'); - expect(typeof dateHelpers.dayIsPartOfTheConditions).toBe('function'); - expect(typeof dateHelpers.parseDate).toBe('function'); - expect(typeof dateHelpers.formatDate).toBe('function'); - expect(typeof dateHelpers.buildDateParser).toBe('function'); - expect(typeof dateHelpers.buildDateFormatter).toBe('function'); -}); + expect(typeof dateHelpers.dateEnglishLocale).toBe('object') + expect(typeof dateHelpers.visibleDaysInMonthView).toBe('function') + expect(typeof dateHelpers.isSameDay).toBe('function') + expect(typeof dateHelpers.isSameMonth).toBe('function') + expect(typeof dateHelpers.isToday).toBe('function') + expect(typeof dateHelpers.addDays).toBe('function') + expect(typeof dateHelpers.addMonths).toBe('function') + expect(typeof dateHelpers.addYears).toBe('function') + expect(typeof dateHelpers.dateIsPartOfTheRange).toBe('function') + expect(typeof dateHelpers.dayIsPartOfTheConditions).toBe('function') + expect(typeof dateHelpers.parseDate).toBe('function') + expect(typeof dateHelpers.formatDate).toBe('function') + expect(typeof dateHelpers.buildDateParser).toBe('function') + expect(typeof dateHelpers.buildDateFormatter).toBe('function') +}) diff --git a/src/__tests__/isEqual.test.ts b/src/__tests__/isEqual.test.ts index 856e7fc..5f2ccf2 100644 --- a/src/__tests__/isEqual.test.ts +++ b/src/__tests__/isEqual.test.ts @@ -1,65 +1,69 @@ -import isEqual from '../helpers/isEqual'; +import isEqual from '../helpers/isEqual' describe('isEqual', () => { it('considers that a number is not equal to a string', () => { - expect(isEqual('12', 12)).toBe(false); - }); + expect(isEqual('12', 12)).toBe(false) + }) it('considers that a number is equal to the same number', () => { - expect(isEqual(12, 12)).toBe(true); - }); + expect(isEqual(12, 12)).toBe(true) + }) it('considers that a numeric string is equal to the same numeric string', () => { - expect(isEqual('12', '12')).toBe(true); - }); + expect(isEqual('12', '12')).toBe(true) + }) it('considers that a regular string is equal to the same regular string', () => { - expect(isEqual('Hello World! 🤨', 'Hello World! 🤨')).toBe(true); - }); + expect(isEqual('Hello World! 🤨', 'Hello World! 🤨')).toBe(true) + }) it('considers that an empty array is equal to another empty array', () => { - expect(isEqual([], [])).toBe(true); - }); + expect(isEqual([], [])).toBe(true) + }) it('considers that an array with same values to be equal', () => { - expect(isEqual([1, '12', 'string', true, undefined], [1, '12', 'string', true, undefined])).toBe(true); - }); + expect( + isEqual([1, '12', 'string', true, undefined], [1, '12', 'string', true, undefined]) + ).toBe(true) + }) it('considers that an array with same values in different order to no be equal', () => { - expect(isEqual([1, '12', 'string', true, undefined], ['12', 1, 'string', true, undefined])).toBe(false); - }); + expect( + isEqual([1, '12', 'string', true, undefined], ['12', 1, 'string', true, undefined]) + ).toBe(false) + }) it('considers that `undefined` is equal to `undefined`', () => { - expect(isEqual(undefined, undefined)).toBe(true); - }); + expect(isEqual(undefined, undefined)).toBe(true) + }) it('considers that `null` is equal to `null`', () => { - expect(isEqual(null, null)).toBe(true); - }); + expect(isEqual(null, null)).toBe(true) + }) it('considers that `NaN` is equal to `NaN`', () => { - expect(isEqual(NaN, NaN)).toBe(true); - }); + expect(isEqual(NaN, NaN)).toBe(true) + }) it('considers that `undefined` is different to `null`', () => { - expect(isEqual(undefined, null)).toBe(false); - }); + expect(isEqual(undefined, null)).toBe(false) + }) it('considers that `null` is different to an empty string', () => { - expect(isEqual('', null)).toBe(false); - }); + expect(isEqual('', null)).toBe(false) + }) it('considers that `true` is equal to `true`', () => { - expect(isEqual(true, true)).toBe(true); - }); + expect(isEqual(true, true)).toBe(true) + }) it('considers that `false` is equal to `false`', () => { - expect(isEqual(false, false)).toBe(true); - }); + expect(isEqual(false, false)).toBe(true) + }) it('considers that `false` is different to `false`', () => { - expect(isEqual(true, false)).toBe(false); - }); + expect(isEqual(true, false)).toBe(false) + }) it('considers that an object with same properties is equal', () => { const a = { @@ -68,7 +72,7 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - }; + } const b = { a: 1, @@ -76,10 +80,10 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - }; + } - expect(isEqual(a, b)).toBe(true); - }); + expect(isEqual(a, b)).toBe(true) + }) it('considers that an object with a different property is not equal', () => { const a = { @@ -88,7 +92,7 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - }; + } const b = { a: '1', @@ -96,57 +100,81 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - }; + } - expect(isEqual(a, b)).toBe(false); - }); + expect(isEqual(a, b)).toBe(false) + }) it('makes a deep comparison', () => { - const a = [undefined, { - a: 1, - test: 2, - something: { + const a = [ + undefined, + { a: 1, - hola: 'Mundo', - 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + test: 2, + something: { + a: 1, + hola: 'Mundo', + 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + }, }, - }, null, [], { a: 1, b: 2, c: 3 }]; - - const b = [undefined, { - a: 1, - test: 2, - something: { + null, + [], + { a: 1, b: 2, c: 3 }, + ] + + const b = [ + undefined, + { a: 1, - hola: 'Mundo', - 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + test: 2, + something: { + a: 1, + hola: 'Mundo', + 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + }, }, - }, null, [], { a: 1, b: 2, c: 3 }]; + null, + [], + { a: 1, b: 2, c: 3 }, + ] - expect(isEqual(a, b)).toBe(true); - }); + expect(isEqual(a, b)).toBe(true) + }) it('makes a deep comparison for something that is not equal', () => { - const a = [undefined, { - a: 1, - test: 2, - something: { + const a = [ + undefined, + { a: 1, - hola: 'Mundo', - 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + test: 2, + something: { + a: 1, + hola: 'Mundo', + 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: '1' } }, ['a', 'b', 'C']], + }, }, - }, null, [], { a: 1, b: 2, c: 3 }]; - - const b = [undefined, { - a: 1, - test: 2, - something: { + null, + [], + { a: 1, b: 2, c: 3 }, + ] + + const b = [ + undefined, + { a: 1, - hola: 'Mundo', - // The 1 in foo is different - 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: 1 } }, ['a', 'b', 'C']], + test: 2, + something: { + a: 1, + hola: 'Mundo', + // The 1 in foo is different + 'an-array': [1, undefined, { hello: 'wolrd', test: { foo: 1 } }, ['a', 'b', 'C']], + }, }, - }, null, [], { a: 1, b: 2, c: 3 }]; - - expect(isEqual(a, b)).toBe(false); - }); -}); + null, + [], + { a: 1, b: 2, c: 3 }, + ] + + expect(isEqual(a, b)).toBe(false) + }) +}) diff --git a/src/__tests__/isPrimitive.test.ts b/src/__tests__/isPrimitive.test.ts index 0c7d1fa..6735d18 100644 --- a/src/__tests__/isPrimitive.test.ts +++ b/src/__tests__/isPrimitive.test.ts @@ -1,38 +1,38 @@ -import isPrimitive from '../helpers/isPrimitive'; +import isPrimitive from '../helpers/isPrimitive' describe('isPrimitive', () => { it('detects null as primitive', () => { - expect(isPrimitive(null)).toBe(true); - }); + expect(isPrimitive(null)).toBe(true) + }) it('detects number as primitive', () => { - expect(isPrimitive(1)).toBe(true); - }); + expect(isPrimitive(1)).toBe(true) + }) it('detects string as primitive', () => { - expect(isPrimitive('a string')).toBe(true); - }); + expect(isPrimitive('a string')).toBe(true) + }) it('detects boolean as primitive', () => { - expect(isPrimitive(true)).toBe(true); - }); + expect(isPrimitive(true)).toBe(true) + }) it('detects undefined as primitive', () => { - expect(isPrimitive(undefined)).toBe(true); - }); + expect(isPrimitive(undefined)).toBe(true) + }) it('detects symbol as primitive', () => { - expect(isPrimitive(Symbol('foo'))).toBe(true); - }); + expect(isPrimitive(Symbol('foo'))).toBe(true) + }) it('detects an object as not primitive', () => { - expect(isPrimitive({})).toBe(false); - }); + expect(isPrimitive({})).toBe(false) + }) it('detects a function as not primitive', () => { - expect(isPrimitive(() => {})).toBe(false); - }); + expect(isPrimitive(() => {})).toBe(false) + }) it('detects an array as not primitive', () => { - expect(isPrimitive([])).toBe(false); - }); -}); + expect(isPrimitive([])).toBe(false) + }) +}) diff --git a/src/__tests__/isTouchOnlyDevice.test.ts b/src/__tests__/isTouchOnlyDevice.test.ts index 0fd1a14..7c10072 100644 --- a/src/__tests__/isTouchOnlyDevice.test.ts +++ b/src/__tests__/isTouchOnlyDevice.test.ts @@ -1,4 +1,4 @@ -import isTouchOnlyDevice from '../helpers/isTouchOnlyDevice'; +import isTouchOnlyDevice from '../helpers/isTouchOnlyDevice' describe('isTouchOnlyDevice.', () => { it('returns `true` if matchMedia return matches', () => { @@ -7,9 +7,9 @@ describe('isTouchOnlyDevice.', () => { matchMedia: () => ({ matches: true, }), - }; - expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(true); - }); + } + expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(true) + }) it('returns `true` if matchMedia doesnt return matches', () => { const windowMock = { @@ -17,20 +17,20 @@ describe('isTouchOnlyDevice.', () => { matchMedia: () => ({ matches: false, }), - }; - expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(false); - }); + } + expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(false) + }) it('uses the global window and navigator by default', () => { - expect(isTouchOnlyDevice()).toBe(false); - }); + expect(isTouchOnlyDevice()).toBe(false) + }) it('returns `false` if window is not defined', () => { - const windowSpy = jest.spyOn(window, 'window', 'get'); - windowSpy.mockImplementation(() => undefined as unknown as Window & typeof globalThis); + const windowSpy = jest.spyOn(window, 'window', 'get') + windowSpy.mockImplementation(() => undefined as unknown as Window & typeof globalThis) - expect(isTouchOnlyDevice()).toBe(false); + expect(isTouchOnlyDevice()).toBe(false) - windowSpy.mockRestore(); - }); -}); + windowSpy.mockRestore() + }) +}) diff --git a/src/__tests__/mergeClasses.test.ts b/src/__tests__/mergeClasses.test.ts index 7dcd3a6..c4dff0b 100644 --- a/src/__tests__/mergeClasses.test.ts +++ b/src/__tests__/mergeClasses.test.ts @@ -1,30 +1,37 @@ -import { mergeClasses } from '../index'; +import { mergeClasses } from '../index' describe('merge classes function', () => { it('merges two string classes', () => { - expect(mergeClasses('hello', 'world')).toBe('hello world'); - }); + expect(mergeClasses('hello', 'world')).toBe('hello world') + }) it('accepts undefined values', () => { - expect(mergeClasses('hello', undefined)).toBe('hello'); - }); + expect(mergeClasses('hello', undefined)).toBe('hello') + }) it('merges two array classes', () => { - expect(mergeClasses(['hello'], ['world'])).toBe('hello world'); - }); + expect(mergeClasses(['hello'], ['world'])).toBe('hello world') + }) it('allows functions that can manipulate the classes interactively', () => { - expect(mergeClasses(['hello'], ({ clear, add }) => { - clear(); - add('no'); - }, ['world'], ({ remove }) => { - remove('world'); - })).toBe('no'); - }); + expect( + mergeClasses( + ['hello'], + ({ clear, add }) => { + clear() + add('no') + }, + ['world'], + ({ remove }) => { + remove('world') + } + ) + ).toBe('no') + }) it('does not allowe duplicates', () => { - expect(mergeClasses(['hello'], ['hello'])).toBe('hello'); - }); + expect(mergeClasses(['hello'], ['hello'])).toBe('hello') + }) it('merges the truthy values from an object format', () => { expect( @@ -36,8 +43,8 @@ describe('merge classes function', () => { { world: 1, universe: null, - } as unknown, - ), - ).toBe('hello world'); - }); -}); + } as unknown + ) + ).toBe('hello world') + }) +}) diff --git a/src/__tests__/normalizeMeasure.test.ts b/src/__tests__/normalizeMeasure.test.ts index f2ab2e6..b19e1b5 100644 --- a/src/__tests__/normalizeMeasure.test.ts +++ b/src/__tests__/normalizeMeasure.test.ts @@ -1,35 +1,35 @@ -import normalizeMeasure from '../helpers/normalizeMeasure'; +import normalizeMeasure from '../helpers/normalizeMeasure' describe('normalizeMeasure', () => { it('converts a number into px', () => { - expect(normalizeMeasure(12)).toBe('12px'); - }); + expect(normalizeMeasure(12)).toBe('12px') + }) it('converts a decimal into px', () => { - expect(normalizeMeasure(12.34)).toBe('12.34px'); - }); + expect(normalizeMeasure(12.34)).toBe('12.34px') + }) it('keeps the amount in px as it is ', () => { - expect(normalizeMeasure('12.34px')).toBe('12.34px'); - }); + expect(normalizeMeasure('12.34px')).toBe('12.34px') + }) it('converts a numeric string to px', () => { - expect(normalizeMeasure('1234')).toBe('1234px'); - }); + expect(normalizeMeasure('1234')).toBe('1234px') + }) it('converts a numeric string with decimals px', () => { - expect(normalizeMeasure('12.34')).toBe('12.34px'); - }); + expect(normalizeMeasure('12.34')).toBe('12.34px') + }) it('keeps any random string as it is', () => { - expect(normalizeMeasure('123,456')).toBe('123,456'); - }); + expect(normalizeMeasure('123,456')).toBe('123,456') + }) it('keeps undefined values ', () => { - expect(normalizeMeasure(undefined)).toBe(undefined); - }); + expect(normalizeMeasure(undefined)).toBe(undefined) + }) it('converts a null value to undefined ', () => { - expect(normalizeMeasure(null)).toBe(undefined); - }); -}); + expect(normalizeMeasure(null)).toBe(undefined) + }) +}) diff --git a/src/__tests__/normalizeOptions.test.ts b/src/__tests__/normalizeOptions.test.ts index 2e10e8a..0f52dcc 100644 --- a/src/__tests__/normalizeOptions.test.ts +++ b/src/__tests__/normalizeOptions.test.ts @@ -1,37 +1,37 @@ -import { normalizeOptions } from '../index'; -import { InputOptions, NormalizedOptions } from '../types'; +import { normalizeOptions } from '../index' +import { InputOptions, NormalizedOptions } from '../types' describe('options as strings', () => { it('returns an empty array if no value', () => { - expect(normalizeOptions()).toEqual([]); - }); + expect(normalizeOptions()).toEqual([]) + }) it('accepts the options as array of strings', () => { - const options: InputOptions = ['Option A', 'Option B', 'Option C']; + const options: InputOptions = ['Option A', 'Option B', 'Option C'] const expectedOptions: NormalizedOptions = [ { value: 'Option A', text: 'Option A', raw: 'Option A' }, { value: 'Option B', text: 'Option B', raw: 'Option B' }, { value: 'Option C', text: 'Option C', raw: 'Option C' }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); -}); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) +}) describe('options as numbers', () => { it('accepts the options as array of numbers', () => { - const options: InputOptions = [1, 2, 5]; + const options: InputOptions = [1, 2, 5] const expectedOptions: NormalizedOptions = [ { value: 1, text: 1, raw: 1 }, { value: 2, text: 2, raw: 2 }, { value: 5, text: 5, raw: 5 }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); -}); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) +}) describe('options as key => value pair', () => { it('accepts the options as key => value pair', () => { @@ -39,17 +39,17 @@ describe('options as key => value pair', () => { 1: 'Option 1', A: 'Option A', 'Option 3': 'Option 3', - }; + } const expectedOptions: NormalizedOptions = [ { value: '1', text: 'Option 1' }, { value: 'A', text: 'Option A' }, { value: 'Option 3', text: 'Option 3' }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); -}); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) +}) describe('options as array of objects', () => { it('accepts the options on the default format', () => { @@ -57,23 +57,23 @@ describe('options as array of objects', () => { { value: 1, text: 'Option 1' }, { value: 'A', text: 'Option A' }, { value: 'Option 3', text: 'Option 3' }, - ]; + ] const expectedOptions: NormalizedOptions = [ { value: 1, text: 'Option 1', raw: { value: 1, text: 'Option 1' } }, { value: 'A', text: 'Option A', raw: { value: 'A', text: 'Option A' } }, { value: 'Option 3', text: 'Option 3', raw: { value: 'Option 3', text: 'Option 3' } }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) it('handles the disabled attribute', () => { const options: InputOptions = [ { value: '1', text: 'Option 1' }, { value: 'A', text: 'Option A', disabled: true }, { value: 'Option 3', text: 'Option 3', disabled: false }, - ]; + ] const expectedOptions: NormalizedOptions = [ { value: '1', text: 'Option 1', raw: { value: '1', text: 'Option 1' } }, @@ -88,11 +88,11 @@ describe('options as array of objects', () => { text: 'Option 3', raw: { value: 'Option 3', text: 'Option 3', disabled: false }, }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); -}); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) +}) describe('options with children', () => { it('handles the children in default format', () => { @@ -105,7 +105,7 @@ describe('options with children', () => { { value: 2, text: 'Children 2' }, ], }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -117,10 +117,10 @@ describe('options with children', () => { ], raw: options[0], }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) it('handles the children as arrays of strings', () => { const options = [ @@ -129,7 +129,7 @@ describe('options with children', () => { text: 'Option A', children: ['Children 1', 'Children 2'], }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -141,10 +141,10 @@ describe('options with children', () => { ], raw: options[0], }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) it('handles the children as arrays of numbers', () => { const options = [ @@ -153,7 +153,7 @@ describe('options with children', () => { text: 'Option A', children: [1, 2, 3], }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -166,10 +166,10 @@ describe('options with children', () => { ], raw: options[0], }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) it('handles the children as value => key pair', () => { const options = [ @@ -181,7 +181,7 @@ describe('options with children', () => { A: 'Option A', }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -193,11 +193,11 @@ describe('options with children', () => { ], raw: options[0], }, - ]; + ] - expect(normalizeOptions(options)).toEqual(expectedOptions); - }); -}); + expect(normalizeOptions(options)).toEqual(expectedOptions) + }) +}) describe('guess option and values', () => { it('get the text with the `textAttribute` param', () => { @@ -210,7 +210,7 @@ describe('guess option and values', () => { value: 'B', label: 'Option B', }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -223,10 +223,10 @@ describe('guess option and values', () => { text: 'Option B', raw: options[1], }, - ]; + ] - expect(normalizeOptions(options, 'label')).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, 'label')).toEqual(expectedOptions) + }) it('get the text with the `textAttribute` param using dot notation', () => { const options = [ @@ -250,7 +250,7 @@ describe('guess option and values', () => { }, }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -263,12 +263,12 @@ describe('guess option and values', () => { text: 'User', raw: options[1], }, - ]; + ] - const textAttribute = 'user.role.label'; + const textAttribute = 'user.role.label' - expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions) + }) it('returns an empty string if the `textAttribute` param doesnt exist', () => { const options = [ @@ -284,7 +284,7 @@ describe('guess option and values', () => { name: 'Sauda', }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -297,12 +297,12 @@ describe('guess option and values', () => { text: '', raw: options[1], }, - ]; + ] - const textAttribute = 'user.role.label'; + const textAttribute = 'user.role.label' - expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions) + }) it('returns the text as an string if the text attribute is not `number` or `string`', () => { const options = [ @@ -326,7 +326,7 @@ describe('guess option and values', () => { }, }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -339,12 +339,12 @@ describe('guess option and values', () => { text: '[object Object]', raw: options[1], }, - ]; + ] - const textAttribute = 'user.role.label'; + const textAttribute = 'user.role.label' - expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions) + }) it('get the value with the `valueAttribute` param', () => { const options = [ @@ -356,7 +356,7 @@ describe('guess option and values', () => { id: 'B', text: 'Option B', }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -369,10 +369,10 @@ describe('guess option and values', () => { text: 'Option B', raw: options[1], }, - ]; + ] - expect(normalizeOptions(options, undefined, 'id')).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, undefined, 'id')).toEqual(expectedOptions) + }) it('get the value with the `valueAttribute` param using dot notation', () => { const options = [ @@ -396,7 +396,7 @@ describe('guess option and values', () => { }, }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -409,12 +409,12 @@ describe('guess option and values', () => { text: 'B', raw: options[1], }, - ]; + ] - const valueAttribute = 'user.role.id'; + const valueAttribute = 'user.role.id' - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) + }) it('returns an `undefined` if the `valueAttribute` param doesnt exist', () => { const options = [ @@ -430,7 +430,7 @@ describe('guess option and values', () => { role: 'user', }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -443,12 +443,12 @@ describe('guess option and values', () => { text: 'Saida', raw: options[1], }, - ]; + ] - const valueAttribute = 'user.role.id'; + const valueAttribute = 'user.role.id' - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) + }) it('returns `null` as value if the `valueAttribute` param is `null`', () => { const options = [ @@ -466,7 +466,7 @@ describe('guess option and values', () => { role: 'user', }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -479,12 +479,12 @@ describe('guess option and values', () => { text: 'Saida', raw: options[1], }, - ]; + ] - const valueAttribute = 'user.id'; + const valueAttribute = 'user.id' - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); - }); + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) + }) it('returns the value as an string if the value attribute is not `number` or `string`', () => { const options = [ @@ -508,7 +508,7 @@ describe('guess option and values', () => { }, }, }, - ]; + ] const expectedOptions: NormalizedOptions = [ { @@ -521,10 +521,10 @@ describe('guess option and values', () => { value: '[object Object]', raw: options[1], }, - ]; + ] - const valueAttribute = 'user.role.label'; + const valueAttribute = 'user.role.label' - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); - }); -}); + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) + }) +}) diff --git a/src/__tests__/normalizedOptionIsDisabled.test.ts b/src/__tests__/normalizedOptionIsDisabled.test.ts index 3c83f57..8537027 100644 --- a/src/__tests__/normalizedOptionIsDisabled.test.ts +++ b/src/__tests__/normalizedOptionIsDisabled.test.ts @@ -1,5 +1,5 @@ -import { NormalizedOption } from '..'; -import normalizedOptionIsDisabled from '../helpers/normalizedOptionIsDisabled'; +import { NormalizedOption } from '..' +import normalizedOptionIsDisabled from '../helpers/normalizedOptionIsDisabled' describe('normalizedOptionIsDisabled', () => { it('option disabled attribute is "disabled" returns true ', () => { @@ -7,35 +7,35 @@ describe('normalizedOptionIsDisabled', () => { value: 'value', text: 'text', disabled: 'disabled', - }; + } - expect(normalizedOptionIsDisabled(option)).toBe(true); - }); + expect(normalizedOptionIsDisabled(option)).toBe(true) + }) it('option disabled attribute is `true` returns true ', () => { const option: NormalizedOption = { value: 'value', text: 'text', disabled: true, - }; + } - expect(normalizedOptionIsDisabled(option)).toBe(true); - }); + expect(normalizedOptionIsDisabled(option)).toBe(true) + }) it('option disabled attribute is `false` returns false ', () => { const option: NormalizedOption = { value: 'value', text: 'text', disabled: false, - }; + } - expect(normalizedOptionIsDisabled(option)).toBe(false); - }); + expect(normalizedOptionIsDisabled(option)).toBe(false) + }) it('option doesnt have disabled attribute returns false ', () => { const option: NormalizedOption = { value: 'value', text: 'text', - }; + } - expect(normalizedOptionIsDisabled(option)).toBe(false); - }); -}); + expect(normalizedOptionIsDisabled(option)).toBe(false) + }) +}) diff --git a/src/__tests__/parseVariant.test.ts b/src/__tests__/parseVariant.test.ts index 7095bb2..9943d9c 100644 --- a/src/__tests__/parseVariant.test.ts +++ b/src/__tests__/parseVariant.test.ts @@ -1,13 +1,13 @@ -import { parseVariant } from '../index'; +import { parseVariant } from '../index' describe('parse variants function', () => { it('returns the same object if no variants passed', () => { const props = { class: 'text-red-500', type: 'number', - }; - expect(parseVariant(props)).toEqual(props); - }); + } + expect(parseVariant(props)).toEqual(props) + }) it('returns the variant props if a variant is added', () => { const props = { @@ -20,24 +20,24 @@ describe('parse variants function', () => { }, }, variant: 'alt', - }; - expect(parseVariant(props)).toEqual(props.variants.alt); - }); + } + expect(parseVariant(props)).toEqual(props.variants.alt) + }) it('returns the default configuration', () => { - const props = {}; - const globalConfiguration = {}; + const props = {} + const globalConfiguration = {} const defaultConfiguration = { type: 'text', fixedClasses: 'border p-3', classes: 'text-red-500', - }; + } expect(parseVariant(props, globalConfiguration, defaultConfiguration)).toEqual({ type: 'text', class: 'text-red-500 border p-3', - }); - }); + }) + }) it('merge the variant props with the default props', () => { const props = { @@ -51,34 +51,34 @@ describe('parse variants function', () => { }, }, variant: 'alt', - }; + } expect(parseVariant(props)).toEqual({ ...props.variants.alt, ...{ placeholder: props.placeholder, }, - }); - }); + }) + }) it('use the props over the configuration', () => { const props = { class: 'text-red-500', type: 'number', placeholder: 'Hello world', - }; + } const configuration = { class: 'text-blue-500', - }; + } - expect(parseVariant(props, configuration)).toEqual(props); - }); + expect(parseVariant(props, configuration)).toEqual(props) + }) it('use the variant from the configuration', () => { const props = { variant: 'alt', - }; + } const configuration = { class: 'text-blue-500', @@ -88,40 +88,40 @@ describe('parse variants function', () => { type: 'text', }, }, - }; + } - expect(parseVariant(props, configuration)).toEqual(configuration.variants.alt); - }); + expect(parseVariant(props, configuration)).toEqual(configuration.variants.alt) + }) it('use the configuration if no props sent', () => { - const props = {}; + const props = {} const configuration = { class: 'text-blue-500', type: 'text', - }; + } - expect(parseVariant(props, configuration)).toEqual(configuration); - }); + expect(parseVariant(props, configuration)).toEqual(configuration) + }) it('doesnt return the className if class is empty', () => { const props = { class: undefined, type: 'text', - }; + } - expect(parseVariant(props)).not.toHaveProperty('className'); - }); + expect(parseVariant(props)).not.toHaveProperty('className') + }) it('merges className, classes and fixedClasses', () => { const props = { class: 'text-red-500', classes: ['border-red-500'], fixedClasses: { 'border-2': true }, - }; + } - expect(parseVariant(props).class).toBe('text-red-500 border-red-500 border-2'); - }); + expect(parseVariant(props).class).toBe('text-red-500 border-red-500 border-2') + }) it('merges className, fixedClasses and variant classes', () => { const props = { @@ -134,10 +134,10 @@ describe('parse variants function', () => { }, }, variant: 'alt', - }; + } - expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border-2'); - }); + expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border-2') + }) it('merges className and variant fixedClasses and classes', () => { const props = { @@ -151,15 +151,15 @@ describe('parse variants function', () => { }, }, variant: 'alt', - }; + } - expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border'); - }); + expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border') + }) it('uses the classes from the configuration', () => { const props = { variant: 'error', - }; + } const configuration = { classes: 'text-black', @@ -168,8 +168,8 @@ describe('parse variants function', () => { classes: 'text-red-500', }, }, - }; + } - expect(parseVariant(props, configuration).class).toBe('text-red-500'); - }); -}); + expect(parseVariant(props, configuration).class).toBe('text-red-500') + }) +}) diff --git a/src/__tests__/parseVariantWithClassesList.test.ts b/src/__tests__/parseVariantWithClassesList.test.ts index 37f4674..827f36e 100644 --- a/src/__tests__/parseVariantWithClassesList.test.ts +++ b/src/__tests__/parseVariantWithClassesList.test.ts @@ -1,15 +1,15 @@ -import { parseVariantWithClassesList } from '../index'; -import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types'; +import { parseVariantWithClassesList } from '../index' +import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types' describe('parse variants with classes list function', () => { it('returns the same object if no variants passed', () => { const props = { class: 'text-red-500', type: 'number', - }; + } - expect(parseVariantWithClassesList(props, [])).toEqual(props); - }); + expect(parseVariantWithClassesList(props, [])).toEqual(props) + }) it('returns the variant props if a variant is added', () => { const props = { @@ -22,13 +22,13 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - }; - expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt); - }); + } + expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt) + }) it('returns the default configuration', () => { - const props = {}; - const globalConfiguration = {}; + const props = {} + const globalConfiguration = {} const defaultConfiguration = { type: 'text', fixedClasses: { @@ -37,20 +37,20 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }); - }); + }) + }) it('returns the global configuration', () => { - const props = {}; + const props = {} const globalConfiguration = { type: 'text', fixedClasses: { @@ -59,7 +59,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } const defaultConfiguration = { type: 'button', @@ -69,17 +69,17 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-blue-500', }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }); - }); + }) + }) it('returns the prop configuration from the variant', () => { const props = { @@ -95,7 +95,7 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } const globalConfiguration = { type: 'text', @@ -105,7 +105,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } const defaultConfiguration = { variants: { @@ -119,22 +119,22 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }); - }); + }) + }) it('returns the global configuration from the variant', () => { const props = { variant: 'error', - }; + } const globalConfiguration = { type: 'text', @@ -155,7 +155,7 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } const defaultConfiguration = { variants: { @@ -169,22 +169,22 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }); - }); + }) + }) it('returns the default configuration from the variant', () => { const props = { variant: 'error', - }; + } const globalConfiguration = { type: 'text', fixedClasses: { @@ -193,7 +193,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - }; + } const defaultConfiguration = { variants: { @@ -207,17 +207,17 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }); - }); + }) + }) it('merge the variant props with the default props', () => { const props = { @@ -231,55 +231,55 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - }; + } expect(parseVariantWithClassesList(props, [])).toEqual({ ...props.variants.alt, ...{ placeholder: props.placeholder, }, - }); - }); + }) + }) it('use the props over the configuration', () => { const props = { class: 'text-red-500', type: 'number', placeholder: 'Hello world', - }; + } const configuration = { class: 'text-blue-500', - }; + } - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props); - }); + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props) + }) it('respects the props for classes list', () => { const props: CSSClass = { classes: { wrapper: 'm-3', body: ({ clear, add }) => { - clear(); - add('text-gray-500'); + clear() + add('text-gray-500') }, }, - }; + } const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { wrapper: 'p-4 m-3', body: 'text-gray-500', }, - }); - }); + }) + }) it('respects only the props defined from the configuration', () => { const props = { @@ -287,14 +287,14 @@ describe('parse variants with classes list function', () => { wrapper: 'm-3', inner: 'p-2', }, - }; + } const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { @@ -302,8 +302,8 @@ describe('parse variants with classes list function', () => { wrapper: 'p-4 m-3', inner: undefined, }, - }); - }); + }) + }) it('accepts undefined values', () => { const props = { @@ -311,58 +311,58 @@ describe('parse variants with classes list function', () => { wrapper: undefined, body: 'text-gray-500', }, - }; + } const configuration = { classes: { wrapper: 'p-4', body: 'bg-red-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], {}, configuration)).toEqual({ classesList: { wrapper: undefined, body: 'bg-red-500 text-gray-500', }, - }); - }); + }) + }) it('pass `undefined` in the classes props clear any value', () => { const props = { classes: undefined, - }; + } const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('pass `undefined` in the fixedClasses props clear any value', () => { const props = { fixedClasses: undefined, - }; + } const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('pass `undefined` in the variant classes props clear any value', () => { const props = { @@ -372,20 +372,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - }; + } const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('pass `undefined` in the variant fixedClasses props clear any value', () => { const props = { @@ -395,25 +395,25 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - }; + } const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }); - }); + }) + }) it('considers not defined values from the configuration variant', () => { const props = { variant: 'error', - }; + } const configuration = { variants: { @@ -426,25 +426,25 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } - const defaultConfiguration = {}; + const defaultConfiguration = {} expect( - parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) ).toEqual({ classesList: { wrapper: 'border p-3', }, - }); - }); + }) + }) it('considers not defined values from the defaultConfiguration variant', () => { const props = { variant: 'error', - }; + } - const configuration = {}; + const configuration = {} const defaultConfiguration = { variants: { @@ -457,21 +457,21 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect( - parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration), + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) ).toEqual({ classesList: { wrapper: 'border p-3', }, - }); - }); + }) + }) it('use the variant from the configuration', () => { const props = { variant: 'alt', - }; + } const configuration = { class: 'text-blue-500', @@ -481,23 +481,23 @@ describe('parse variants with classes list function', () => { type: 'text', }, }, - }; + } expect(parseVariantWithClassesList(props, [], configuration)).toEqual( - configuration.variants.alt, - ); - }); + configuration.variants.alt + ) + }) it('use the configuration if no props sent', () => { - const props = {}; + const props = {} const configuration = { class: 'text-blue-500', type: 'text', - }; + } - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration); - }); + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration) + }) it('merges className and fixedClasses', () => { const props = { @@ -508,20 +508,20 @@ describe('parse variants with classes list function', () => { fixedClasses: { wrapper: { 'border-2': true }, }, - }; + } - const config = parseVariantWithClassesList(props, ['wrapper']); + const config = parseVariantWithClassesList(props, ['wrapper']) expect(config).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-red-500 border-2', }, - }); - }); + }) + }) it('merges fixedClasses and variant classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { class: 'text-red-500', @@ -539,20 +539,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - }; + } expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-blue-500 border-2', }, - }); - }); + }) + }) it('uses the classes from the configuration', () => { const props = { variant: 'error', - }; + } const configuration = { classes: { @@ -565,25 +565,25 @@ describe('parse variants with classes list function', () => { }, }, }, - }; + } expect(parseVariantWithClassesList(props, ['wrapper'], configuration)).toEqual({ classesList: { wrapper: 'text-red-500', }, - }); - }); + }) + }) it('handles undefined classes for a variant', () => { const props = { variant: 'error', - }; + } - expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}); - }); + expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}) + }) it('merges only the attributes that are defined from the variant', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { @@ -601,10 +601,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - }; + } expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -612,11 +612,11 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500', input: 'shadow', }, - }); - }); + }) + }) it('merges only the attributes that are defined from the variant and keep the fixed classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { fixedClasses: { @@ -640,10 +640,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - }; + } expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) ).toEqual({ classesList: { wrapper: 'space-x-2 flex items-center', @@ -651,33 +651,34 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500 semibold', input: 'shadow', }, - }); - }); + }) + }) it('merges the only the new attributes to the global configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', }, - }; + } - const globalConfiguration: WithVariantPropsAndClassesList = { - classes: { - wrapper: 'flex items-center space-x-2', - inputWrapper: 'inline-flex', - label: 'uppercase text-gray-500', - input: '', - }, - }; + const globalConfiguration: WithVariantPropsAndClassesList = + { + classes: { + wrapper: 'flex items-center space-x-2', + inputWrapper: 'inline-flex', + label: 'uppercase text-gray-500', + input: '', + }, + } expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], - globalConfiguration, - ), + globalConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -685,17 +686,18 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }); - }); + }) + }) it('it merges the new attributes from the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' - const globalConfiguration: WithVariantPropsAndClassesList = { - classes: { - input: 'border-1', - }, - }; + const globalConfiguration: WithVariantPropsAndClassesList = + { + classes: { + input: 'border-1', + }, + } const defaultConfiguration = { classes: { @@ -704,15 +706,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - }; + } expect( parseVariantWithClassesList( {}, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration, - ), + defaultConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -720,20 +722,20 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }); - }); + }) + }) it('it merges the props with the the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', label: ({ add }) => { - add('bg-green-500'); + add('bg-green-500') }, }, - }; + } const defaultConfiguration = { classes: { @@ -742,15 +744,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - }; + } expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], {}, - defaultConfiguration, - ), + defaultConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -758,28 +760,28 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500 bg-green-500', input: 'border-1', }, - }); - }); + }) + }) it('it merges the global configuration, the props, and the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' const props: WithVariantPropsAndClassesList = { classes: { wrapper: [ ({ clear }) => { - clear(); + clear() }, 'flex items-center space-x-2', ], }, - }; + } const globalConfiguration = { classes: { input: 'border-1', }, - }; + } const defaultConfiguration = { classes: { @@ -788,15 +790,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - }; + } expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration, - ), + defaultConfiguration + ) ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -804,6 +806,6 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }); - }); -}); + }) + }) +}) diff --git a/src/__tests__/pick.test.ts b/src/__tests__/pick.test.ts index 3b4222a..a1609c2 100644 --- a/src/__tests__/pick.test.ts +++ b/src/__tests__/pick.test.ts @@ -1,4 +1,4 @@ -import pick from '../helpers/pick'; +import pick from '../helpers/pick' describe('pick', () => { it('filter the truthy attributes of an object', () => { @@ -8,13 +8,13 @@ describe('pick', () => { gender: '', other: undefined, onemore: false, - }; + } expect(pick(obj)).toEqual({ name: 'Alfonso', age: 33, - }); - }); + }) + }) it('filter the attributes of an object by a condition', () => { const obj = { @@ -23,13 +23,13 @@ describe('pick', () => { gender: '', other: undefined, onemore: false, - }; + } expect(pick(obj, (value) => ['number', 'undefined'].includes(typeof value))).toEqual({ age: 33, other: undefined, - }); - }); + }) + }) it('filter the attributes of an object by a condition with the key name', () => { const obj = { @@ -38,11 +38,11 @@ describe('pick', () => { gender: '', other: undefined, onemore: false, - }; + } expect(pick(obj, (_value, key) => ['age', 'other'].includes(key))).toEqual({ age: 33, other: undefined, - }); - }); -}); + }) + }) +}) diff --git a/src/__tests__/promisify.test.ts b/src/__tests__/promisify.test.ts index 3b5ad3a..536601e 100644 --- a/src/__tests__/promisify.test.ts +++ b/src/__tests__/promisify.test.ts @@ -1,27 +1,27 @@ -import promisify from '../helpers/promisify'; +import promisify from '../helpers/promisify' describe('promisify', () => { it('converts a random value into a promise', async () => { - const value = 'result'; + const value = 'result' - const promise = promisify(value); + const promise = promisify(value) - expect(promise).toBeInstanceOf(Promise); + expect(promise).toBeInstanceOf(Promise) - const result = await promise; + const result = await promise - expect(result).toBe(value); - }); + expect(result).toBe(value) + }) it('keeps promises as it is', async () => { - const value = new Promise((resolve) => resolve('result')); + const value = new Promise((resolve) => resolve('result')) - const promise = promisify(value); + const promise = promisify(value) - expect(promise).toBeInstanceOf(Promise); + expect(promise).toBeInstanceOf(Promise) - const result = await promise; + const result = await promise - expect(result).toBe('result'); - }); -}); + expect(result).toBe('result') + }) +}) diff --git a/src/__tests__/promisifyFunctionResult.test.ts b/src/__tests__/promisifyFunctionResult.test.ts index fdb81b7..0692cd4 100644 --- a/src/__tests__/promisifyFunctionResult.test.ts +++ b/src/__tests__/promisifyFunctionResult.test.ts @@ -1,79 +1,80 @@ -import promisifyFunctionResult from '../helpers/promisifyFunctionResult'; +import promisifyFunctionResult from '../helpers/promisifyFunctionResult' describe('promisifyFunctionResult', () => { it('converts the result of a function into a promise', async () => { - const fn = () => 'result'; + const fn = () => 'result' - const promisified = promisifyFunctionResult(fn); + const promisified = promisifyFunctionResult(fn) - expect(promisified).toBeInstanceOf(Promise); + expect(promisified).toBeInstanceOf(Promise) - const result = await promisified; + const result = await promisified - expect(result).toBe('result'); - }); + expect(result).toBe('result') + }) it('keeps promises as it is', async () => { - const fn = () => new Promise((resolve) => resolve('result')); + const fn = () => new Promise((resolve) => resolve('result')) - const promisified = promisifyFunctionResult(fn); + const promisified = promisifyFunctionResult(fn) - expect(promisified).toBeInstanceOf(Promise); + expect(promisified).toBeInstanceOf(Promise) - const result = await promisified; + const result = await promisified - expect(result).toBe('result'); - }); + expect(result).toBe('result') + }) it('pass the parameters to the function', async () => { const fn = (status: string): string => { if (status === 'success') { - return 'success'; + return 'success' } - return 'error'; - }; + return 'error' + } - const promisified = promisifyFunctionResult(fn, 'success'); + const promisified = promisifyFunctionResult(fn, 'success') - expect(promisified).toBeInstanceOf(Promise); + expect(promisified).toBeInstanceOf(Promise) - const result = await promisified; + const result = await promisified - expect(result).toBe('success'); + expect(result).toBe('success') - const promisified2 = promisifyFunctionResult(fn, 'other'); + const promisified2 = promisifyFunctionResult(fn, 'other') - expect(promisified2).toBeInstanceOf(Promise); + expect(promisified2).toBeInstanceOf(Promise) - const result2 = await promisified2; + const result2 = await promisified2 - expect(result2).toBe('error'); - }); + expect(result2).toBe('error') + }) it('pass the parameters to the promise', async () => { - const fn = (status: string): Promise => new Promise((resolve) => { - if (status === 'success') { - resolve('success'); - } + const fn = (status: string): Promise => + new Promise((resolve) => { + if (status === 'success') { + resolve('success') + } - resolve('error'); - }); + resolve('error') + }) - const promisified = promisifyFunctionResult(fn, 'success'); + const promisified = promisifyFunctionResult(fn, 'success') - expect(promisified).toBeInstanceOf(Promise); + expect(promisified).toBeInstanceOf(Promise) - const result = await promisified; + const result = await promisified - expect(result).toBe('success'); + expect(result).toBe('success') - const promisified2 = promisifyFunctionResult(fn, 'other'); + const promisified2 = promisifyFunctionResult(fn, 'other') - expect(promisified2).toBeInstanceOf(Promise); + expect(promisified2).toBeInstanceOf(Promise) - const result2 = await promisified2; + const result2 = await promisified2 - expect(result2).toBe('error'); - }); -}); + expect(result2).toBe('error') + }) +}) diff --git a/src/__tests__/substractFromArray.test.ts b/src/__tests__/substractFromArray.test.ts index 504284f..2e1148d 100644 --- a/src/__tests__/substractFromArray.test.ts +++ b/src/__tests__/substractFromArray.test.ts @@ -1,26 +1,24 @@ -import substractFromArray from '../helpers/substractFromArray'; +import substractFromArray from '../helpers/substractFromArray' describe('substractFromArray', () => { it('keeps the same array if item doesnt exist', () => { - const arr = [1, 2, 3]; - expect(substractFromArray(arr, 4)).toEqual([1, 2, 3]); - }); + const arr = [1, 2, 3] + expect(substractFromArray(arr, 4)).toEqual([1, 2, 3]) + }) it('removes the item if already exists', () => { - const arr = [1, 2, 3]; - expect(substractFromArray(arr, 1)).toEqual([2, 3]); + const arr = [1, 2, 3] + expect(substractFromArray(arr, 1)).toEqual([2, 3]) // Should not affect the original array - expect(arr).toEqual(arr); - }); + expect(arr).toEqual(arr) + }) it('returns an empty array if is not array', () => { - expect(substractFromArray(null, 'whatever')) - .toEqual([]); - }); + expect(substractFromArray(null, 'whatever')).toEqual([]) + }) it('removes an existing item for objects', () => { - const arr = [{ a: 1 }, { b: '2' }, { three: '3' }]; - expect(substractFromArray(arr, { b: '2' })) - .toEqual([{ a: 1 }, { three: '3' }]); - }); -}); + const arr = [{ a: 1 }, { b: '2' }, { three: '3' }] + expect(substractFromArray(arr, { b: '2' })).toEqual([{ a: 1 }, { three: '3' }]) + }) +}) diff --git a/src/__tests__/throttle.test.ts b/src/__tests__/throttle.test.ts index 5d51bc6..9630209 100644 --- a/src/__tests__/throttle.test.ts +++ b/src/__tests__/throttle.test.ts @@ -1,51 +1,51 @@ -import throttle from '../helpers/throttle'; +import throttle from '../helpers/throttle' describe('throttle', () => { it('runs the method after 200 ms by default', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - jest.useFakeTimers(); + jest.useFakeTimers() - const throttledFn = throttle(mockFn); + const throttledFn = throttle(mockFn) - throttledFn(); + throttledFn() - expect(mockFn).toHaveBeenCalledTimes(1); + expect(mockFn).toHaveBeenCalledTimes(1) - jest.advanceTimersByTime(199); + jest.advanceTimersByTime(199) - throttledFn(); + throttledFn() - expect(mockFn).toHaveBeenCalledTimes(1); + expect(mockFn).toHaveBeenCalledTimes(1) - jest.advanceTimersByTime(1); + jest.advanceTimersByTime(1) - throttledFn(); + throttledFn() - expect(mockFn).toHaveBeenCalledTimes(2); - }); + expect(mockFn).toHaveBeenCalledTimes(2) + }) it('runs the method inmediatly once', () => { - const mockFn = jest.fn(); + const mockFn = jest.fn() - jest.useFakeTimers(); + jest.useFakeTimers() - const throttledFn = throttle(mockFn, 300); + const throttledFn = throttle(mockFn, 300) - throttledFn(); + throttledFn() - expect(mockFn).toHaveBeenCalledTimes(1); + expect(mockFn).toHaveBeenCalledTimes(1) - jest.advanceTimersByTime(299); + jest.advanceTimersByTime(299) - throttledFn(); + throttledFn() - expect(mockFn).toHaveBeenCalledTimes(1); + expect(mockFn).toHaveBeenCalledTimes(1) - jest.advanceTimersByTime(1); + jest.advanceTimersByTime(1) - throttledFn(); + throttledFn() - expect(mockFn).toHaveBeenCalledTimes(2); - }); -}); + expect(mockFn).toHaveBeenCalledTimes(2) + }) +}) diff --git a/src/config/TAlertConfig.ts b/src/config/TAlertConfig.ts index 205d61f..d509f7a 100644 --- a/src/config/TAlertConfig.ts +++ b/src/config/TAlertConfig.ts @@ -1,21 +1,23 @@ -import { enterAndLeave } from './transitions'; +import { enterAndLeave } from './transitions' const TAlertConfig = { classes: { // @tw - wrapper: 'relative flex items-center p-4 border-l-4 border-blue-500 rounded shadow-sm bg-blue-50', + wrapper: + 'relative flex items-center p-4 border-l-4 border-blue-500 rounded shadow-sm bg-blue-50', // @tw body: 'flex-grow', // @tw - close: 'relative flex items-center justify-center flex-shrink-0 w-6 h-6 ml-4 text-blue-500 transition duration-100 ease-in-out rounded hover:bg-blue-200 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + close: + 'relative flex items-center justify-center flex-shrink-0 w-6 h-6 ml-4 text-blue-500 transition duration-100 ease-in-out rounded hover:bg-blue-200 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw closeIcon: 'w-4 h-4', ...enterAndLeave, }, -}; +} -export const TAlertClassesKeys = Object.keys(TAlertConfig.classes); +export const TAlertClassesKeys = Object.keys(TAlertConfig.classes) -export type TAlertClassesValidKeys = keyof typeof TAlertConfig.classes; +export type TAlertClassesValidKeys = keyof typeof TAlertConfig.classes -export default TAlertConfig; +export default TAlertConfig diff --git a/src/config/TButtonConfig.ts b/src/config/TButtonConfig.ts index 95ab2fd..657bd74 100644 --- a/src/config/TButtonConfig.ts +++ b/src/config/TButtonConfig.ts @@ -1,6 +1,6 @@ const TButtonConfig = { classes: 'block px-4 py-2 text-white transition duration-100 ease-in-out bg-blue-500 border border-transparent rounded shadow-sm hover:bg-blue-600 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -}; +} -export default TButtonConfig; +export default TButtonConfig diff --git a/src/config/TCardConfig.ts b/src/config/TCardConfig.ts index 278ce97..0a66fea 100644 --- a/src/config/TCardConfig.ts +++ b/src/config/TCardConfig.ts @@ -9,10 +9,10 @@ export const TCardConfig = { // @tw footer: 'p-3 border-t border-gray-100 rounded-b', }, -}; +} -export const TCardClassesKeys = Object.keys(TCardConfig.classes); +export const TCardClassesKeys = Object.keys(TCardConfig.classes) -export type TCardClassesValidKeys = keyof typeof TCardConfig.classes; +export type TCardClassesValidKeys = keyof typeof TCardConfig.classes -export default TCardConfig; +export default TCardConfig diff --git a/src/config/TCheckboxConfig.ts b/src/config/TCheckboxConfig.ts index da9b92d..5838c2a 100644 --- a/src/config/TCheckboxConfig.ts +++ b/src/config/TCheckboxConfig.ts @@ -1,6 +1,6 @@ const TCheckboxConfig = { classes: 'text-blue-500 transition duration-100 ease-in-out border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 focus:ring-offset-0 disabled:opacity-50 disabled:cursor-not-allowed', -}; +} -export default TCheckboxConfig; +export default TCheckboxConfig diff --git a/src/config/TDatepickerConfig.ts b/src/config/TDatepickerConfig.ts index 15276c4..1c2b666 100644 --- a/src/config/TDatepickerConfig.ts +++ b/src/config/TDatepickerConfig.ts @@ -27,7 +27,8 @@ const TDatepickerConfig = { // @tw inputWrapper: '', // @tw - input: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', + input: + 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', // @tw clearButton: 'text-gray-600 transition duration-100 ease-in-out rounded hover:bg-gray-100', // @tw @@ -43,7 +44,8 @@ const TDatepickerConfig = { // @tw navigator: 'px-3 pt-2', // @tw - navigatorViewButton: 'inline-flex px-2 py-1 -ml-1 transition duration-100 ease-in-out rounded-full cursor-pointer hover:bg-gray-100', + navigatorViewButton: + 'inline-flex px-2 py-1 -ml-1 transition duration-100 ease-in-out rounded-full cursor-pointer hover:bg-gray-100', // @tw navigatorViewButtonIcon: 'text-gray-400 fill-current', // @tw @@ -61,9 +63,11 @@ const TDatepickerConfig = { // @tw navigatorLabelYear: 'ml-1 text-gray-500', // @tw - navigatorPrevButton: 'inline-flex p-1 ml-2 ml-auto transition duration-100 ease-in-out rounded-full cursor-pointer hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed', + navigatorPrevButton: + 'inline-flex p-1 ml-2 ml-auto transition duration-100 ease-in-out rounded-full cursor-pointer hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed', // @tw - navigatorNextButton: 'inline-flex p-1 -mr-1 transition duration-100 ease-in-out rounded-full cursor-pointer hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed', + navigatorNextButton: + 'inline-flex p-1 -mr-1 transition duration-100 ease-in-out rounded-full cursor-pointer hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed', // @tw navigatorPrevButtonIcon: 'text-gray-400', // @tw @@ -75,7 +79,8 @@ const TDatepickerConfig = { // @tw calendarHeaderWrapper: '', // @tw - calendarHeaderWeekDay: 'flex items-center justify-center w-8 h-8 text-xs text-gray-500 uppercase', + calendarHeaderWeekDay: + 'flex items-center justify-center w-8 h-8 text-xs text-gray-500 uppercase', // @tw calendarDaysWrapper: '', // @tw @@ -83,7 +88,8 @@ const TDatepickerConfig = { // Day item // @tw - otherMonthDay: 'w-8 h-8 mx-auto text-sm text-gray-400 rounded-full hover:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed', + otherMonthDay: + 'w-8 h-8 mx-auto text-sm text-gray-400 rounded-full hover:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed', // @tw emptyDay: '', // @tw @@ -93,15 +99,19 @@ const TDatepickerConfig = { // @tw inRangeDay: 'w-full h-8 text-sm bg-blue-200 disabled:opacity-50 disabled:cursor-not-allowed', // @tw - selectedDay: 'w-8 h-8 mx-auto text-sm text-white bg-blue-500 rounded-full disabled:opacity-50 disabled:cursor-not-allowed', + selectedDay: + 'w-8 h-8 mx-auto text-sm text-white bg-blue-500 rounded-full disabled:opacity-50 disabled:cursor-not-allowed', // @tw - activeDay: 'w-8 h-8 mx-auto text-sm bg-blue-100 rounded-full disabled:opacity-50 disabled:cursor-not-allowed', + activeDay: + 'w-8 h-8 mx-auto text-sm bg-blue-100 rounded-full disabled:opacity-50 disabled:cursor-not-allowed', // @tw - highlightedDay: 'w-8 h-8 mx-auto text-sm bg-blue-200 rounded-full disabled:opacity-50 disabled:cursor-not-allowed', + highlightedDay: + 'w-8 h-8 mx-auto text-sm bg-blue-200 rounded-full disabled:opacity-50 disabled:cursor-not-allowed', // @tw day: 'w-8 h-8 mx-auto text-sm rounded-full hover:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed', // @tw - today: 'w-8 h-8 mx-auto text-sm border border-blue-500 rounded-full hover:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed', + today: + 'w-8 h-8 mx-auto text-sm border border-blue-500 rounded-full hover:bg-blue-100 disabled:opacity-50 disabled:cursor-not-allowed', // Months View // @tw @@ -129,35 +139,46 @@ const TDatepickerConfig = { // @tw timepickerTimeWrapper: 'flex items-center space-x-2', // @tw - timepickerTimeFieldsWrapper: 'flex items-center w-full text-right bg-gray-100 border border-gray-100 rounded-md focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + timepickerTimeFieldsWrapper: + 'flex items-center w-full text-right bg-gray-100 border border-gray-100 rounded-md focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - timepickerOkButton: 'text-sm font-semibold text-blue-600 uppercase transition duration-100 ease-in-out border border-transparent rounded cursor-pointer focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + timepickerOkButton: + 'text-sm font-semibold text-blue-600 uppercase transition duration-100 ease-in-out border border-transparent rounded cursor-pointer focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - timepickerInput: 'w-8 h-6 p-0 text-sm text-center transition duration-100 ease-in-out bg-transparent border border-transparent rounded focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + timepickerInput: + 'w-8 h-6 p-0 text-sm text-center transition duration-100 ease-in-out bg-transparent border border-transparent rounded focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw timepickerTimeLabel: 'flex-grow text-sm text-gray-500', // @tw - timepickerAmPmWrapper: 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out bg-gray-100 border border-transparent rounded cursor-pointer focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + timepickerAmPmWrapper: + 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out bg-gray-100 border border-transparent rounded cursor-pointer focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - timepickerAmPmWrapperChecked: 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out bg-gray-100 border border-transparent rounded cursor-pointer focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + timepickerAmPmWrapperChecked: + 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out bg-gray-100 border border-transparent rounded cursor-pointer focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - timepickerAmPmWrapperDisabled: 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out opacity-50 cursor-not-allowed', + timepickerAmPmWrapperDisabled: + 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out opacity-50 cursor-not-allowed', // @tw - timepickerAmPmWrapperCheckedDisabled: 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out opacity-50 cursor-not-allowed', + timepickerAmPmWrapperCheckedDisabled: + 'relative inline-flex flex-shrink-0 transition duration-200 ease-in-out opacity-50 cursor-not-allowed', // @tw - timepickerAmPmButton: 'absolute flex items-center justify-center w-6 h-6 text-xs text-gray-800 transition duration-200 ease-in-out transform translate-x-0 bg-white rounded shadow', + timepickerAmPmButton: + 'absolute flex items-center justify-center w-6 h-6 text-xs text-gray-800 transition duration-200 ease-in-out transform translate-x-0 bg-white rounded shadow', // @tw - timepickerAmPmButtonChecked: 'absolute flex items-center justify-center w-6 h-6 text-xs text-gray-800 transition duration-200 ease-in-out transform translate-x-full bg-white rounded shadow', + timepickerAmPmButtonChecked: + 'absolute flex items-center justify-center w-6 h-6 text-xs text-gray-800 transition duration-200 ease-in-out transform translate-x-full bg-white rounded shadow', // @tw - timepickerAmPmCheckedPlaceholder: 'flex items-center justify-center w-6 h-6 text-xs text-gray-500 rounded-sm', + timepickerAmPmCheckedPlaceholder: + 'flex items-center justify-center w-6 h-6 text-xs text-gray-500 rounded-sm', // @tw - timepickerAmPmUncheckedPlaceholder: 'flex items-center justify-center w-6 h-6 text-xs text-gray-500 rounded-sm', + timepickerAmPmUncheckedPlaceholder: + 'flex items-center justify-center w-6 h-6 text-xs text-gray-500 rounded-sm', // ...enterAndLeave, }, -}; +} -export const TDatepickerClassesKeys = Object.keys(TDatepickerConfig.classes); +export const TDatepickerClassesKeys = Object.keys(TDatepickerConfig.classes) -export type TDatepickerClassesValidKeys = keyof typeof TDatepickerConfig.classes; +export type TDatepickerClassesValidKeys = keyof typeof TDatepickerConfig.classes -export default TDatepickerConfig; +export default TDatepickerConfig diff --git a/src/config/TDialogConfig.ts b/src/config/TDialogConfig.ts index 87d74e7..3f6619d 100644 --- a/src/config/TDialogConfig.ts +++ b/src/config/TDialogConfig.ts @@ -1,13 +1,13 @@ -import { PromiseRejectFn, Data } from '../types/Misc'; -import TInputConfig from './TInputConfig'; +import { PromiseRejectFn, Data } from '../types/Misc' +import TInputConfig from './TInputConfig' // eslint-disable-next-line import/no-named-as-default -import TModalConfig from './TModalConfig'; +import TModalConfig from './TModalConfig' const { overlay: fixedOverlay, wrapper: fixedWrapper, modal: fixedDialog, -} = TModalConfig.fixedClasses; +} = TModalConfig.fixedClasses const { overlay, @@ -27,7 +27,7 @@ const { leaveActiveClass, leaveFromClass, leaveToClass, -} = TModalConfig.classes; +} = TModalConfig.classes const TDialogConfig = { fixedClasses: { @@ -47,7 +47,8 @@ const TDialogConfig = { // @tw content: 'flex flex-col justify-center w-full', // @tw - iconWrapper: 'flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto mb-2 bg-gray-100 rounded-full', + iconWrapper: + 'flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto mb-2 bg-gray-100 rounded-full', // @tw icon: 'w-6 h-6 text-gray-700', // @tw @@ -62,9 +63,11 @@ const TDialogConfig = { // @tw buttons: 'flex justify-center p-3 space-x-4 bg-gray-100 rounded-b', // @tw - cancelButton: 'block w-full max-w-xs px-4 py-2 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm hover:bg-gray-100 focus:border-gray-100 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', + cancelButton: + 'block w-full max-w-xs px-4 py-2 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm hover:bg-gray-100 focus:border-gray-100 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', // @tw - okButton: 'block w-full max-w-xs px-4 py-2 text-white transition duration-100 ease-in-out bg-blue-500 border border-transparent rounded shadow-sm hover:bg-blue-600 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', + okButton: + 'block w-full max-w-xs px-4 py-2 text-white transition duration-100 ease-in-out bg-blue-500 border border-transparent rounded shadow-sm hover:bg-blue-600 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', // @tw inputWrapper: 'mt-3', @@ -76,7 +79,8 @@ const TDialogConfig = { errorMessage: 'block p-3 mb-3 -mx-3 -mt-3 text-sm text-center text-red-500 rounded-t bg-red-50', // @tw - busyWrapper: 'absolute top-0 left-0 flex items-center justify-center w-full h-full bg-white bg-opacity-75', + busyWrapper: + 'absolute top-0 left-0 flex items-center justify-center w-full h-full bg-white bg-opacity-75', // @tw busyIcon: 'w-6 h-6 text-gray-500', @@ -94,7 +98,7 @@ const TDialogConfig = { overlayLeaveFromClass, overlayLeaveToClass, }, -}; +} export enum DialogType { Alert = 'alert', @@ -122,42 +126,46 @@ export enum DialogHideReason { } export type DialogResponse = { - hideReason: DialogHideReason; - isOk: boolean; - isCancel: boolean; - isDismissed: boolean; + hideReason: DialogHideReason + isOk: boolean + isCancel: boolean + isDismissed: boolean // eslint-disable-next-line @typescript-eslint/no-explicit-any - input?: any; + input?: any // eslint-disable-next-line @typescript-eslint/no-explicit-any - response?: any; -}; + response?: any +} -export type DialogShowFn = (name: string) => Promise; +export type DialogShowFn = (name: string) => Promise -export type DialogProgramaticallyShowFn = (titleOrDialogOptions: Options | string, text?: string, icon?: string) => Promise; +export type DialogProgramaticallyShowFn = ( + titleOrDialogOptions: Options | string, + text?: string, + icon?: string +) => Promise -export type DialogHideFn = (name: string) => void; +export type DialogHideFn = (name: string) => void export type DialogBeforeHideParams = { - cancel: PromiseRejectFn; - response?: DialogResponse; -}; + cancel: PromiseRejectFn + response?: DialogResponse +} export type DialogBeforeShowParams = { - cancel: PromiseRejectFn; + cancel: PromiseRejectFn // eslint-disable-next-line @typescript-eslint/no-explicit-any - params?: any; -}; + params?: any +} // eslint-disable-next-line @typescript-eslint/no-explicit-any -export type DialogInputValidatorFn = (value: any) => string | Promise | null | undefined; +export type DialogInputValidatorFn = (value: any) => string | Promise | null | undefined // @TODO: see if was can get use a more specific typing // eslint-disable-next-line @typescript-eslint/no-explicit-any -export type DialogPreconfirmFn = ((input: any) => Promise | any); +export type DialogPreconfirmFn = (input: any) => Promise | any -export const TDialogClassesKeys = Object.keys(TDialogConfig.classes); +export const TDialogClassesKeys = Object.keys(TDialogConfig.classes) -export type TDialogClassesValidKeys = keyof typeof TDialogConfig.classes; +export type TDialogClassesValidKeys = keyof typeof TDialogConfig.classes -export default TDialogConfig; +export default TDialogConfig diff --git a/src/config/TDropdownConfig.ts b/src/config/TDropdownConfig.ts index 6df1faa..4c43098 100644 --- a/src/config/TDropdownConfig.ts +++ b/src/config/TDropdownConfig.ts @@ -1,5 +1,5 @@ -import TButtonConfig from './TButtonConfig'; -import { enterAndLeave } from './transitions'; +import TButtonConfig from './TButtonConfig' +import { enterAndLeave } from './transitions' const TDropdownConfig = { classes: { @@ -8,11 +8,11 @@ const TDropdownConfig = { dropdown: 'w-56 bg-white rounded shadow', ...enterAndLeave, }, -}; +} -export const TDropdownClassesKeys = Object.keys(TDropdownConfig.classes); +export const TDropdownClassesKeys = Object.keys(TDropdownConfig.classes) -export type TDropdownClassesValidKeys = keyof typeof TDropdownConfig.classes; +export type TDropdownClassesValidKeys = keyof typeof TDropdownConfig.classes export const TDropdownPopperDefaultOptions = { placement: 'bottom', @@ -26,6 +26,6 @@ export const TDropdownPopperDefaultOptions = { ], strategy: 'absolute', onFirstUpdate: undefined, -}; +} -export default TDropdownConfig; +export default TDropdownConfig diff --git a/src/config/TInputConfig.ts b/src/config/TInputConfig.ts index e1f4403..2626f8c 100644 --- a/src/config/TInputConfig.ts +++ b/src/config/TInputConfig.ts @@ -1,6 +1,6 @@ const TInputConfig = { classes: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -}; +} -export default TInputConfig; +export default TInputConfig diff --git a/src/config/TInputGroupConfig.ts b/src/config/TInputGroupConfig.ts index 5bf944a..06cd5e1 100644 --- a/src/config/TInputGroupConfig.ts +++ b/src/config/TInputGroupConfig.ts @@ -11,10 +11,10 @@ const TInputGroupConfig = { // @tw description: 'text-sm text-gray-400', }, -}; +} -export const TInputGroupClassesKeys = Object.keys(TInputGroupConfig.classes); +export const TInputGroupClassesKeys = Object.keys(TInputGroupConfig.classes) -export type TInputGroupClassesValidKeys = keyof typeof TInputGroupConfig.classes; +export type TInputGroupClassesValidKeys = keyof typeof TInputGroupConfig.classes -export default TInputGroupConfig; +export default TInputGroupConfig diff --git a/src/config/TModalConfig.ts b/src/config/TModalConfig.ts index a608e87..82354c2 100644 --- a/src/config/TModalConfig.ts +++ b/src/config/TModalConfig.ts @@ -13,7 +13,8 @@ export const TModalConfig = { // @tw wrapper: 'z-50 max-w-lg px-3 py-12', // @tw - close: 'absolute top-0 right-0 z-10 flex items-center justify-center w-8 h-8 -m-3 text-gray-700 transition ease-in-out bg-gray-100 rounded-full shadow duration-400 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 hover:bg-gray-200', + close: + 'absolute top-0 right-0 z-10 flex items-center justify-center w-8 h-8 -m-3 text-gray-700 transition ease-in-out bg-gray-100 rounded-full shadow duration-400 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 hover:bg-gray-200', // @tw closeIcon: 'w-4 h-4', // @tw @@ -49,7 +50,7 @@ export const TModalConfig = { // @tw leaveToClass: 'transform scale-95 opacity-0', }, -}; +} export enum ModalHideReason { Outside = 'outside', @@ -60,12 +61,12 @@ export enum ModalHideReason { Other = 'other', } -export type ModalShowFn = (name: string, params?: Record) => void; +export type ModalShowFn = (name: string, params?: Record) => void -export type ModalHideFn = (name: string) => void; +export type ModalHideFn = (name: string) => void -export const TModalClassesKeys = Object.keys(TModalConfig.classes); +export const TModalClassesKeys = Object.keys(TModalConfig.classes) -export type TModalClassesValidKeys = keyof typeof TModalConfig.classes; +export type TModalClassesValidKeys = keyof typeof TModalConfig.classes -export default TModalConfig; +export default TModalConfig diff --git a/src/config/TRadioConfig.ts b/src/config/TRadioConfig.ts index d65b155..a12c19c 100644 --- a/src/config/TRadioConfig.ts +++ b/src/config/TRadioConfig.ts @@ -1,6 +1,6 @@ const TRadioConfig = { classes: 'text-blue-500 transition duration-100 ease-in-out border-gray-300 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 focus:ring-offset-0 disabled:opacity-50 disabled:cursor-not-allowed', -}; +} -export default TRadioConfig; +export default TRadioConfig diff --git a/src/config/TRichSelectConfig.ts b/src/config/TRichSelectConfig.ts index daffa88..b38795f 100644 --- a/src/config/TRichSelectConfig.ts +++ b/src/config/TRichSelectConfig.ts @@ -1,4 +1,4 @@ -import { enterAndLeave } from './transitions'; +import { enterAndLeave } from './transitions' const TRichSelectConfig = { classes: { @@ -7,7 +7,8 @@ const TRichSelectConfig = { // TDropdown Component // @tw - trigger: 'flex items-center justify-between w-full px-3 py-2 text-left text-black transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', + trigger: + 'flex items-center justify-between w-full px-3 py-2 text-left text-black transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', // @tw dropdown: 'z-10 bg-white rounded shadow-lg', // Dropdown content @@ -16,7 +17,8 @@ const TRichSelectConfig = { // Clear button // @tw - clearButton: 'absolute flex items-center justify-center w-6 h-6 text-gray-600 transition duration-100 ease-in-out rounded mt-2.5 mr-2 top-0 right-0 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + clearButton: + 'absolute flex items-center justify-center w-6 h-6 text-gray-600 transition duration-100 ease-in-out rounded mt-2.5 mr-2 top-0 right-0 hover:bg-gray-100 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // Option list // @tw @@ -60,7 +62,8 @@ const TRichSelectConfig = { // @tw searchWrapper: 'inline-block w-full placeholder-gray-400', // @tw - searchInput: 'inline-block w-full px-3 py-2 text-sm border border-gray-300 rounded shadow-inner bg-gray-50 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + searchInput: + 'inline-block w-full px-3 py-2 text-sm border border-gray-300 rounded shadow-inner bg-gray-50 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // State texts // @tw @@ -92,16 +95,17 @@ const TRichSelectConfig = { // @tw tagLabel: 'px-3', // @tw - tagDeleteButton: '-ml-1.5 h-full hover:bg-blue-600 hover:shadow-sm inline-flex items-center px-2 transition focus:border-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-opacity-50 rounded-r', + tagDeleteButton: + '-ml-1.5 h-full hover:bg-blue-600 hover:shadow-sm inline-flex items-center px-2 transition focus:border-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:ring-opacity-50 rounded-r', // @tw tagDeleteButtonIcon: 'w-3 h-3', ...enterAndLeave, }, -}; +} -export const TRichSelectClassesKeys = Object.keys(TRichSelectConfig.classes); +export const TRichSelectClassesKeys = Object.keys(TRichSelectConfig.classes) -export type TRichSelectClassesValidKeys = keyof typeof TRichSelectConfig.classes; +export type TRichSelectClassesValidKeys = keyof typeof TRichSelectConfig.classes -export default TRichSelectConfig; +export default TRichSelectConfig diff --git a/src/config/TSelectConfig.ts b/src/config/TSelectConfig.ts index caf65c7..3f20a3f 100644 --- a/src/config/TSelectConfig.ts +++ b/src/config/TSelectConfig.ts @@ -1,6 +1,6 @@ const TSelectConfig = { classes: 'block w-full pl-3 pr-10 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -}; +} -export default TSelectConfig; +export default TSelectConfig diff --git a/src/config/TTagConfig.ts b/src/config/TTagConfig.ts index f04f272..c05137c 100644 --- a/src/config/TTagConfig.ts +++ b/src/config/TTagConfig.ts @@ -1,6 +1,6 @@ const TTagConfig = { // @tw classes: '', -}; +} -export default TTagConfig; +export default TTagConfig diff --git a/src/config/TTextareaConfig.ts b/src/config/TTextareaConfig.ts index 0700d73..1ddd10a 100644 --- a/src/config/TTextareaConfig.ts +++ b/src/config/TTextareaConfig.ts @@ -1,6 +1,6 @@ const TTextareaConfig = { classes: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -}; +} -export default TTextareaConfig; +export default TTextareaConfig diff --git a/src/config/TToggleConfig.ts b/src/config/TToggleConfig.ts index 8338842..03b8f8f 100644 --- a/src/config/TToggleConfig.ts +++ b/src/config/TToggleConfig.ts @@ -3,31 +3,43 @@ const TToggleConfig = { classes: { // @tw - wrapper: 'bg-gray-100 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + wrapper: + 'bg-gray-100 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - wrapperChecked: 'bg-blue-500 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + wrapperChecked: + 'bg-blue-500 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - wrapperDisabled: 'bg-gray-100 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + wrapperDisabled: + 'bg-gray-100 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - wrapperCheckedDisabled: 'bg-blue-500 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', + wrapperCheckedDisabled: + 'bg-blue-500 border-2 border-transparent rounded-full focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50', // @tw - button: 'flex items-center justify-center w-5 h-5 text-xs text-gray-400 bg-white rounded-full shadow', + button: + 'flex items-center justify-center w-5 h-5 text-xs text-gray-400 bg-white rounded-full shadow', // @tw - buttonChecked: 'flex items-center justify-center w-5 h-5 text-xs text-blue-500 bg-white rounded-full shadow', + buttonChecked: + 'flex items-center justify-center w-5 h-5 text-xs text-blue-500 bg-white rounded-full shadow', // @tw - checkedPlaceholder: 'flex items-center justify-center w-5 h-5 text-xs text-gray-400 rounded-full', + checkedPlaceholder: + 'flex items-center justify-center w-5 h-5 text-xs text-gray-400 rounded-full', // @tw - uncheckedPlaceholder: 'flex items-center justify-center w-5 h-5 text-xs text-gray-400 rounded-full', + uncheckedPlaceholder: + 'flex items-center justify-center w-5 h-5 text-xs text-gray-400 rounded-full', }, fixedClasses: { // @tw - wrapper: 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out cursor-pointer', + wrapper: + 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out cursor-pointer', // @tw - wrapperChecked: 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out cursor-pointer', + wrapperChecked: + 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out cursor-pointer', // @tw - wrapperDisabled: 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out opacity-50 cursor-pointer cursor-not-allowed', + wrapperDisabled: + 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out opacity-50 cursor-pointer cursor-not-allowed', // @tw - wrapperCheckedDisabled: 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out opacity-50 cursor-pointer cursor-not-allowed', + wrapperCheckedDisabled: + 'relative inline-flex flex-shrink-0 transition-colors duration-200 ease-in-out opacity-50 cursor-pointer cursor-not-allowed', // @tw button: 'absolute transition duration-200 ease-in-out transform translate-x-0', // @tw @@ -37,10 +49,10 @@ const TToggleConfig = { // @tw uncheckedPlaceholder: '', }, -}; +} -export const TToggleClassesKeys = Object.keys(TToggleConfig.classes); +export const TToggleClassesKeys = Object.keys(TToggleConfig.classes) -export type TToggleClassesValidKeys = keyof typeof TToggleConfig.classes; +export type TToggleClassesValidKeys = keyof typeof TToggleConfig.classes -export default TToggleConfig; +export default TToggleConfig diff --git a/src/config/TWrappedCheckboxConfig.ts b/src/config/TWrappedCheckboxConfig.ts index 5b879ff..565850b 100644 --- a/src/config/TWrappedCheckboxConfig.ts +++ b/src/config/TWrappedCheckboxConfig.ts @@ -1,9 +1,24 @@ -import { CSSClass } from '../types'; -import TCheckboxConfig from './TCheckboxConfig'; +import { CSSClass } from '../types' +import TCheckboxConfig from './TCheckboxConfig' -export const TWrappedCheckboxClassesKeys = ['wrapper', 'wrapperChecked', 'inputWrapper', 'inputWrapperChecked', 'input', 'label', 'labelChecked']; +export const TWrappedCheckboxClassesKeys = [ + 'wrapper', + 'wrapperChecked', + 'inputWrapper', + 'inputWrapperChecked', + 'input', + 'label', + 'labelChecked', +] -export type TWrappedCheckboxClassesValidKeys = 'wrapper' | 'wrapperChecked' | 'inputWrapper' | 'inputWrapperChecked' | 'input' | 'label' | 'labelChecked'; +export type TWrappedCheckboxClassesValidKeys = + | 'wrapper' + | 'wrapperChecked' + | 'inputWrapper' + | 'inputWrapperChecked' + | 'input' + | 'label' + | 'labelChecked' export const TWrappedCheckboxConfig: { classes: { @@ -16,6 +31,6 @@ export const TWrappedCheckboxConfig: { label: '', input: TCheckboxConfig.classes, }, -}; +} -export default TWrappedCheckboxConfig; +export default TWrappedCheckboxConfig diff --git a/src/config/TWrappedRadioConfig.ts b/src/config/TWrappedRadioConfig.ts index 00f71a2..cd6acaa 100644 --- a/src/config/TWrappedRadioConfig.ts +++ b/src/config/TWrappedRadioConfig.ts @@ -1,10 +1,25 @@ -import { CSSClass } from '../types/CSSClass'; +import { CSSClass } from '../types/CSSClass' -import TRadioConfig from './TRadioConfig'; +import TRadioConfig from './TRadioConfig' -export const TWrappedRadioClassesKeys = ['wrapper', 'wrapperChecked', 'inputWrapper', 'inputWrapperChecked', 'input', 'label', 'labelChecked']; +export const TWrappedRadioClassesKeys = [ + 'wrapper', + 'wrapperChecked', + 'inputWrapper', + 'inputWrapperChecked', + 'input', + 'label', + 'labelChecked', +] -export type TWrappedRadioClassesValidKeys = 'wrapper' | 'wrapperChecked' | 'inputWrapper' | 'inputWrapperChecked' | 'input' | 'label' | 'labelChecked'; +export type TWrappedRadioClassesValidKeys = + | 'wrapper' + | 'wrapperChecked' + | 'inputWrapper' + | 'inputWrapperChecked' + | 'input' + | 'label' + | 'labelChecked' export const TWrappedRadioConfig: { classes: { @@ -17,6 +32,6 @@ export const TWrappedRadioConfig: { label: '', input: TRadioConfig.classes, }, -}; +} -export default TWrappedRadioConfig; +export default TWrappedRadioConfig diff --git a/src/config/index.ts b/src/config/index.ts index 5747cda..5003fd2 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,24 +1,69 @@ -export { default as TInputConfig } from './TInputConfig'; -export { default as TTextareaConfig } from './TTextareaConfig'; -export { default as TButtonConfig } from './TButtonConfig'; -export { default as TSelectConfig } from './TSelectConfig'; -export { default as TCheckboxConfig } from './TCheckboxConfig'; -export { default as TRadioConfig } from './TRadioConfig'; -export { default as TTagConfig } from './TTagConfig'; -export { default as TCardConfig, TCardClassesKeys, TCardClassesValidKeys } from './TCardConfig'; -export { - default as TModalConfig, TModalClassesKeys, TModalClassesValidKeys, ModalShowFn, ModalHideFn, ModalHideReason, -} from './TModalConfig'; -export { - default as TDialogConfig, TDialogClassesKeys, TDialogClassesValidKeys, DialogBeforeShowParams, DialogBeforeHideParams, DialogHideFn, DialogShowFn, DialogProgramaticallyShowFn, DialogResponse, DialogHideReason, DialogType, DialogIcon, DialogPreconfirmFn, DialogInputValidatorFn, -} from './TDialogConfig'; -export { default as TAlertConfig, TAlertClassesKeys, TAlertClassesValidKeys } from './TAlertConfig'; -export { default as TInputGroupConfig, TInputGroupClassesKeys, TInputGroupClassesValidKeys } from './TInputGroupConfig'; -export { - default as TDropdownConfig, TDropdownPopperDefaultOptions, TDropdownClassesKeys, TDropdownClassesValidKeys, -} from './TDropdownConfig'; -export { default as TRichSelectConfig, TRichSelectClassesKeys, TRichSelectClassesValidKeys } from './TRichSelectConfig'; -export { default as TDatepickerConfig, TDatepickerClassesKeys, TDatepickerClassesValidKeys } from './TDatepickerConfig'; -export { default as TToggleConfig, TToggleClassesKeys, TToggleClassesValidKeys } from './TToggleConfig'; -export { default as TWrappedRadioConfig, TWrappedRadioClassesKeys, TWrappedRadioClassesValidKeys } from './TWrappedRadioConfig'; -export { default as TWrappedCheckboxConfig, TWrappedCheckboxClassesKeys, TWrappedCheckboxClassesValidKeys } from './TWrappedCheckboxConfig'; +export { default as TInputConfig } from './TInputConfig' +export { default as TTextareaConfig } from './TTextareaConfig' +export { default as TButtonConfig } from './TButtonConfig' +export { default as TSelectConfig } from './TSelectConfig' +export { default as TCheckboxConfig } from './TCheckboxConfig' +export { default as TRadioConfig } from './TRadioConfig' +export { default as TTagConfig } from './TTagConfig' +export { default as TCardConfig, TCardClassesKeys, TCardClassesValidKeys } from './TCardConfig' +export { + default as TModalConfig, + TModalClassesKeys, + TModalClassesValidKeys, + ModalShowFn, + ModalHideFn, + ModalHideReason, +} from './TModalConfig' +export { + default as TDialogConfig, + TDialogClassesKeys, + TDialogClassesValidKeys, + DialogBeforeShowParams, + DialogBeforeHideParams, + DialogHideFn, + DialogShowFn, + DialogProgramaticallyShowFn, + DialogResponse, + DialogHideReason, + DialogType, + DialogIcon, + DialogPreconfirmFn, + DialogInputValidatorFn, +} from './TDialogConfig' +export { default as TAlertConfig, TAlertClassesKeys, TAlertClassesValidKeys } from './TAlertConfig' +export { + default as TInputGroupConfig, + TInputGroupClassesKeys, + TInputGroupClassesValidKeys, +} from './TInputGroupConfig' +export { + default as TDropdownConfig, + TDropdownPopperDefaultOptions, + TDropdownClassesKeys, + TDropdownClassesValidKeys, +} from './TDropdownConfig' +export { + default as TRichSelectConfig, + TRichSelectClassesKeys, + TRichSelectClassesValidKeys, +} from './TRichSelectConfig' +export { + default as TDatepickerConfig, + TDatepickerClassesKeys, + TDatepickerClassesValidKeys, +} from './TDatepickerConfig' +export { + default as TToggleConfig, + TToggleClassesKeys, + TToggleClassesValidKeys, +} from './TToggleConfig' +export { + default as TWrappedRadioConfig, + TWrappedRadioClassesKeys, + TWrappedRadioClassesValidKeys, +} from './TWrappedRadioConfig' +export { + default as TWrappedCheckboxConfig, + TWrappedCheckboxClassesKeys, + TWrappedCheckboxClassesValidKeys, +} from './TWrappedCheckboxConfig' diff --git a/src/config/transitions.ts b/src/config/transitions.ts index ba57ce1..54e40a9 100644 --- a/src/config/transitions.ts +++ b/src/config/transitions.ts @@ -12,4 +12,4 @@ export const enterAndLeave = { leaveFromClass: 'transform scale-100 opacity-100', // @tw leaveToClass: 'transform scale-95 opacity-0', -}; +} diff --git a/src/dates/addDays.ts b/src/dates/addDays.ts index a13fc90..5597ceb 100644 --- a/src/dates/addDays.ts +++ b/src/dates/addDays.ts @@ -1,9 +1,9 @@ -import clone from '../helpers/clone'; +import clone from '../helpers/clone' -const addDays = (date: Date, amount = 1) : Date => { - const result = clone(date); - result.setDate(result.getDate() + amount); - return result; -}; +const addDays = (date: Date, amount = 1): Date => { + const result = clone(date) + result.setDate(result.getDate() + amount) + return result +} -export default addDays; +export default addDays diff --git a/src/dates/addMonths.ts b/src/dates/addMonths.ts index 571194c..4daf5a8 100644 --- a/src/dates/addMonths.ts +++ b/src/dates/addMonths.ts @@ -1,18 +1,18 @@ -import clone from '../helpers/clone'; -import getLastDayOfPrevMonth from './getLastDayOfPrevMonth'; +import clone from '../helpers/clone' +import getLastDayOfPrevMonth from './getLastDayOfPrevMonth' const addMonths = (date: Date, amount = 1): Date => { - let newDate = clone(date); - newDate.setMonth(date.getMonth() + amount); + let newDate = clone(date) + newDate.setMonth(date.getMonth() + amount) // Means the current day has less days so the extra month is // in the following month if (newDate.getDate() !== date.getDate()) { // Assign the last day of previous month - newDate = getLastDayOfPrevMonth(newDate); + newDate = getLastDayOfPrevMonth(newDate) } - return newDate; -}; + return newDate +} -export default addMonths; +export default addMonths diff --git a/src/dates/addYears.ts b/src/dates/addYears.ts index 9537e85..ce7642d 100644 --- a/src/dates/addYears.ts +++ b/src/dates/addYears.ts @@ -1,19 +1,19 @@ -import clone from '../helpers/clone'; -import getLastDayOfPrevMonth from './getLastDayOfPrevMonth'; +import clone from '../helpers/clone' +import getLastDayOfPrevMonth from './getLastDayOfPrevMonth' const addYears = (date: Date, amount = 1): Date => { - let newDate = clone(date); + let newDate = clone(date) - newDate.setFullYear(date.getFullYear() + amount); + newDate.setFullYear(date.getFullYear() + amount) // Means the new date is is a different month, this happens when the // next month has less days than the current month. (29th feb vs 28th feb) if (newDate.getDate() !== date.getDate()) { // Assign the last day of previous month - newDate = getLastDayOfPrevMonth(newDate); + newDate = getLastDayOfPrevMonth(newDate) } - return newDate; -}; + return newDate +} -export default addYears; +export default addYears diff --git a/src/dates/buildDateFormatter.ts b/src/dates/buildDateFormatter.ts index 7c8ec12..2cb0736 100644 --- a/src/dates/buildDateFormatter.ts +++ b/src/dates/buildDateFormatter.ts @@ -1,12 +1,14 @@ -import formatDate from './formatDate'; -import { DateLocale, DateFormatter } from '../types/Dates'; +import formatDate from './formatDate' +import { DateLocale, DateFormatter } from '../types/Dates' -const buildDateFormatter = (locale: DateLocale, customDateFormatter?: DateFormatter) : DateFormatter => (date: Date | null | undefined, format = 'Y-m-d H:i:S') => { - if (customDateFormatter) { - return customDateFormatter(date, format, locale); - } +const buildDateFormatter = + (locale: DateLocale, customDateFormatter?: DateFormatter): DateFormatter => + (date: Date | null | undefined, format = 'Y-m-d H:i:S') => { + if (customDateFormatter) { + return customDateFormatter(date, format, locale) + } - return formatDate(date, format, locale); -}; + return formatDate(date, format, locale) + } -export default buildDateFormatter; +export default buildDateFormatter diff --git a/src/dates/buildDateParser.ts b/src/dates/buildDateParser.ts index 9465cf5..a8171bc 100644 --- a/src/dates/buildDateParser.ts +++ b/src/dates/buildDateParser.ts @@ -1,12 +1,14 @@ -import parseDate from './parseDate'; -import { DateLocale, DateValue, DateParser } from '../types/Dates'; +import parseDate from './parseDate' +import { DateLocale, DateValue, DateParser } from '../types/Dates' -const buildDateParser = (locale: DateLocale, customDateParser?: DateParser) : DateParser => (date: DateValue | null | undefined, format = 'Y-m-d H:i:S', timeless?: boolean) => { - if (customDateParser) { - return customDateParser(date, format, timeless, locale); - } +const buildDateParser = + (locale: DateLocale, customDateParser?: DateParser): DateParser => + (date: DateValue | null | undefined, format = 'Y-m-d H:i:S', timeless?: boolean) => { + if (customDateParser) { + return customDateParser(date, format, timeless, locale) + } - return parseDate(date, format, timeless, locale); -}; + return parseDate(date, format, timeless, locale) + } -export default buildDateParser; +export default buildDateParser diff --git a/src/dates/dateIsPartOfTheRange.ts b/src/dates/dateIsPartOfTheRange.ts index 26a8c2b..d795a02 100644 --- a/src/dates/dateIsPartOfTheRange.ts +++ b/src/dates/dateIsPartOfTheRange.ts @@ -1,25 +1,31 @@ -import { DateParser, DateValue } from '../types/Dates'; -import parseDate from './parseDate'; +import { DateParser, DateValue } from '../types/Dates' +import parseDate from './parseDate' -const dateIsPartOfTheRange = (date: Date, min: DateValue | undefined, max: DateValue | undefined, dateParser: DateParser = parseDate, dateFormat = 'Y-m-d H:i:S'): boolean => { - const minDate = min === undefined ? undefined : dateParser(min, dateFormat); - const maxDate = max === undefined ? undefined : dateParser(max, dateFormat); +const dateIsPartOfTheRange = ( + date: Date, + min: DateValue | undefined, + max: DateValue | undefined, + dateParser: DateParser = parseDate, + dateFormat = 'Y-m-d H:i:S' +): boolean => { + const minDate = min === undefined ? undefined : dateParser(min, dateFormat) + const maxDate = max === undefined ? undefined : dateParser(max, dateFormat) - const time = date.getTime(); + const time = date.getTime() if (minDate && maxDate) { - return time >= minDate.getTime() && time <= maxDate.getTime(); + return time >= minDate.getTime() && time <= maxDate.getTime() } if (minDate) { - return time >= minDate.getTime(); + return time >= minDate.getTime() } if (maxDate) { - return time <= maxDate.getTime(); + return time <= maxDate.getTime() } - return true; -}; + return true +} -export default dateIsPartOfTheRange; +export default dateIsPartOfTheRange diff --git a/src/dates/dayIsPartOfTheConditions.ts b/src/dates/dayIsPartOfTheConditions.ts index 767a9ac..dc65600 100644 --- a/src/dates/dayIsPartOfTheConditions.ts +++ b/src/dates/dayIsPartOfTheConditions.ts @@ -1,30 +1,35 @@ -import isSameDay from './isSameDay'; +import isSameDay from './isSameDay' -import { DateParser, DateConditions } from '../types/Dates'; +import { DateParser, DateConditions } from '../types/Dates' -const dayIsPartOfTheConditions = (date: Date | null | undefined, condition: DateConditions | undefined, dateParser: DateParser, dateFormat?: string): boolean => { +const dayIsPartOfTheConditions = ( + date: Date | null | undefined, + condition: DateConditions | undefined, + dateParser: DateParser, + dateFormat?: string +): boolean => { if (!date) { - return false; + return false } if (typeof condition === 'function') { - return condition(date); + return condition(date) } if (typeof condition === 'string' || condition instanceof String) { - const disabledDate = dateParser(condition as string, dateFormat); - return isSameDay(disabledDate, date); + const disabledDate = dateParser(condition as string, dateFormat) + return isSameDay(disabledDate, date) } if (condition instanceof Date) { - return isSameDay(condition, date); + return isSameDay(condition, date) } if (Array.isArray(condition)) { - return condition.some((c) => dayIsPartOfTheConditions(date, c, dateParser, dateFormat)); + return condition.some((c) => dayIsPartOfTheConditions(date, c, dateParser, dateFormat)) } - return false; -}; + return false +} -export default dayIsPartOfTheConditions; +export default dayIsPartOfTheConditions diff --git a/src/dates/formatDate.ts b/src/dates/formatDate.ts index 08d5c2a..460d72d 100644 --- a/src/dates/formatDate.ts +++ b/src/dates/formatDate.ts @@ -1,16 +1,13 @@ -import { DateLocale, TokenFormattingFunctions, DateToken } from '../types/Dates'; +import { DateLocale, TokenFormattingFunctions, DateToken } from '../types/Dates' -import { English } from './l10n/default'; +import { English } from './l10n/default' -const boolToInt = (bool: boolean) : 1 | 0 => (bool === true ? 1 : 0); +const boolToInt = (bool: boolean): 1 | 0 => (bool === true ? 1 : 0) -const pad = (number: string | number, length = 2) : string => `000${number}`.slice(length * -1); +const pad = (number: string | number, length = 2): string => `000${number}`.slice(length * -1) -const monthToString = ( - monthNumber: number, - shorthand: boolean, - locale: DateLocale, -): string => locale.months[shorthand ? 'shorthand' : 'longhand'][monthNumber]; +const monthToString = (monthNumber: number, shorthand: boolean, locale: DateLocale): string => + locale.months[shorthand ? 'shorthand' : 'longhand'][monthNumber] export const tokenFormatingFunctions: TokenFormattingFunctions = { // get the date in UTC @@ -18,23 +15,17 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // weekday name, short, e.g. Thu D(date: Date, locale: DateLocale) { - return locale.weekdays.shorthand[ - tokenFormatingFunctions.w(date, locale) as number - ]; + return locale.weekdays.shorthand[tokenFormatingFunctions.w(date, locale) as number] }, // full month name e.g. January F(date: Date, locale: DateLocale) { - return monthToString( - (tokenFormatingFunctions.n(date, locale) as number) - 1, - false, - locale, - ); + return monthToString((tokenFormatingFunctions.n(date, locale) as number) - 1, false, locale) }, // padded hour 1-12 G(date: Date, locale: DateLocale) { - return pad(tokenFormatingFunctions.h(date, locale)); + return pad(tokenFormatingFunctions.h(date, locale)) }, // hours with leading zero e.g. 03 @@ -42,7 +33,7 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // day (1-30) with ordinal suffix e.g. 1st, 2nd J(date: Date, locale: DateLocale) { - return date.getDate() + locale.ordinal(date.getDate()); + return date.getDate() + locale.ordinal(date.getDate()) }, // AM/PM @@ -50,7 +41,7 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // shorthand month e.g. Jan, Sep, Oct, etc M(date: Date, locale: DateLocale) { - return monthToString(date.getMonth(), true, locale); + return monthToString(date.getMonth(), true, locale) }, // seconds 00-59 @@ -61,25 +52,22 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { W(givenDate: Date) { // return options.getWeek(date); - const date = new Date(givenDate.getTime()); - date.setHours(0, 0, 0, 0); + const date = new Date(givenDate.getTime()) + date.setHours(0, 0, 0, 0) // Thursday in current week decides the year. - date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7)); + date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7)) // January 4 is always in week 1. - const week1 = new Date(date.getFullYear(), 0, 4); + const week1 = new Date(date.getFullYear(), 0, 4) // Adjust to Thursday in week 1 and count number of weeks from date to week1. return ( - 1 - + Math.round( - ((date.getTime() - week1.getTime()) / 86400000 - - 3 - + ((week1.getDay() + 6) % 7)) - / 7, - ) - ); + 1 + + Math.round( + ((date.getTime() - week1.getTime()) / 86400000 - 3 + ((week1.getDay() + 6) % 7)) / 7 + ) + ) }, // full year e.g. 2016, padded (0001-9999) @@ -99,7 +87,7 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // weekday name, full, e.g. Thursday l(date: Date, locale: DateLocale) { - return locale.weekdays.longhand[date.getDay()]; + return locale.weekdays.longhand[date.getDay()] }, // padded month number (01-12) @@ -116,26 +104,31 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // last two digits of year e.g. 16 for 2016 y: (date: Date) => String(date.getFullYear()).substring(2), -}; +} -const formatDate = (date: Date | null | undefined, format: string, customLocale?: DateLocale): string => { +const formatDate = ( + date: Date | null | undefined, + format: string, + customLocale?: DateLocale +): string => { if (!date) { - return ''; + return '' } - const locale = customLocale || English; + const locale = customLocale || English return format .split('') .map((char, i, arr) => { if (tokenFormatingFunctions[char as DateToken] && arr[i - 1] !== '\\') { - return tokenFormatingFunctions[char as DateToken](date, locale); - } if (char !== '\\') { - return char; + return tokenFormatingFunctions[char as DateToken](date, locale) } - return ''; + if (char !== '\\') { + return char + } + return '' }) - .join(''); -}; + .join('') +} -export default formatDate; +export default formatDate diff --git a/src/dates/getDateInDayNumber.ts b/src/dates/getDateInDayNumber.ts index b3191af..d6cc79c 100644 --- a/src/dates/getDateInDayNumber.ts +++ b/src/dates/getDateInDayNumber.ts @@ -1,3 +1,4 @@ -const getDateInDayNumber = (date: Date, dayNumber: number): Date => new Date(date.getFullYear(), date.getMonth(), dayNumber); +const getDateInDayNumber = (date: Date, dayNumber: number): Date => + new Date(date.getFullYear(), date.getMonth(), dayNumber) -export default getDateInDayNumber; +export default getDateInDayNumber diff --git a/src/dates/getFirstDayOfMonth.ts b/src/dates/getFirstDayOfMonth.ts index 34be39e..7033d2a 100644 --- a/src/dates/getFirstDayOfMonth.ts +++ b/src/dates/getFirstDayOfMonth.ts @@ -1,3 +1,4 @@ -const getFirstDayOfMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth(), 1); +const getFirstDayOfMonth = (fromDate: Date): Date => + new Date(fromDate.getFullYear(), fromDate.getMonth(), 1) -export default getFirstDayOfMonth; +export default getFirstDayOfMonth diff --git a/src/dates/getFirstDayOfNextMonth.ts b/src/dates/getFirstDayOfNextMonth.ts index b03c59a..e1f9033 100644 --- a/src/dates/getFirstDayOfNextMonth.ts +++ b/src/dates/getFirstDayOfNextMonth.ts @@ -1,3 +1,4 @@ -const getFirstDayOfNextMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 1); +const getFirstDayOfNextMonth = (fromDate: Date): Date => + new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 1) -export default getFirstDayOfNextMonth; +export default getFirstDayOfNextMonth diff --git a/src/dates/getFirstDayOfPrevMonth.ts b/src/dates/getFirstDayOfPrevMonth.ts index 59a6a21..a594a2c 100644 --- a/src/dates/getFirstDayOfPrevMonth.ts +++ b/src/dates/getFirstDayOfPrevMonth.ts @@ -1,3 +1,4 @@ -const getFirstDayOfPrevMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth() - 1, 1); +const getFirstDayOfPrevMonth = (fromDate: Date): Date => + new Date(fromDate.getFullYear(), fromDate.getMonth() - 1, 1) -export default getFirstDayOfPrevMonth; +export default getFirstDayOfPrevMonth diff --git a/src/dates/getLastDayOfMonth.ts b/src/dates/getLastDayOfMonth.ts index ca65470..e2261d3 100644 --- a/src/dates/getLastDayOfMonth.ts +++ b/src/dates/getLastDayOfMonth.ts @@ -1,3 +1,4 @@ -const getLastDayOfMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0); +const getLastDayOfMonth = (fromDate: Date): Date => + new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0) -export default getLastDayOfMonth; +export default getLastDayOfMonth diff --git a/src/dates/getLastDayOfPrevMonth.ts b/src/dates/getLastDayOfPrevMonth.ts index df64b03..db47d5c 100644 --- a/src/dates/getLastDayOfPrevMonth.ts +++ b/src/dates/getLastDayOfPrevMonth.ts @@ -1,3 +1,4 @@ -const getLastDayOfPrevMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth(), 0); +const getLastDayOfPrevMonth = (fromDate: Date): Date => + new Date(fromDate.getFullYear(), fromDate.getMonth(), 0) -export default getLastDayOfPrevMonth; +export default getLastDayOfPrevMonth diff --git a/src/dates/index.ts b/src/dates/index.ts index 70e7666..b36a9bf 100644 --- a/src/dates/index.ts +++ b/src/dates/index.ts @@ -1,14 +1,14 @@ -export { English as dateEnglishLocale } from './l10n/default'; -export { default as visibleDaysInMonthView } from './visibleDaysInMonthView'; -export { default as isSameMonth } from './isSameMonth'; -export { default as isSameDay } from './isSameDay'; -export { default as isToday } from './isToday'; -export { default as addDays } from './addDays'; -export { default as addMonths } from './addMonths'; -export { default as addYears } from './addYears'; -export { default as dateIsPartOfTheRange } from './dateIsPartOfTheRange'; -export { default as dayIsPartOfTheConditions } from './dayIsPartOfTheConditions'; -export { default as parseDate } from './parseDate'; -export { default as formatDate } from './formatDate'; -export { default as buildDateParser } from './buildDateParser'; -export { default as buildDateFormatter } from './buildDateFormatter'; +export { English as dateEnglishLocale } from './l10n/default' +export { default as visibleDaysInMonthView } from './visibleDaysInMonthView' +export { default as isSameMonth } from './isSameMonth' +export { default as isSameDay } from './isSameDay' +export { default as isToday } from './isToday' +export { default as addDays } from './addDays' +export { default as addMonths } from './addMonths' +export { default as addYears } from './addYears' +export { default as dateIsPartOfTheRange } from './dateIsPartOfTheRange' +export { default as dayIsPartOfTheConditions } from './dayIsPartOfTheConditions' +export { default as parseDate } from './parseDate' +export { default as formatDate } from './formatDate' +export { default as buildDateParser } from './buildDateParser' +export { default as buildDateFormatter } from './buildDateFormatter' diff --git a/src/dates/isSameDay.ts b/src/dates/isSameDay.ts index a4071b8..b00d5e0 100644 --- a/src/dates/isSameDay.ts +++ b/src/dates/isSameDay.ts @@ -1,11 +1,13 @@ const isSameDay = (date1?: Date, date2?: Date): boolean => { if (!date1 || !date2) { - return false; + return false } - return date1.getDate() === date2.getDate() - && date1.getMonth() === date2.getMonth() - && date1.getFullYear() === date2.getFullYear(); -}; + return ( + date1.getDate() === date2.getDate() && + date1.getMonth() === date2.getMonth() && + date1.getFullYear() === date2.getFullYear() + ) +} -export default isSameDay; +export default isSameDay diff --git a/src/dates/isSameMonth.ts b/src/dates/isSameMonth.ts index de506d9..f8bf410 100644 --- a/src/dates/isSameMonth.ts +++ b/src/dates/isSameMonth.ts @@ -1,9 +1,9 @@ const isSameMonth = (date1?: Date, date2?: Date): boolean => { if (!date1 || !date2) { - return false; + return false } - return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth(); -}; + return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() +} -export default isSameMonth; +export default isSameMonth diff --git a/src/dates/isToday.ts b/src/dates/isToday.ts index c442b16..c62448a 100644 --- a/src/dates/isToday.ts +++ b/src/dates/isToday.ts @@ -1,5 +1,5 @@ -import isSameDay from './isSameDay'; +import isSameDay from './isSameDay' -const isToday = (date: Date) : boolean => isSameDay(date, new Date()); +const isToday = (date: Date): boolean => isSameDay(date, new Date()) -export default isToday; +export default isToday diff --git a/src/dates/l10n/ar.ts b/src/dates/l10n/ar.ts index 8b8ad00..17a9866 100644 --- a/src/dates/l10n/ar.ts +++ b/src/dates/l10n/ar.ts @@ -1,18 +1,10 @@ /* Arabic locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Arabic: CustomDateLocale = { weekdays: { shorthand: ['أحد', 'اثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة', 'سبت'], - longhand: [ - 'الأحد', - 'الاثنين', - 'الثلاثاء', - 'الأربعاء', - 'الخميس', - 'الجمعة', - 'السبت', - ], + longhand: ['الأحد', 'الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'], }, months: { @@ -34,6 +26,6 @@ export const Arabic: CustomDateLocale = { }, rangeSeparator: ' - ', -}; +} -export default Arabic; +export default Arabic diff --git a/src/dates/l10n/at.ts b/src/dates/l10n/at.ts index b9ddf1b..389ce50 100644 --- a/src/dates/l10n/at.ts +++ b/src/dates/l10n/at.ts @@ -1,35 +1,14 @@ /* Austria locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Austria: CustomDateLocale = { weekdays: { shorthand: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], - longhand: [ - 'Sonntag', - 'Montag', - 'Dienstag', - 'Mittwoch', - 'Donnerstag', - 'Freitag', - 'Samstag', - ], + longhand: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'], }, months: { - shorthand: [ - 'Jän', - 'Feb', - 'Mär', - 'Apr', - 'Mai', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Dez', - ], + shorthand: ['Jän', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'], longhand: [ 'Jänner', 'Februar', @@ -49,6 +28,6 @@ export const Austria: CustomDateLocale = { firstDayOfWeek: 1, weekAbbreviation: 'KW', rangeSeparator: ' bis ', -}; +} -export default Austria; +export default Austria diff --git a/src/dates/l10n/az.ts b/src/dates/l10n/az.ts index ee9180b..d5ea0d9 100644 --- a/src/dates/l10n/az.ts +++ b/src/dates/l10n/az.ts @@ -1,5 +1,5 @@ /* Azerbaijan locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Azerbaijan: CustomDateLocale = { weekdays: { @@ -16,20 +16,7 @@ export const Azerbaijan: CustomDateLocale = { }, months: { - shorthand: [ - 'Yan', - 'Fev', - 'Mar', - 'Apr', - 'May', - 'İyn', - 'İyl', - 'Avq', - 'Sen', - 'Okt', - 'Noy', - 'Dek', - ], + shorthand: ['Yan', 'Fev', 'Mar', 'Apr', 'May', 'İyn', 'İyl', 'Avq', 'Sen', 'Okt', 'Noy', 'Dek'], longhand: [ 'Yanvar', 'Fevral', @@ -51,6 +38,6 @@ export const Azerbaijan: CustomDateLocale = { weekAbbreviation: 'Hf', amPM: ['GƏ', 'GS'], time24hr: true, -}; +} -export default Azerbaijan; +export default Azerbaijan diff --git a/src/dates/l10n/be.ts b/src/dates/l10n/be.ts index 147af1d..e51519f 100644 --- a/src/dates/l10n/be.ts +++ b/src/dates/l10n/be.ts @@ -1,34 +1,13 @@ /* Belarusian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Belarusian: CustomDateLocale = { weekdays: { shorthand: ['Нд', 'Пн', 'Аў', 'Ср', 'Чц', 'Пт', 'Сб'], - longhand: [ - 'Нядзеля', - 'Панядзелак', - 'Аўторак', - 'Серада', - 'Чацвер', - 'Пятніца', - 'Субота', - ], + longhand: ['Нядзеля', 'Панядзелак', 'Аўторак', 'Серада', 'Чацвер', 'Пятніца', 'Субота'], }, months: { - shorthand: [ - 'Сту', - 'Лют', - 'Сак', - 'Кра', - 'Тра', - 'Чэр', - 'Ліп', - 'Жні', - 'Вер', - 'Кас', - 'Ліс', - 'Сне', - ], + shorthand: ['Сту', 'Лют', 'Сак', 'Кра', 'Тра', 'Чэр', 'Ліп', 'Жні', 'Вер', 'Кас', 'Ліс', 'Сне'], longhand: [ 'Студзень', 'Люты', @@ -46,13 +25,13 @@ export const Belarusian: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, rangeSeparator: ' — ', weekAbbreviation: 'Тыд.', amPM: ['ДП', 'ПП'], yearAriaLabel: 'Год', time24hr: true, -}; +} -export default Belarusian; +export default Belarusian diff --git a/src/dates/l10n/bg.ts b/src/dates/l10n/bg.ts index 869f305..d18cd60 100644 --- a/src/dates/l10n/bg.ts +++ b/src/dates/l10n/bg.ts @@ -1,18 +1,10 @@ /* Bulgarian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Bulgarian: CustomDateLocale = { weekdays: { shorthand: ['Нд', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'], - longhand: [ - 'Неделя', - 'Понеделник', - 'Вторник', - 'Сряда', - 'Четвъртък', - 'Петък', - 'Събота', - ], + longhand: ['Неделя', 'Понеделник', 'Вторник', 'Сряда', 'Четвъртък', 'Петък', 'Събота'], }, months: { @@ -47,6 +39,6 @@ export const Bulgarian: CustomDateLocale = { }, time24hr: true, firstDayOfWeek: 1, -}; +} -export default Bulgarian; +export default Bulgarian diff --git a/src/dates/l10n/bn.ts b/src/dates/l10n/bn.ts index 3df5951..d8268b7 100644 --- a/src/dates/l10n/bn.ts +++ b/src/dates/l10n/bn.ts @@ -1,18 +1,10 @@ /* Bangla locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Bangla: CustomDateLocale = { weekdays: { shorthand: ['রবি', 'সোম', 'মঙ্গল', 'বুধ', 'বৃহস্পতি', 'শুক্র', 'শনি'], - longhand: [ - 'রবিবার', - 'সোমবার', - 'মঙ্গলবার', - 'বুধবার', - 'বৃহস্পতিবার', - 'শুক্রবার', - 'শনিবার', - ], + longhand: ['রবিবার', 'সোমবার', 'মঙ্গলবার', 'বুধবার', 'বৃহস্পতিবার', 'শুক্রবার', 'শনিবার'], }, months: { @@ -45,6 +37,6 @@ export const Bangla: CustomDateLocale = { 'ডিসেম্বর', ], }, -}; +} -export default Bangla; +export default Bangla diff --git a/src/dates/l10n/bs.ts b/src/dates/l10n/bs.ts index 6212f45..3e869bb 100644 --- a/src/dates/l10n/bs.ts +++ b/src/dates/l10n/bs.ts @@ -1,37 +1,16 @@ /* Bosnian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Bosnian: CustomDateLocale = { firstDayOfWeek: 1, weekdays: { shorthand: ['Ned', 'Pon', 'Uto', 'Sri', 'Čet', 'Pet', 'Sub'], - longhand: [ - 'Nedjelja', - 'Ponedjeljak', - 'Utorak', - 'Srijeda', - 'Četvrtak', - 'Petak', - 'Subota', - ], + longhand: ['Nedjelja', 'Ponedjeljak', 'Utorak', 'Srijeda', 'Četvrtak', 'Petak', 'Subota'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Maj', - 'Jun', - 'Jul', - 'Avg', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Avg', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'Januar', 'Februar', @@ -48,6 +27,6 @@ export const Bosnian: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Bosnian; +export default Bosnian diff --git a/src/dates/l10n/cat.ts b/src/dates/l10n/cat.ts index c61a2f4..2c1b98b 100644 --- a/src/dates/l10n/cat.ts +++ b/src/dates/l10n/cat.ts @@ -1,18 +1,10 @@ /* Catalan locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Catalan: CustomDateLocale = { weekdays: { shorthand: ['Dg', 'Dl', 'Dt', 'Dc', 'Dj', 'Dv', 'Ds'], - longhand: [ - 'Diumenge', - 'Dilluns', - 'Dimarts', - 'Dimecres', - 'Dijous', - 'Divendres', - 'Dissabte', - ], + longhand: ['Diumenge', 'Dilluns', 'Dimarts', 'Dimecres', 'Dijous', 'Divendres', 'Dissabte'], }, months: { @@ -47,24 +39,24 @@ export const Catalan: CustomDateLocale = { }, ordinal: (nth) => { - const s = nth % 100; - if (s > 3 && s < 21) return 'è'; + const s = nth % 100 + if (s > 3 && s < 21) return 'è' switch (s % 10) { case 1: - return 'r'; + return 'r' case 2: - return 'n'; + return 'n' case 3: - return 'r'; + return 'r' case 4: - return 't'; + return 't' default: - return 'è'; + return 'è' } }, firstDayOfWeek: 1, time24hr: true, -}; +} -export default Catalan; +export default Catalan diff --git a/src/dates/l10n/cs.ts b/src/dates/l10n/cs.ts index 97a8e6f..9c9603e 100644 --- a/src/dates/l10n/cs.ts +++ b/src/dates/l10n/cs.ts @@ -1,34 +1,13 @@ /* Czech locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Czech: CustomDateLocale = { weekdays: { shorthand: ['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'], - longhand: [ - 'Neděle', - 'Pondělí', - 'Úterý', - 'Středa', - 'Čtvrtek', - 'Pátek', - 'Sobota', - ], + longhand: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'], }, months: { - shorthand: [ - 'Led', - 'Ún', - 'Bře', - 'Dub', - 'Kvě', - 'Čer', - 'Čvc', - 'Srp', - 'Zář', - 'Říj', - 'Lis', - 'Pro', - ], + shorthand: ['Led', 'Ún', 'Bře', 'Dub', 'Kvě', 'Čer', 'Čvc', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro'], longhand: [ 'Leden', 'Únor', @@ -46,13 +25,13 @@ export const Czech: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '.'; + return '.' }, rangeSeparator: ' do ', weekAbbreviation: 'Týd.', amPM: ['dop.', 'odp.'], yearAriaLabel: 'Rok', time24hr: true, -}; +} -export default Czech; +export default Czech diff --git a/src/dates/l10n/cy.ts b/src/dates/l10n/cy.ts index 8d21b39..a29c266 100644 --- a/src/dates/l10n/cy.ts +++ b/src/dates/l10n/cy.ts @@ -1,5 +1,5 @@ /* Welsh locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Welsh: CustomDateLocale = { weekdays: { @@ -49,37 +49,28 @@ export const Welsh: CustomDateLocale = { firstDayOfWeek: 1, ordinal: (nth) => { - if (nth === 1) return 'af'; + if (nth === 1) return 'af' - if (nth === 2) return 'ail'; + if (nth === 2) return 'ail' - if (nth === 3 || nth === 4) return 'ydd'; + if (nth === 3 || nth === 4) return 'ydd' - if (nth === 5 || nth === 6) return 'ed'; + if (nth === 5 || nth === 6) return 'ed' - if ( - (nth >= 7 && nth <= 10) - || nth === 12 - || nth === 15 - || nth === 18 - || nth === 20 - ) { return 'fed'; } + if ((nth >= 7 && nth <= 10) || nth === 12 || nth === 15 || nth === 18 || nth === 20) { + return 'fed' + } - if ( - nth === 11 - || nth === 13 - || nth === 14 - || nth === 16 - || nth === 17 - || nth === 19 - ) { return 'eg'; } + if (nth === 11 || nth === 13 || nth === 14 || nth === 16 || nth === 17 || nth === 19) { + return 'eg' + } - if (nth >= 21 && nth <= 39) return 'ain'; + if (nth >= 21 && nth <= 39) return 'ain' // Inconclusive. - return ''; + return '' }, time24hr: true, -}; +} -export default Welsh; +export default Welsh diff --git a/src/dates/l10n/da.ts b/src/dates/l10n/da.ts index 6ea8c7b..00f1257 100644 --- a/src/dates/l10n/da.ts +++ b/src/dates/l10n/da.ts @@ -1,35 +1,14 @@ /* Danish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Danish: CustomDateLocale = { weekdays: { shorthand: ['søn', 'man', 'tir', 'ons', 'tors', 'fre', 'lør'], - longhand: [ - 'søndag', - 'mandag', - 'tirsdag', - 'onsdag', - 'torsdag', - 'fredag', - 'lørdag', - ], + longhand: ['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'], }, months: { - shorthand: [ - 'jan', - 'feb', - 'mar', - 'apr', - 'maj', - 'jun', - 'jul', - 'aug', - 'sep', - 'okt', - 'nov', - 'dec', - ], + shorthand: ['jan', 'feb', 'mar', 'apr', 'maj', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'], longhand: [ 'januar', 'februar', @@ -52,6 +31,6 @@ export const Danish: CustomDateLocale = { rangeSeparator: ' til ', weekAbbreviation: 'uge', time24hr: true, -}; +} -export default Danish; +export default Danish diff --git a/src/dates/l10n/de.ts b/src/dates/l10n/de.ts index 0d0574d..82047a6 100644 --- a/src/dates/l10n/de.ts +++ b/src/dates/l10n/de.ts @@ -1,35 +1,14 @@ /* German locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const German: CustomDateLocale = { weekdays: { shorthand: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], - longhand: [ - 'Sonntag', - 'Montag', - 'Dienstag', - 'Mittwoch', - 'Donnerstag', - 'Freitag', - 'Samstag', - ], + longhand: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mär', - 'Apr', - 'Mai', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Dez', - ], + shorthand: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'], longhand: [ 'Januar', 'Februar', @@ -50,6 +29,6 @@ export const German: CustomDateLocale = { weekAbbreviation: 'KW', rangeSeparator: ' bis ', time24hr: true, -}; +} -export default German; +export default German diff --git a/src/dates/l10n/default.ts b/src/dates/l10n/default.ts index 4e96011..f93376c 100644 --- a/src/dates/l10n/default.ts +++ b/src/dates/l10n/default.ts @@ -1,33 +1,12 @@ -import { DateLocale } from '../../types/Dates'; +import { DateLocale } from '../../types/Dates' export const English: DateLocale = { weekdays: { shorthand: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], - longhand: [ - 'Sunday', - 'Monday', - 'Tuesday', - 'Wednesday', - 'Thursday', - 'Friday', - 'Saturday', - ], + longhand: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'May', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Oct', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], longhand: [ 'January', 'February', @@ -46,16 +25,16 @@ export const English: DateLocale = { daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], firstDayOfWeek: 0, ordinal: (nth: number) => { - const s = nth % 100; + const s = nth % 100 switch (s % 10) { case 1: - return 'st'; + return 'st' case 2: - return 'nd'; + return 'nd' case 3: - return 'rd'; + return 'rd' default: - return 'th'; + return 'th' } }, rangeSeparator: ' to ', @@ -68,6 +47,6 @@ export const English: DateLocale = { time24hr: false, timeLabel: 'Time', okLabel: 'Ok', -}; +} -export default English; +export default English diff --git a/src/dates/l10n/eo.ts b/src/dates/l10n/eo.ts index 00b2776..e4fb557 100644 --- a/src/dates/l10n/eo.ts +++ b/src/dates/l10n/eo.ts @@ -1,5 +1,5 @@ /* Esperanto locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Esperanto: CustomDateLocale = { firstDayOfWeek: 1, @@ -9,32 +9,11 @@ export const Esperanto: CustomDateLocale = { weekdays: { shorthand: ['Dim', 'Lun', 'Mar', 'Mer', 'Ĵaŭ', 'Ven', 'Sab'], - longhand: [ - 'dimanĉo', - 'lundo', - 'mardo', - 'merkredo', - 'ĵaŭdo', - 'vendredo', - 'sabato', - ], + longhand: ['dimanĉo', 'lundo', 'mardo', 'merkredo', 'ĵaŭdo', 'vendredo', 'sabato'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Maj', - 'Jun', - 'Jul', - 'Aŭg', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aŭg', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'januaro', 'februaro', @@ -53,6 +32,6 @@ export const Esperanto: CustomDateLocale = { ordinal: () => '-a', time24hr: true, -}; +} -export default Esperanto; +export default Esperanto diff --git a/src/dates/l10n/es.ts b/src/dates/l10n/es.ts index 6d6e4a2..8fdf479 100644 --- a/src/dates/l10n/es.ts +++ b/src/dates/l10n/es.ts @@ -1,35 +1,14 @@ /* Spanish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Spanish: CustomDateLocale = { weekdays: { shorthand: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'], - longhand: [ - 'Domingo', - 'Lunes', - 'Martes', - 'Miércoles', - 'Jueves', - 'Viernes', - 'Sábado', - ], + longhand: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'], }, months: { - shorthand: [ - 'Ene', - 'Feb', - 'Mar', - 'Abr', - 'May', - 'Jun', - 'Jul', - 'Ago', - 'Sep', - 'Oct', - 'Nov', - 'Dic', - ], + shorthand: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], longhand: [ 'Enero', 'Febrero', @@ -53,6 +32,6 @@ export const Spanish: CustomDateLocale = { time24hr: true, timeLabel: 'Hora', okLabel: 'Ok', -}; +} -export default Spanish; +export default Spanish diff --git a/src/dates/l10n/et.ts b/src/dates/l10n/et.ts index 3855407..a54a8b1 100644 --- a/src/dates/l10n/et.ts +++ b/src/dates/l10n/et.ts @@ -1,18 +1,10 @@ /* Estonian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Estonian: CustomDateLocale = { weekdays: { shorthand: ['P', 'E', 'T', 'K', 'N', 'R', 'L'], - longhand: [ - 'Pühapäev', - 'Esmaspäev', - 'Teisipäev', - 'Kolmapäev', - 'Neljapäev', - 'Reede', - 'Laupäev', - ], + longhand: ['Pühapäev', 'Esmaspäev', 'Teisipäev', 'Kolmapäev', 'Neljapäev', 'Reede', 'Laupäev'], }, months: { @@ -49,12 +41,12 @@ export const Estonian: CustomDateLocale = { firstDayOfWeek: 1, ordinal() { - return '.'; + return '.' }, weekAbbreviation: 'Näd', rangeSeparator: ' kuni ', time24hr: true, -}; +} -export default Estonian; +export default Estonian diff --git a/src/dates/l10n/fa.ts b/src/dates/l10n/fa.ts index 2fe9f9e..f48649e 100644 --- a/src/dates/l10n/fa.ts +++ b/src/dates/l10n/fa.ts @@ -1,18 +1,10 @@ /* Farsi (Persian) locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Persian: CustomDateLocale = { weekdays: { shorthand: ['یک', 'دو', 'سه', 'چهار', 'پنج', 'جمعه', 'شنبه'], - longhand: [ - 'یک‌شنبه', - 'دوشنبه', - 'سه‌شنبه', - 'چهارشنبه', - 'پنچ‌شنبه', - 'جمعه', - 'شنبه', - ], + longhand: ['یک‌شنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنچ‌شنبه', 'جمعه', 'شنبه'], }, months: { @@ -47,6 +39,6 @@ export const Persian: CustomDateLocale = { }, firstDayOfWeek: 6, ordinal: () => '', -}; +} -export default Persian; +export default Persian diff --git a/src/dates/l10n/fi.ts b/src/dates/l10n/fi.ts index adc21c4..e7d5bac 100644 --- a/src/dates/l10n/fi.ts +++ b/src/dates/l10n/fi.ts @@ -1,5 +1,5 @@ /* Finnish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Finnish: CustomDateLocale = { firstDayOfWeek: 1, @@ -50,6 +50,6 @@ export const Finnish: CustomDateLocale = { ordinal: () => '.', time24hr: true, -}; +} -export default Finnish; +export default Finnish diff --git a/src/dates/l10n/fo.ts b/src/dates/l10n/fo.ts index 9bd66fa..41cf443 100644 --- a/src/dates/l10n/fo.ts +++ b/src/dates/l10n/fo.ts @@ -1,5 +1,5 @@ /* Faroese locale for flatpickr */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Faroese: CustomDateLocale = { weekdays: { @@ -16,20 +16,7 @@ export const Faroese: CustomDateLocale = { }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Mai', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Des', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Des'], longhand: [ 'Januar', 'Februar', @@ -53,6 +40,6 @@ export const Faroese: CustomDateLocale = { weekAbbreviation: 'vika', yearAriaLabel: 'Ár', time24hr: true, -}; +} -export default Faroese; +export default Faroese diff --git a/src/dates/l10n/fr.ts b/src/dates/l10n/fr.ts index f2bdece..2f60111 100644 --- a/src/dates/l10n/fr.ts +++ b/src/dates/l10n/fr.ts @@ -1,20 +1,12 @@ /* French locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const French: CustomDateLocale = { firstDayOfWeek: 1, weekdays: { shorthand: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'], - longhand: [ - 'dimanche', - 'lundi', - 'mardi', - 'mercredi', - 'jeudi', - 'vendredi', - 'samedi', - ], + longhand: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'], }, months: { @@ -49,13 +41,13 @@ export const French: CustomDateLocale = { }, ordinal: (nth) => { - if (nth > 1) return ''; + if (nth > 1) return '' - return 'er'; + return 'er' }, rangeSeparator: ' au ', weekAbbreviation: 'Sem', time24hr: true, -}; +} -export default French; +export default French diff --git a/src/dates/l10n/ga.ts b/src/dates/l10n/ga.ts index cb473a8..42cdba8 100644 --- a/src/dates/l10n/ga.ts +++ b/src/dates/l10n/ga.ts @@ -1,5 +1,5 @@ /* Gaelic Irish locale for flatpickr */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Irish: CustomDateLocale = { firstDayOfWeek: 1, @@ -18,20 +18,7 @@ export const Irish: CustomDateLocale = { }, months: { - shorthand: [ - 'Ean', - 'Fea', - 'Már', - 'Aib', - 'Bea', - 'Mei', - 'Iúi', - 'Lún', - 'MFo', - 'DFo', - 'Sam', - 'Nol', - ], + shorthand: ['Ean', 'Fea', 'Már', 'Aib', 'Bea', 'Mei', 'Iúi', 'Lún', 'MFo', 'DFo', 'Sam', 'Nol'], longhand: [ 'Eanáir', 'Feabhra', @@ -48,6 +35,6 @@ export const Irish: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Irish; +export default Irish diff --git a/src/dates/l10n/gr.ts b/src/dates/l10n/gr.ts index 576f069..5782938 100644 --- a/src/dates/l10n/gr.ts +++ b/src/dates/l10n/gr.ts @@ -1,35 +1,14 @@ /* Greek locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Greek: CustomDateLocale = { weekdays: { shorthand: ['Κυ', 'Δε', 'Τρ', 'Τε', 'Πέ', 'Πα', 'Σά'], - longhand: [ - 'Κυριακή', - 'Δευτέρα', - 'Τρίτη', - 'Τετάρτη', - 'Πέμπτη', - 'Παρασκευή', - 'Σάββατο', - ], + longhand: ['Κυριακή', 'Δευτέρα', 'Τρίτη', 'Τετάρτη', 'Πέμπτη', 'Παρασκευή', 'Σάββατο'], }, months: { - shorthand: [ - 'Ιαν', - 'Φεβ', - 'Μάρ', - 'Απρ', - 'Μάι', - 'Ιού', - 'Ιού', - 'Αύγ', - 'Σεπ', - 'Οκτ', - 'Νοέ', - 'Δεκ', - ], + shorthand: ['Ιαν', 'Φεβ', 'Μάρ', 'Απρ', 'Μάι', 'Ιού', 'Ιού', 'Αύγ', 'Σεπ', 'Οκτ', 'Νοέ', 'Δεκ'], longhand: [ 'Ιανουάριος', 'Φεβρουάριος', @@ -49,13 +28,13 @@ export const Greek: CustomDateLocale = { firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, weekAbbreviation: 'Εβδ', rangeSeparator: ' έως ', amPM: ['ΠΜ', 'ΜΜ'], -}; +} -export default Greek; +export default Greek diff --git a/src/dates/l10n/he.ts b/src/dates/l10n/he.ts index a688f68..4285a03 100644 --- a/src/dates/l10n/he.ts +++ b/src/dates/l10n/he.ts @@ -1,5 +1,5 @@ /* Hebrew locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Hebrew: CustomDateLocale = { weekdays: { @@ -39,6 +39,6 @@ export const Hebrew: CustomDateLocale = { }, rangeSeparator: ' אל ', time24hr: true, -}; +} -export default Hebrew; +export default Hebrew diff --git a/src/dates/l10n/hi.ts b/src/dates/l10n/hi.ts index 4205815..20e68f8 100644 --- a/src/dates/l10n/hi.ts +++ b/src/dates/l10n/hi.ts @@ -1,18 +1,10 @@ /* Hindi locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Hindi: CustomDateLocale = { weekdays: { shorthand: ['रवि', 'सोम', 'मंगल', 'बुध', 'गुरु', 'शुक्र', 'शनि'], - longhand: [ - 'रविवार', - 'सोमवार', - 'मंगलवार', - 'बुधवार', - 'गुरुवार', - 'शुक्रवार', - 'शनिवार', - ], + longhand: ['रविवार', 'सोमवार', 'मंगलवार', 'बुधवार', 'गुरुवार', 'शुक्रवार', 'शनिवार'], }, months: { @@ -45,6 +37,6 @@ export const Hindi: CustomDateLocale = { 'दिसम्बर', ], }, -}; +} -export default Hindi; +export default Hindi diff --git a/src/dates/l10n/hr.ts b/src/dates/l10n/hr.ts index ed00519..761ed14 100644 --- a/src/dates/l10n/hr.ts +++ b/src/dates/l10n/hr.ts @@ -1,20 +1,12 @@ /* Croatian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Croatian: CustomDateLocale = { firstDayOfWeek: 1, weekdays: { shorthand: ['Ned', 'Pon', 'Uto', 'Sri', 'Čet', 'Pet', 'Sub'], - longhand: [ - 'Nedjelja', - 'Ponedjeljak', - 'Utorak', - 'Srijeda', - 'Četvrtak', - 'Petak', - 'Subota', - ], + longhand: ['Nedjelja', 'Ponedjeljak', 'Utorak', 'Srijeda', 'Četvrtak', 'Petak', 'Subota'], }, months: { @@ -48,6 +40,6 @@ export const Croatian: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Croatian; +export default Croatian diff --git a/src/dates/l10n/hu.ts b/src/dates/l10n/hu.ts index c92bdc8..0eb28f1 100644 --- a/src/dates/l10n/hu.ts +++ b/src/dates/l10n/hu.ts @@ -1,20 +1,12 @@ /* Hungarian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Hungarian: CustomDateLocale = { firstDayOfWeek: 1, weekdays: { shorthand: ['V', 'H', 'K', 'Sz', 'Cs', 'P', 'Szo'], - longhand: [ - 'Vasárnap', - 'Hétfő', - 'Kedd', - 'Szerda', - 'Csütörtök', - 'Péntek', - 'Szombat', - ], + longhand: ['Vasárnap', 'Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat'], }, months: { @@ -49,12 +41,12 @@ export const Hungarian: CustomDateLocale = { }, ordinal() { - return '.'; + return '.' }, weekAbbreviation: 'Hét', rangeSeparator: ' - ', time24hr: true, -}; +} -export default Hungarian; +export default Hungarian diff --git a/src/dates/l10n/id.ts b/src/dates/l10n/id.ts index e8ec8f5..907b095 100644 --- a/src/dates/l10n/id.ts +++ b/src/dates/l10n/id.ts @@ -1,5 +1,5 @@ /* Indonesian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Indonesian: CustomDateLocale = { weekdays: { @@ -8,20 +8,7 @@ export const Indonesian: CustomDateLocale = { }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Mei', - 'Jun', - 'Jul', - 'Agu', - 'Sep', - 'Okt', - 'Nov', - 'Des', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'], longhand: [ 'Januari', 'Februari', @@ -43,6 +30,6 @@ export const Indonesian: CustomDateLocale = { ordinal: () => '', time24hr: true, rangeSeparator: ' - ', -}; +} -export default Indonesian; +export default Indonesian diff --git a/src/dates/l10n/index.ts b/src/dates/l10n/index.ts index 3aadf28..d9225ca 100644 --- a/src/dates/l10n/index.ts +++ b/src/dates/l10n/index.ts @@ -1,66 +1,66 @@ /* eslint-disable camelcase */ -import { DateLocaleName, CustomDateLocale } from '../../types/Dates'; +import { DateLocaleName, CustomDateLocale } from '../../types/Dates' -import { Arabic as ar } from './ar'; -import { Austria as at } from './at'; -import { Azerbaijan as az } from './az'; -import { Belarusian as be } from './be'; -import { Bosnian as bs } from './bs'; -import { Bulgarian as bg } from './bg'; -import { Bangla as bn } from './bn'; -import { Catalan as cat } from './cat'; -import { Czech as cs } from './cs'; -import { Welsh as cy } from './cy'; -import { Danish as da } from './da'; -import { German as de } from './de'; -import { English as en } from './default'; -import { Esperanto as eo } from './eo'; -import { Spanish as es } from './es'; -import { Estonian as et } from './et'; -import { Persian as fa } from './fa'; -import { Finnish as fi } from './fi'; -import { Faroese as fo } from './fo'; -import { French as fr } from './fr'; -import { Greek as gr } from './gr'; -import { Hebrew as he } from './he'; -import { Hindi as hi } from './hi'; -import { Croatian as hr } from './hr'; -import { Hungarian as hu } from './hu'; -import { Indonesian as id } from './id'; -import { Icelandic as is } from './is'; -import { Italian as it } from './it'; -import { Japanese as ja } from './ja'; -import { Georgian as ka } from './ka'; -import { Korean as ko } from './ko'; -import { Khmer as km } from './km'; -import { Kazakh as kz } from './kz'; -import { Lithuanian as lt } from './lt'; -import { Latvian as lv } from './lv'; -import { Macedonian as mk } from './mk'; -import { Mongolian as mn } from './mn'; -import { Malaysian as ms } from './ms'; -import { Burmese as my } from './my'; -import { Dutch as nl } from './nl'; -import { Norwegian as no } from './no'; -import { Punjabi as pa } from './pa'; -import { Polish as pl } from './pl'; -import { Portuguese as pt } from './pt'; -import { Romanian as ro } from './ro'; -import { Russian as ru } from './ru'; -import { Sinhala as si } from './si'; -import { Slovak as sk } from './sk'; -import { Slovenian as sl } from './sl'; -import { Albanian as sq } from './sq'; -import { Serbian as sr } from './sr'; -import { Swedish as sv } from './sv'; -import { Thai as th } from './th'; -import { Turkish as tr } from './tr'; -import { Ukrainian as uk } from './uk'; -import { Uzbek as uz } from './uz'; -import { UzbekLatin as uzLatn } from './uz_latn'; -import { Vietnamese as vn } from './vn'; -import { Mandarin as zh } from './zh'; -import { MandarinTraditional as zh_tw } from './zh-tw'; +import { Arabic as ar } from './ar' +import { Austria as at } from './at' +import { Azerbaijan as az } from './az' +import { Belarusian as be } from './be' +import { Bosnian as bs } from './bs' +import { Bulgarian as bg } from './bg' +import { Bangla as bn } from './bn' +import { Catalan as cat } from './cat' +import { Czech as cs } from './cs' +import { Welsh as cy } from './cy' +import { Danish as da } from './da' +import { German as de } from './de' +import { English as en } from './default' +import { Esperanto as eo } from './eo' +import { Spanish as es } from './es' +import { Estonian as et } from './et' +import { Persian as fa } from './fa' +import { Finnish as fi } from './fi' +import { Faroese as fo } from './fo' +import { French as fr } from './fr' +import { Greek as gr } from './gr' +import { Hebrew as he } from './he' +import { Hindi as hi } from './hi' +import { Croatian as hr } from './hr' +import { Hungarian as hu } from './hu' +import { Indonesian as id } from './id' +import { Icelandic as is } from './is' +import { Italian as it } from './it' +import { Japanese as ja } from './ja' +import { Georgian as ka } from './ka' +import { Korean as ko } from './ko' +import { Khmer as km } from './km' +import { Kazakh as kz } from './kz' +import { Lithuanian as lt } from './lt' +import { Latvian as lv } from './lv' +import { Macedonian as mk } from './mk' +import { Mongolian as mn } from './mn' +import { Malaysian as ms } from './ms' +import { Burmese as my } from './my' +import { Dutch as nl } from './nl' +import { Norwegian as no } from './no' +import { Punjabi as pa } from './pa' +import { Polish as pl } from './pl' +import { Portuguese as pt } from './pt' +import { Romanian as ro } from './ro' +import { Russian as ru } from './ru' +import { Sinhala as si } from './si' +import { Slovak as sk } from './sk' +import { Slovenian as sl } from './sl' +import { Albanian as sq } from './sq' +import { Serbian as sr } from './sr' +import { Swedish as sv } from './sv' +import { Thai as th } from './th' +import { Turkish as tr } from './tr' +import { Ukrainian as uk } from './uk' +import { Uzbek as uz } from './uz' +import { UzbekLatin as uzLatn } from './uz_latn' +import { Vietnamese as vn } from './vn' +import { Mandarin as zh } from './zh' +import { MandarinTraditional as zh_tw } from './zh-tw' const l10n: Record = { ar, @@ -125,6 +125,6 @@ const l10n: Record = { zh_tw, uz, uz_latn: uzLatn, -}; +} -export default l10n; +export default l10n diff --git a/src/dates/l10n/is.ts b/src/dates/l10n/is.ts index 9c0eb33..6ab5de7 100644 --- a/src/dates/l10n/is.ts +++ b/src/dates/l10n/is.ts @@ -1,5 +1,5 @@ /* Icelandic locale for flatpickr */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Icelandic: CustomDateLocale = { weekdays: { @@ -16,20 +16,7 @@ export const Icelandic: CustomDateLocale = { }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Maí', - 'Jún', - 'Júl', - 'Ágú', - 'Sep', - 'Okt', - 'Nóv', - 'Des', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Maí', 'Jún', 'Júl', 'Ágú', 'Sep', 'Okt', 'Nóv', 'Des'], longhand: [ 'Janúar', 'Febrúar', @@ -53,6 +40,6 @@ export const Icelandic: CustomDateLocale = { weekAbbreviation: 'vika', yearAriaLabel: 'Ár', time24hr: true, -}; +} -export default Icelandic; +export default Icelandic diff --git a/src/dates/l10n/it.ts b/src/dates/l10n/it.ts index 74ac227..188e446 100644 --- a/src/dates/l10n/it.ts +++ b/src/dates/l10n/it.ts @@ -1,35 +1,14 @@ /* Italian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Italian: CustomDateLocale = { weekdays: { shorthand: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'], - longhand: [ - 'Domenica', - 'Lunedì', - 'Martedì', - 'Mercoledì', - 'Giovedì', - 'Venerdì', - 'Sabato', - ], + longhand: ['Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'], }, months: { - shorthand: [ - 'Gen', - 'Feb', - 'Mar', - 'Apr', - 'Mag', - 'Giu', - 'Lug', - 'Ago', - 'Set', - 'Ott', - 'Nov', - 'Dic', - ], + shorthand: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'], longhand: [ 'Gennaio', 'Febbraio', @@ -50,6 +29,6 @@ export const Italian: CustomDateLocale = { rangeSeparator: ' al ', weekAbbreviation: 'Se', time24hr: true, -}; +} -export default Italian; +export default Italian diff --git a/src/dates/l10n/ja.ts b/src/dates/l10n/ja.ts index 7016b63..94f302f 100644 --- a/src/dates/l10n/ja.ts +++ b/src/dates/l10n/ja.ts @@ -1,18 +1,10 @@ /* Japanese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Japanese: CustomDateLocale = { weekdays: { shorthand: ['日', '月', '火', '水', '木', '金', '土'], - longhand: [ - '日曜日', - '月曜日', - '火曜日', - '水曜日', - '木曜日', - '金曜日', - '土曜日', - ], + longhand: ['日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日'], }, months: { @@ -48,6 +40,6 @@ export const Japanese: CustomDateLocale = { time24hr: true, rangeSeparator: ' から ', firstDayOfWeek: 1, -}; +} -export default Japanese; +export default Japanese diff --git a/src/dates/l10n/ka.ts b/src/dates/l10n/ka.ts index 97f8bed..ab52067 100644 --- a/src/dates/l10n/ka.ts +++ b/src/dates/l10n/ka.ts @@ -1,34 +1,13 @@ /* Georgian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Georgian: CustomDateLocale = { weekdays: { shorthand: ['კვ', 'ორ', 'სა', 'ოთ', 'ხუ', 'პა', 'შა'], - longhand: [ - 'კვირა', - 'ორშაბათი', - 'სამშაბათი', - 'ოთხშაბათი', - 'ხუთშაბათი', - 'პარასკევი', - 'შაბათი', - ], + longhand: ['კვირა', 'ორშაბათი', 'სამშაბათი', 'ოთხშაბათი', 'ხუთშაბათი', 'პარასკევი', 'შაბათი'], }, months: { - shorthand: [ - 'იან', - 'თებ', - 'მარ', - 'აპრ', - 'მაი', - 'ივნ', - 'ივლ', - 'აგვ', - 'სექ', - 'ოქტ', - 'ნოე', - 'დეკ', - ], + shorthand: ['იან', 'თებ', 'მარ', 'აპრ', 'მაი', 'ივნ', 'ივლ', 'აგვ', 'სექ', 'ოქტ', 'ნოე', 'დეკ'], longhand: [ 'იანვარი', 'თებერვალი', @@ -46,13 +25,13 @@ export const Georgian: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, rangeSeparator: ' — ', weekAbbreviation: 'კვ.', amPM: ['AM', 'PM'], yearAriaLabel: 'წელი', time24hr: true, -}; +} -export default Georgian; +export default Georgian diff --git a/src/dates/l10n/km.ts b/src/dates/l10n/km.ts index 864e341..ffe5571 100644 --- a/src/dates/l10n/km.ts +++ b/src/dates/l10n/km.ts @@ -1,18 +1,10 @@ /* Khmer locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Khmer: CustomDateLocale = { weekdays: { shorthand: ['អាទិត្យ', 'ចន្ទ', 'អង្គារ', 'ពុធ', 'ព្រហស.', 'សុក្រ', 'សៅរ៍'], - longhand: [ - 'អាទិត្យ', - 'ចន្ទ', - 'អង្គារ', - 'ពុធ', - 'ព្រហស្បតិ៍', - 'សុក្រ', - 'សៅរ៍', - ], + longhand: ['អាទិត្យ', 'ចន្ទ', 'អង្គារ', 'ពុធ', 'ព្រហស្បតិ៍', 'សុក្រ', 'សៅរ៍'], }, months: { shorthand: [ @@ -50,6 +42,6 @@ export const Khmer: CustomDateLocale = { weekAbbreviation: 'សប្តាហ៍', yearAriaLabel: 'ឆ្នាំ', time24hr: true, -}; +} -export default Khmer; +export default Khmer diff --git a/src/dates/l10n/ko.ts b/src/dates/l10n/ko.ts index df72717..31802b6 100644 --- a/src/dates/l10n/ko.ts +++ b/src/dates/l10n/ko.ts @@ -1,18 +1,10 @@ /* Republic of Korea locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Korean: CustomDateLocale = { weekdays: { shorthand: ['일', '월', '화', '수', '목', '금', '토'], - longhand: [ - '일요일', - '월요일', - '화요일', - '수요일', - '목요일', - '금요일', - '토요일', - ], + longhand: ['일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일'], }, months: { @@ -49,6 +41,6 @@ export const Korean: CustomDateLocale = { ordinal: () => '일', rangeSeparator: ' ~ ', -}; +} -export default Korean; +export default Korean diff --git a/src/dates/l10n/kz.ts b/src/dates/l10n/kz.ts index cf0fff0..e28d6e1 100644 --- a/src/dates/l10n/kz.ts +++ b/src/dates/l10n/kz.ts @@ -1,34 +1,13 @@ /* Kazakh locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Kazakh: CustomDateLocale = { weekdays: { shorthand: ['Жс', 'Дс', 'Сc', 'Ср', 'Бс', 'Жм', 'Сб'], - longhand: [ - 'Жексенбi', - 'Дүйсенбi', - 'Сейсенбi', - 'Сәрсенбi', - 'Бейсенбi', - 'Жұма', - 'Сенбi', - ], + longhand: ['Жексенбi', 'Дүйсенбi', 'Сейсенбi', 'Сәрсенбi', 'Бейсенбi', 'Жұма', 'Сенбi'], }, months: { - shorthand: [ - 'Қаң', - 'Ақп', - 'Нау', - 'Сәу', - 'Мам', - 'Мау', - 'Шiл', - 'Там', - 'Қыр', - 'Қаз', - 'Қар', - 'Жел', - ], + shorthand: ['Қаң', 'Ақп', 'Нау', 'Сәу', 'Мам', 'Мау', 'Шiл', 'Там', 'Қыр', 'Қаз', 'Қар', 'Жел'], longhand: [ 'Қаңтар', 'Ақпан', @@ -46,12 +25,12 @@ export const Kazakh: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, rangeSeparator: ' — ', weekAbbreviation: 'Апта', amPM: ['ТД', 'ТК'], yearAriaLabel: 'Жыл', -}; +} -export default Kazakh; +export default Kazakh diff --git a/src/dates/l10n/lt.ts b/src/dates/l10n/lt.ts index 9966c30..48f7676 100644 --- a/src/dates/l10n/lt.ts +++ b/src/dates/l10n/lt.ts @@ -1,5 +1,5 @@ /* Lithuanian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Lithuanian: CustomDateLocale = { weekdays: { @@ -16,20 +16,7 @@ export const Lithuanian: CustomDateLocale = { }, months: { - shorthand: [ - 'Sau', - 'Vas', - 'Kov', - 'Bal', - 'Geg', - 'Bir', - 'Lie', - 'Rgp', - 'Rgs', - 'Spl', - 'Lap', - 'Grd', - ], + shorthand: ['Sau', 'Vas', 'Kov', 'Bal', 'Geg', 'Bir', 'Lie', 'Rgp', 'Rgs', 'Spl', 'Lap', 'Grd'], longhand: [ 'Sausis', 'Vasaris', @@ -49,11 +36,11 @@ export const Lithuanian: CustomDateLocale = { firstDayOfWeek: 1, ordinal() { - return '-a'; + return '-a' }, rangeSeparator: ' iki ', weekAbbreviation: 'Sav', time24hr: true, -}; +} -export default Lithuanian; +export default Lithuanian diff --git a/src/dates/l10n/lv.ts b/src/dates/l10n/lv.ts index 2105e06..ebf43b0 100644 --- a/src/dates/l10n/lv.ts +++ b/src/dates/l10n/lv.ts @@ -1,5 +1,5 @@ /* Latvian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Latvian: CustomDateLocale = { firstDayOfWeek: 1, @@ -18,20 +18,7 @@ export const Latvian: CustomDateLocale = { }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Mai', - 'Jūn', - 'Jūl', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jūn', 'Jūl', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'Janvāris', 'Februāris', @@ -50,6 +37,6 @@ export const Latvian: CustomDateLocale = { rangeSeparator: ' līdz ', time24hr: true, -}; +} -export default Latvian; +export default Latvian diff --git a/src/dates/l10n/mk.ts b/src/dates/l10n/mk.ts index 3b618b5..ea0af61 100644 --- a/src/dates/l10n/mk.ts +++ b/src/dates/l10n/mk.ts @@ -1,35 +1,14 @@ /* Macedonian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Macedonian: CustomDateLocale = { weekdays: { shorthand: ['Не', 'По', 'Вт', 'Ср', 'Че', 'Пе', 'Са'], - longhand: [ - 'Недела', - 'Понеделник', - 'Вторник', - 'Среда', - 'Четврток', - 'Петок', - 'Сабота', - ], + longhand: ['Недела', 'Понеделник', 'Вторник', 'Среда', 'Четврток', 'Петок', 'Сабота'], }, months: { - shorthand: [ - 'Јан', - 'Фев', - 'Мар', - 'Апр', - 'Мај', - 'Јун', - 'Јул', - 'Авг', - 'Сеп', - 'Окт', - 'Ное', - 'Дек', - ], + shorthand: ['Јан', 'Фев', 'Мар', 'Апр', 'Мај', 'Јун', 'Јул', 'Авг', 'Сеп', 'Окт', 'Ное', 'Дек'], longhand: [ 'Јануари', 'Февруари', @@ -50,6 +29,6 @@ export const Macedonian: CustomDateLocale = { weekAbbreviation: 'Нед.', rangeSeparator: ' до ', time24hr: true, -}; +} -export default Macedonian; +export default Macedonian diff --git a/src/dates/l10n/mn.ts b/src/dates/l10n/mn.ts index aae503f..bfbfbdc 100644 --- a/src/dates/l10n/mn.ts +++ b/src/dates/l10n/mn.ts @@ -1,5 +1,5 @@ /* Mongolian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Mongolian: CustomDateLocale = { firstDayOfWeek: 1, @@ -40,6 +40,6 @@ export const Mongolian: CustomDateLocale = { }, rangeSeparator: '-с ', time24hr: true, -}; +} -export default Mongolian; +export default Mongolian diff --git a/src/dates/l10n/ms.ts b/src/dates/l10n/ms.ts index 1b446e5..c4ef692 100644 --- a/src/dates/l10n/ms.ts +++ b/src/dates/l10n/ms.ts @@ -1,35 +1,14 @@ /* Malaysian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Malaysian: CustomDateLocale = { weekdays: { shorthand: ['Min', 'Isn', 'Sel', 'Rab', 'Kha', 'Jum', 'Sab'], - longhand: [ - 'Minggu', - 'Isnin', - 'Selasa', - 'Rabu', - 'Khamis', - 'Jumaat', - 'Sabtu', - ], + longhand: ['Minggu', 'Isnin', 'Selasa', 'Rabu', 'Khamis', 'Jumaat', 'Sabtu'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mac', - 'Apr', - 'Mei', - 'Jun', - 'Jul', - 'Ogo', - 'Sep', - 'Okt', - 'Nov', - 'Dis', - ], + shorthand: ['Jan', 'Feb', 'Mac', 'Apr', 'Mei', 'Jun', 'Jul', 'Ogo', 'Sep', 'Okt', 'Nov', 'Dis'], longhand: [ 'Januari', 'Februari', @@ -49,6 +28,6 @@ export const Malaysian: CustomDateLocale = { firstDayOfWeek: 1, ordinal: () => '', -}; +} -export default Malaysian; +export default Malaysian diff --git a/src/dates/l10n/my.ts b/src/dates/l10n/my.ts index 294bada..9c6d537 100644 --- a/src/dates/l10n/my.ts +++ b/src/dates/l10n/my.ts @@ -1,18 +1,10 @@ /* Burmese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Burmese: CustomDateLocale = { weekdays: { shorthand: ['နွေ', 'လာ', 'ဂါ', 'ဟူး', 'ကြာ', 'သော', 'နေ'], - longhand: [ - 'တနင်္ဂနွေ', - 'တနင်္လာ', - 'အင်္ဂါ', - 'ဗုဒ္ဓဟူး', - 'ကြာသပတေး', - 'သောကြာ', - 'စနေ', - ], + longhand: ['တနင်္ဂနွေ', 'တနင်္လာ', 'အင်္ဂါ', 'ဗုဒ္ဓဟူး', 'ကြာသပတေး', 'သောကြာ', 'စနေ'], }, months: { @@ -50,6 +42,6 @@ export const Burmese: CustomDateLocale = { ordinal: () => '', time24hr: true, -}; +} -export default Burmese; +export default Burmese diff --git a/src/dates/l10n/nl.ts b/src/dates/l10n/nl.ts index 9c56fc6..f28494c 100644 --- a/src/dates/l10n/nl.ts +++ b/src/dates/l10n/nl.ts @@ -1,18 +1,10 @@ /* Dutch locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Dutch: CustomDateLocale = { weekdays: { shorthand: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'], - longhand: [ - 'zondag', - 'maandag', - 'dinsdag', - 'woensdag', - 'donderdag', - 'vrijdag', - 'zaterdag', - ], + longhand: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'], }, months: { @@ -52,10 +44,10 @@ export const Dutch: CustomDateLocale = { time24hr: true, ordinal: (nth) => { - if (nth === 1 || nth === 8 || nth >= 20) return 'ste'; + if (nth === 1 || nth === 8 || nth >= 20) return 'ste' - return 'de'; + return 'de' }, -}; +} -export default Dutch; +export default Dutch diff --git a/src/dates/l10n/no.ts b/src/dates/l10n/no.ts index e223fc9..636f735 100644 --- a/src/dates/l10n/no.ts +++ b/src/dates/l10n/no.ts @@ -1,35 +1,14 @@ /* Norwegian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Norwegian: CustomDateLocale = { weekdays: { shorthand: ['Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'], - longhand: [ - 'Søndag', - 'Mandag', - 'Tirsdag', - 'Onsdag', - 'Torsdag', - 'Fredag', - 'Lørdag', - ], + longhand: ['Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Mai', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Des', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Des'], longhand: [ 'Januar', 'Februar', @@ -52,6 +31,6 @@ export const Norwegian: CustomDateLocale = { time24hr: true, ordinal: () => '.', -}; +} -export default Norwegian; +export default Norwegian diff --git a/src/dates/l10n/pa.ts b/src/dates/l10n/pa.ts index 93a3915..0d70014 100644 --- a/src/dates/l10n/pa.ts +++ b/src/dates/l10n/pa.ts @@ -1,35 +1,14 @@ /* Punjabi locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Punjabi: CustomDateLocale = { weekdays: { shorthand: ['ਐਤ', 'ਸੋਮ', 'ਮੰਗਲ', 'ਬੁੱਧ', 'ਵੀਰ', 'ਸ਼ੁੱਕਰ', 'ਸ਼ਨਿੱਚਰ'], - longhand: [ - 'ਐਤਵਾਰ', - 'ਸੋਮਵਾਰ', - 'ਮੰਗਲਵਾਰ', - 'ਬੁੱਧਵਾਰ', - 'ਵੀਰਵਾਰ', - 'ਸ਼ੁੱਕਰਵਾਰ', - 'ਸ਼ਨਿੱਚਰਵਾਰ', - ], + longhand: ['ਐਤਵਾਰ', 'ਸੋਮਵਾਰ', 'ਮੰਗਲਵਾਰ', 'ਬੁੱਧਵਾਰ', 'ਵੀਰਵਾਰ', 'ਸ਼ੁੱਕਰਵਾਰ', 'ਸ਼ਨਿੱਚਰਵਾਰ'], }, months: { - shorthand: [ - 'ਜਨ', - 'ਫ਼ਰ', - 'ਮਾਰ', - 'ਅਪ੍ਰੈ', - 'ਮਈ', - 'ਜੂਨ', - 'ਜੁਲਾ', - 'ਅਗ', - 'ਸਤੰ', - 'ਅਕ', - 'ਨਵੰ', - 'ਦਸੰ', - ], + shorthand: ['ਜਨ', 'ਫ਼ਰ', 'ਮਾਰ', 'ਅਪ੍ਰੈ', 'ਮਈ', 'ਜੂਨ', 'ਜੁਲਾ', 'ਅਗ', 'ਸਤੰ', 'ਅਕ', 'ਨਵੰ', 'ਦਸੰ'], longhand: [ 'ਜਨਵਰੀ', 'ਫ਼ਰਵਰੀ', @@ -46,6 +25,6 @@ export const Punjabi: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Punjabi; +export default Punjabi diff --git a/src/dates/l10n/pl.ts b/src/dates/l10n/pl.ts index 25b2b46..15c4bad 100644 --- a/src/dates/l10n/pl.ts +++ b/src/dates/l10n/pl.ts @@ -1,35 +1,14 @@ /* Polish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Polish: CustomDateLocale = { weekdays: { shorthand: ['Nd', 'Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'So'], - longhand: [ - 'Niedziela', - 'Poniedziałek', - 'Wtorek', - 'Środa', - 'Czwartek', - 'Piątek', - 'Sobota', - ], + longhand: ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'], }, months: { - shorthand: [ - 'Sty', - 'Lut', - 'Mar', - 'Kwi', - 'Maj', - 'Cze', - 'Lip', - 'Sie', - 'Wrz', - 'Paź', - 'Lis', - 'Gru', - ], + shorthand: ['Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'], longhand: [ 'Styczeń', 'Luty', @@ -51,6 +30,6 @@ export const Polish: CustomDateLocale = { time24hr: true, ordinal: () => '.', -}; +} -export default Polish; +export default Polish diff --git a/src/dates/l10n/pt.ts b/src/dates/l10n/pt.ts index 9222630..0e302b3 100644 --- a/src/dates/l10n/pt.ts +++ b/src/dates/l10n/pt.ts @@ -1,5 +1,5 @@ /* Portuguese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Portuguese: CustomDateLocale = { weekdays: { @@ -16,20 +16,7 @@ export const Portuguese: CustomDateLocale = { }, months: { - shorthand: [ - 'Jan', - 'Fev', - 'Mar', - 'Abr', - 'Mai', - 'Jun', - 'Jul', - 'Ago', - 'Set', - 'Out', - 'Nov', - 'Dez', - ], + shorthand: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'], longhand: [ 'Janeiro', 'Fevereiro', @@ -48,6 +35,6 @@ export const Portuguese: CustomDateLocale = { rangeSeparator: ' até ', time24hr: true, -}; +} -export default Portuguese; +export default Portuguese diff --git a/src/dates/l10n/ro.ts b/src/dates/l10n/ro.ts index 7cc4eaf..57881fa 100644 --- a/src/dates/l10n/ro.ts +++ b/src/dates/l10n/ro.ts @@ -1,35 +1,14 @@ /* Romanian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Romanian: CustomDateLocale = { weekdays: { shorthand: ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sâm'], - longhand: [ - 'Duminică', - 'Luni', - 'Marți', - 'Miercuri', - 'Joi', - 'Vineri', - 'Sâmbătă', - ], + longhand: ['Duminică', 'Luni', 'Marți', 'Miercuri', 'Joi', 'Vineri', 'Sâmbătă'], }, months: { - shorthand: [ - 'Ian', - 'Feb', - 'Mar', - 'Apr', - 'Mai', - 'Iun', - 'Iul', - 'Aug', - 'Sep', - 'Oct', - 'Noi', - 'Dec', - ], + shorthand: ['Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun', 'Iul', 'Aug', 'Sep', 'Oct', 'Noi', 'Dec'], longhand: [ 'Ianuarie', 'Februarie', @@ -50,6 +29,6 @@ export const Romanian: CustomDateLocale = { time24hr: true, ordinal: () => '', -}; +} -export default Romanian; +export default Romanian diff --git a/src/dates/l10n/ru.ts b/src/dates/l10n/ru.ts index 316acfa..079df50 100644 --- a/src/dates/l10n/ru.ts +++ b/src/dates/l10n/ru.ts @@ -1,18 +1,10 @@ /* Russian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Russian: CustomDateLocale = { weekdays: { shorthand: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'], - longhand: [ - 'Воскресенье', - 'Понедельник', - 'Вторник', - 'Среда', - 'Четверг', - 'Пятница', - 'Суббота', - ], + longhand: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'], }, months: { shorthand: [ @@ -46,13 +38,13 @@ export const Russian: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, rangeSeparator: ' — ', weekAbbreviation: 'Нед.', amPM: ['ДП', 'ПП'], yearAriaLabel: 'Год', time24hr: true, -}; +} -export default Russian; +export default Russian diff --git a/src/dates/l10n/si.ts b/src/dates/l10n/si.ts index aebf7e9..2aa6aea 100644 --- a/src/dates/l10n/si.ts +++ b/src/dates/l10n/si.ts @@ -1,18 +1,10 @@ /* Sinhala locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Sinhala: CustomDateLocale = { weekdays: { shorthand: ['ඉ', 'ස', 'අ', 'බ', 'බ්‍ර', 'සි', 'සෙ'], - longhand: [ - 'ඉරිදා', - 'සඳුදා', - 'අඟහරුවාදා', - 'බදාදා', - 'බ්‍රහස්පතින්දා', - 'සිකුරාදා', - 'සෙනසුරාදා', - ], + longhand: ['ඉරිදා', 'සඳුදා', 'අඟහරුවාදා', 'බදාදා', 'බ්‍රහස්පතින්දා', 'සිකුරාදා', 'සෙනසුරාදා'], }, months: { @@ -46,6 +38,6 @@ export const Sinhala: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Sinhala; +export default Sinhala diff --git a/src/dates/l10n/sk.ts b/src/dates/l10n/sk.ts index a7924cc..564915a 100644 --- a/src/dates/l10n/sk.ts +++ b/src/dates/l10n/sk.ts @@ -1,35 +1,14 @@ /* Slovak locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Slovak: CustomDateLocale = { weekdays: { shorthand: ['Ned', 'Pon', 'Ut', 'Str', 'Štv', 'Pia', 'Sob'], - longhand: [ - 'Nedeľa', - 'Pondelok', - 'Utorok', - 'Streda', - 'Štvrtok', - 'Piatok', - 'Sobota', - ], + longhand: ['Nedeľa', 'Pondelok', 'Utorok', 'Streda', 'Štvrtok', 'Piatok', 'Sobota'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Máj', - 'Jún', - 'Júl', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Máj', 'Jún', 'Júl', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'Január', 'Február', @@ -50,8 +29,8 @@ export const Slovak: CustomDateLocale = { rangeSeparator: ' do ', time24hr: true, ordinal() { - return '.'; + return '.' }, -}; +} -export default Slovak; +export default Slovak diff --git a/src/dates/l10n/sl.ts b/src/dates/l10n/sl.ts index 6dbc792..4167ce8 100644 --- a/src/dates/l10n/sl.ts +++ b/src/dates/l10n/sl.ts @@ -1,35 +1,14 @@ /* Slovenian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Slovenian: CustomDateLocale = { weekdays: { shorthand: ['Ned', 'Pon', 'Tor', 'Sre', 'Čet', 'Pet', 'Sob'], - longhand: [ - 'Nedelja', - 'Ponedeljek', - 'Torek', - 'Sreda', - 'Četrtek', - 'Petek', - 'Sobota', - ], + longhand: ['Nedelja', 'Ponedeljek', 'Torek', 'Sreda', 'Četrtek', 'Petek', 'Sobota'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Maj', - 'Jun', - 'Jul', - 'Avg', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Avg', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'Januar', 'Februar', @@ -50,8 +29,8 @@ export const Slovenian: CustomDateLocale = { rangeSeparator: ' do ', time24hr: true, ordinal() { - return '.'; + return '.' }, -}; +} -export default Slovenian; +export default Slovenian diff --git a/src/dates/l10n/sq.ts b/src/dates/l10n/sq.ts index 865ae4c..260875b 100644 --- a/src/dates/l10n/sq.ts +++ b/src/dates/l10n/sq.ts @@ -1,35 +1,14 @@ /* Albanian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Albanian: CustomDateLocale = { weekdays: { shorthand: ['Di', 'Hë', 'Ma', 'Më', 'En', 'Pr', 'Sh'], - longhand: [ - 'E Diel', - 'E Hënë', - 'E Martë', - 'E Mërkurë', - 'E Enjte', - 'E Premte', - 'E Shtunë', - ], + longhand: ['E Diel', 'E Hënë', 'E Martë', 'E Mërkurë', 'E Enjte', 'E Premte', 'E Shtunë'], }, months: { - shorthand: [ - 'Jan', - 'Shk', - 'Mar', - 'Pri', - 'Maj', - 'Qer', - 'Kor', - 'Gus', - 'Sht', - 'Tet', - 'Nën', - 'Dhj', - ], + shorthand: ['Jan', 'Shk', 'Mar', 'Pri', 'Maj', 'Qer', 'Kor', 'Gus', 'Sht', 'Tet', 'Nën', 'Dhj'], longhand: [ 'Janar', 'Shkurt', @@ -46,6 +25,6 @@ export const Albanian: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Albanian; +export default Albanian diff --git a/src/dates/l10n/sr-cyr.ts b/src/dates/l10n/sr-cyr.ts index ced236c..c87bea7 100644 --- a/src/dates/l10n/sr-cyr.ts +++ b/src/dates/l10n/sr-cyr.ts @@ -1,35 +1,14 @@ /* Serbian Cyrillic locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const SerbianCyrillic: CustomDateLocale = { weekdays: { shorthand: ['Нед', 'Пон', 'Уто', 'Сре', 'Чет', 'Пет', 'Суб'], - longhand: [ - 'Недеља', - 'Понедељак', - 'Уторак', - 'Среда', - 'Четвртак', - 'Петак', - 'Субота', - ], + longhand: ['Недеља', 'Понедељак', 'Уторак', 'Среда', 'Четвртак', 'Петак', 'Субота'], }, months: { - shorthand: [ - 'Јан', - 'Феб', - 'Мар', - 'Апр', - 'Мај', - 'Јун', - 'Јул', - 'Авг', - 'Сеп', - 'Окт', - 'Нов', - 'Дец', - ], + shorthand: ['Јан', 'Феб', 'Мар', 'Апр', 'Мај', 'Јун', 'Јул', 'Авг', 'Сеп', 'Окт', 'Нов', 'Дец'], longhand: [ 'Јануар', 'Фебруар', @@ -49,6 +28,6 @@ export const SerbianCyrillic: CustomDateLocale = { firstDayOfWeek: 1, weekAbbreviation: 'Нед.', rangeSeparator: ' до ', -}; +} -export default SerbianCyrillic; +export default SerbianCyrillic diff --git a/src/dates/l10n/sr.ts b/src/dates/l10n/sr.ts index 11a758b..1af23e7 100644 --- a/src/dates/l10n/sr.ts +++ b/src/dates/l10n/sr.ts @@ -1,35 +1,14 @@ /* Serbian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Serbian: CustomDateLocale = { weekdays: { shorthand: ['Ned', 'Pon', 'Uto', 'Sre', 'Čet', 'Pet', 'Sub'], - longhand: [ - 'Nedelja', - 'Ponedeljak', - 'Utorak', - 'Sreda', - 'Četvrtak', - 'Petak', - 'Subota', - ], + longhand: ['Nedelja', 'Ponedeljak', 'Utorak', 'Sreda', 'Četvrtak', 'Petak', 'Subota'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Maj', - 'Jun', - 'Jul', - 'Avg', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Avg', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'Januar', 'Februar', @@ -50,6 +29,6 @@ export const Serbian: CustomDateLocale = { weekAbbreviation: 'Ned.', rangeSeparator: ' do ', time24hr: true, -}; +} -export default Serbian; +export default Serbian diff --git a/src/dates/l10n/sv.ts b/src/dates/l10n/sv.ts index 8704298..5ad1b3b 100644 --- a/src/dates/l10n/sv.ts +++ b/src/dates/l10n/sv.ts @@ -1,5 +1,5 @@ /* Swedish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Swedish: CustomDateLocale = { firstDayOfWeek: 1, @@ -7,32 +7,11 @@ export const Swedish: CustomDateLocale = { weekdays: { shorthand: ['Sön', 'Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör'], - longhand: [ - 'Söndag', - 'Måndag', - 'Tisdag', - 'Onsdag', - 'Torsdag', - 'Fredag', - 'Lördag', - ], + longhand: ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'], }, months: { - shorthand: [ - 'Jan', - 'Feb', - 'Mar', - 'Apr', - 'Maj', - 'Jun', - 'Jul', - 'Aug', - 'Sep', - 'Okt', - 'Nov', - 'Dec', - ], + shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'], longhand: [ 'Januari', 'Februari', @@ -51,6 +30,6 @@ export const Swedish: CustomDateLocale = { time24hr: true, ordinal: () => '.', -}; +} -export default Swedish; +export default Swedish diff --git a/src/dates/l10n/th.ts b/src/dates/l10n/th.ts index 5e56140..54f7383 100644 --- a/src/dates/l10n/th.ts +++ b/src/dates/l10n/th.ts @@ -1,18 +1,10 @@ /* Thai locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Thai: CustomDateLocale = { weekdays: { shorthand: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'], - longhand: [ - 'อาทิตย์', - 'จันทร์', - 'อังคาร', - 'พุธ', - 'พฤหัสบดี', - 'ศุกร์', - 'เสาร์', - ], + longhand: ['อาทิตย์', 'จันทร์', 'อังคาร', 'พุธ', 'พฤหัสบดี', 'ศุกร์', 'เสาร์'], }, months: { @@ -51,6 +43,6 @@ export const Thai: CustomDateLocale = { time24hr: true, ordinal: () => '', -}; +} -export default Thai; +export default Thai diff --git a/src/dates/l10n/tr.ts b/src/dates/l10n/tr.ts index 2ca728b..831fa46 100644 --- a/src/dates/l10n/tr.ts +++ b/src/dates/l10n/tr.ts @@ -1,35 +1,14 @@ /* Turkish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Turkish: CustomDateLocale = { weekdays: { shorthand: ['Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cmt'], - longhand: [ - 'Pazar', - 'Pazartesi', - 'Salı', - 'Çarşamba', - 'Perşembe', - 'Cuma', - 'Cumartesi', - ], + longhand: ['Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi'], }, months: { - shorthand: [ - 'Oca', - 'Şub', - 'Mar', - 'Nis', - 'May', - 'Haz', - 'Tem', - 'Ağu', - 'Eyl', - 'Eki', - 'Kas', - 'Ara', - ], + shorthand: ['Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Eki', 'Kas', 'Ara'], longhand: [ 'Ocak', 'Şubat', @@ -51,6 +30,6 @@ export const Turkish: CustomDateLocale = { weekAbbreviation: 'Hf', amPM: ['ÖÖ', 'ÖS'], time24hr: true, -}; +} -export default Turkish; +export default Turkish diff --git a/src/dates/l10n/uk.ts b/src/dates/l10n/uk.ts index 3a68364..bda1883 100644 --- a/src/dates/l10n/uk.ts +++ b/src/dates/l10n/uk.ts @@ -1,37 +1,16 @@ /* Ukrainian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Ukrainian: CustomDateLocale = { firstDayOfWeek: 1, weekdays: { shorthand: ['Нд', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'], - longhand: [ - 'Неділя', - 'Понеділок', - 'Вівторок', - 'Середа', - 'Четвер', - "П'ятниця", - 'Субота', - ], + longhand: ['Неділя', 'Понеділок', 'Вівторок', 'Середа', 'Четвер', "П'ятниця", 'Субота'], }, months: { - shorthand: [ - 'Січ', - 'Лют', - 'Бер', - 'Кві', - 'Тра', - 'Чер', - 'Лип', - 'Сер', - 'Вер', - 'Жов', - 'Лис', - 'Гру', - ], + shorthand: ['Січ', 'Лют', 'Бер', 'Кві', 'Тра', 'Чер', 'Лип', 'Сер', 'Вер', 'Жов', 'Лис', 'Гру'], longhand: [ 'Січень', 'Лютий', @@ -48,6 +27,6 @@ export const Ukrainian: CustomDateLocale = { ], }, time24hr: true, -}; +} -export default Ukrainian; +export default Ukrainian diff --git a/src/dates/l10n/uz.ts b/src/dates/l10n/uz.ts index 4555eb1..af8393c 100644 --- a/src/dates/l10n/uz.ts +++ b/src/dates/l10n/uz.ts @@ -1,34 +1,13 @@ /* Uzbek locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Uzbek: CustomDateLocale = { weekdays: { shorthand: ['Якш', 'Душ', 'Сеш', 'Чор', 'Пай', 'Жум', 'Шан'], - longhand: [ - 'Якшанба', - 'Душанба', - 'Сешанба', - 'Чоршанба', - 'Пайшанба', - 'Жума', - 'Шанба', - ], + longhand: ['Якшанба', 'Душанба', 'Сешанба', 'Чоршанба', 'Пайшанба', 'Жума', 'Шанба'], }, months: { - shorthand: [ - 'Янв', - 'Фев', - 'Мар', - 'Апр', - 'Май', - 'Июн', - 'Июл', - 'Авг', - 'Сен', - 'Окт', - 'Ноя', - 'Дек', - ], + shorthand: ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'], longhand: [ 'Январ', 'Феврал', @@ -46,13 +25,13 @@ export const Uzbek: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, rangeSeparator: ' — ', weekAbbreviation: 'Ҳафта', amPM: ['AM', 'PM'], yearAriaLabel: 'Йил', time24hr: true, -}; +} -export default Uzbek; +export default Uzbek diff --git a/src/dates/l10n/uz_latn.ts b/src/dates/l10n/uz_latn.ts index 5da40a2..e7b8c66 100644 --- a/src/dates/l10n/uz_latn.ts +++ b/src/dates/l10n/uz_latn.ts @@ -1,18 +1,10 @@ /* Uzbek locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const UzbekLatin: CustomDateLocale = { weekdays: { shorthand: ['Ya', 'Du', 'Se', 'Cho', 'Pa', 'Ju', 'Sha'], - longhand: [ - 'Yakshanba', - 'Dushanba', - 'Seshanba', - 'Chorshanba', - 'Payshanba', - 'Juma', - 'Shanba', - ], + longhand: ['Yakshanba', 'Dushanba', 'Seshanba', 'Chorshanba', 'Payshanba', 'Juma', 'Shanba'], }, months: { shorthand: [ @@ -46,13 +38,13 @@ export const UzbekLatin: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return ''; + return '' }, rangeSeparator: ' — ', weekAbbreviation: 'Hafta', amPM: ['AM', 'PM'], yearAriaLabel: 'Yil', time24hr: true, -}; +} -export default UzbekLatin; +export default UzbekLatin diff --git a/src/dates/l10n/vn.ts b/src/dates/l10n/vn.ts index 843ac27..f455cdb 100644 --- a/src/dates/l10n/vn.ts +++ b/src/dates/l10n/vn.ts @@ -1,18 +1,10 @@ /* Vietnamese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Vietnamese: CustomDateLocale = { weekdays: { shorthand: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'], - longhand: [ - 'Chủ nhật', - 'Thứ hai', - 'Thứ ba', - 'Thứ tư', - 'Thứ năm', - 'Thứ sáu', - 'Thứ bảy', - ], + longhand: ['Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm', 'Thứ sáu', 'Thứ bảy'], }, months: { @@ -48,6 +40,6 @@ export const Vietnamese: CustomDateLocale = { firstDayOfWeek: 1, rangeSeparator: ' đến ', -}; +} -export default Vietnamese; +export default Vietnamese diff --git a/src/dates/l10n/zh-tw.ts b/src/dates/l10n/zh-tw.ts index 3a1d85d..3153fa2 100644 --- a/src/dates/l10n/zh-tw.ts +++ b/src/dates/l10n/zh-tw.ts @@ -1,18 +1,10 @@ /* Mandarin locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const MandarinTraditional: CustomDateLocale = { weekdays: { shorthand: ['週日', '週一', '週二', '週三', '週四', '週五', '週六'], - longhand: [ - '星期日', - '星期一', - '星期二', - '星期三', - '星期四', - '星期五', - '星期六', - ], + longhand: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'], }, months: { shorthand: [ @@ -46,6 +38,6 @@ export const MandarinTraditional: CustomDateLocale = { }, rangeSeparator: ' 至 ', weekAbbreviation: '週', -}; +} -export default MandarinTraditional; +export default MandarinTraditional diff --git a/src/dates/l10n/zh.ts b/src/dates/l10n/zh.ts index 119860f..31c5b5f 100644 --- a/src/dates/l10n/zh.ts +++ b/src/dates/l10n/zh.ts @@ -1,18 +1,10 @@ /* Mandarin locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates'; +import { CustomDateLocale } from '../../types/Dates' export const Mandarin: CustomDateLocale = { weekdays: { shorthand: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], - longhand: [ - '星期日', - '星期一', - '星期二', - '星期三', - '星期四', - '星期五', - '星期六', - ], + longhand: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'], }, months: { @@ -48,6 +40,6 @@ export const Mandarin: CustomDateLocale = { rangeSeparator: ' 至 ', weekAbbreviation: '周', -}; +} -export default Mandarin; +export default Mandarin diff --git a/src/dates/parseDate.ts b/src/dates/parseDate.ts index 525a1b8..d8cba19 100644 --- a/src/dates/parseDate.ts +++ b/src/dates/parseDate.ts @@ -1,89 +1,85 @@ -import clone from '../helpers/clone'; +import clone from '../helpers/clone' import { - DateValue, DateLocale, TokenRegex, TokenParsingFunctions, TokenParsingFunction, DateToken, -} from '../types/Dates'; + DateValue, + DateLocale, + TokenRegex, + TokenParsingFunctions, + TokenParsingFunction, + DateToken, +} from '../types/Dates' -import { English } from './l10n/default'; +import { English } from './l10n/default' -const boolToInt = (bool: boolean) : 1 | 0 => (bool === true ? 1 : 0); +const boolToInt = (bool: boolean): 1 | 0 => (bool === true ? 1 : 0) -const doNothing = (): undefined => undefined; +const doNothing = (): undefined => undefined const tokenParsingFunctions: TokenParsingFunctions = { D: doNothing, F(dateObj: Date, monthName: string, locale: DateLocale) { - dateObj.setMonth(locale.months.longhand.indexOf(monthName)); + dateObj.setMonth(locale.months.longhand.indexOf(monthName)) }, G: (dateObj: Date, hour: string) => { - dateObj.setHours(parseFloat(hour)); + dateObj.setHours(parseFloat(hour)) }, H: (dateObj: Date, hour: string) => { - dateObj.setHours(parseFloat(hour)); + dateObj.setHours(parseFloat(hour)) }, J: (dateObj: Date, day: string) => { - dateObj.setDate(parseFloat(day)); + dateObj.setDate(parseFloat(day)) }, K: (dateObj: Date, amPM: string, locale: DateLocale) => { dateObj.setHours( - (dateObj.getHours() % 12) - + 12 * boolToInt(new RegExp(locale.amPM[1], 'i').test(amPM)), - ); + (dateObj.getHours() % 12) + 12 * boolToInt(new RegExp(locale.amPM[1], 'i').test(amPM)) + ) }, M(dateObj: Date, shortMonth: string, locale: DateLocale) { - dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth)); + dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth)) }, S: (dateObj: Date, seconds: string) => { - dateObj.setSeconds(parseFloat(seconds)); + dateObj.setSeconds(parseFloat(seconds)) }, U: (_: Date, unixSeconds: string) => new Date(parseFloat(unixSeconds) * 1000), W(dateObj: Date, weekNum: string, locale: DateLocale) { - const weekNumber = parseInt(weekNum, 10); - const date = new Date( - dateObj.getFullYear(), - 0, - 2 + (weekNumber - 1) * 7, - 0, - 0, - 0, - 0, - ); - date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek); - - return date; + const weekNumber = parseInt(weekNum, 10) + const date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0) + date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek) + + return date }, Y: (dateObj: Date, year: string) => { - dateObj.setFullYear(parseFloat(year)); + dateObj.setFullYear(parseFloat(year)) }, Z: (_: Date, ISODate: string) => new Date(ISODate), d: (dateObj: Date, day: string) => { - dateObj.setDate(parseFloat(day)); + dateObj.setDate(parseFloat(day)) }, h: (dateObj: Date, hour: string) => { - dateObj.setHours(parseFloat(hour)); + dateObj.setHours(parseFloat(hour)) }, i: (dateObj: Date, minutes: string) => { - dateObj.setMinutes(parseFloat(minutes)); + dateObj.setMinutes(parseFloat(minutes)) }, j: (dateObj: Date, day: string) => { - dateObj.setDate(parseFloat(day)); + dateObj.setDate(parseFloat(day)) }, l: doNothing, m: (dateObj: Date, month: string) => { - dateObj.setMonth(parseFloat(month) - 1); + dateObj.setMonth(parseFloat(month) - 1) }, n: (dateObj: Date, month: string) => { - dateObj.setMonth(parseFloat(month) - 1); + dateObj.setMonth(parseFloat(month) - 1) }, s: (dateObj: Date, seconds: string) => { - dateObj.setSeconds(parseFloat(seconds)); + dateObj.setSeconds(parseFloat(seconds)) }, w: doNothing, y: (dateObj: Date, year: string) => { - dateObj.setFullYear(2000 + parseFloat(year)); + dateObj.setFullYear(2000 + parseFloat(year)) }, -}; +} const tokenRegex: TokenRegex = { // A textual representation of a day (regex matches any word) @@ -117,120 +113,129 @@ const tokenRegex: TokenRegex = { s: '(\\d\\d|\\d)', w: '(\\d\\d|\\d)', y: '(\\d{2})', -}; +} -const isTimestamp = (date: string | number): boolean => typeof date === 'number'; +const isTimestamp = (date: string | number): boolean => typeof date === 'number' -const isGMTString = (date: string): boolean => date.toLowerCase().endsWith('gmt'); +const isGMTString = (date: string): boolean => date.toLowerCase().endsWith('gmt') -const isIsoString = (date: string): boolean => date.toLowerCase().endsWith('z'); +const isIsoString = (date: string): boolean => date.toLowerCase().endsWith('z') -const getIsBackSlash = (char: string | undefined): boolean => char === '\\'; +const getIsBackSlash = (char: string | undefined): boolean => char === '\\' -const getTokenParsingOperationsFromFormat = (date: string, format: string, locale: DateLocale): { fn: TokenParsingFunction; match: string }[] => { +const getTokenParsingOperationsFromFormat = ( + date: string, + format: string, + locale: DateLocale +): { fn: TokenParsingFunction; match: string }[] => { // The regex used for the `K` token is different for English and other languages - const localeTokenRegex = { ...tokenRegex }; + const localeTokenRegex = { ...tokenRegex } // Generates something like `(AM|PM|am|pm)` localeTokenRegex.K = `(${locale.amPM[0]}|${ locale.amPM[1] - }|${locale.amPM[0].toLowerCase()}|${locale.amPM[1].toLowerCase()})`; + }|${locale.amPM[0].toLowerCase()}|${locale.amPM[1].toLowerCase()})` - const operations: { fn: TokenParsingFunction; match: string }[] = []; + const operations: { fn: TokenParsingFunction; match: string }[] = [] - let regexString = ''; - let matchIndex = 0; + let regexString = '' + let matchIndex = 0 format.split('').forEach((token: string | DateToken, tokenIndex: number) => { - const isBackSlash = getIsBackSlash(token); - const isEscaped = getIsBackSlash(format[tokenIndex - 1]) || isBackSlash; - const regex: string | undefined = localeTokenRegex[token as DateToken]; + const isBackSlash = getIsBackSlash(token) + const isEscaped = getIsBackSlash(format[tokenIndex - 1]) || isBackSlash + const regex: string | undefined = localeTokenRegex[token as DateToken] if (!isEscaped && regex) { - regexString += regex; + regexString += regex - const match = new RegExp(regexString).exec(date); + const match = new RegExp(regexString).exec(date) if (match !== null) { - matchIndex += 1; + matchIndex += 1 if (token === 'Y') { // Should run the operation for years first operations.unshift({ fn: tokenParsingFunctions[token], match: match[matchIndex], - }); + }) } else { operations.push({ fn: tokenParsingFunctions[token], match: match[matchIndex], - }); + }) } } } else if (!isBackSlash) { // Meaning any character - regexString += '.'; + regexString += '.' } - }); + }) - return operations; -}; + return operations +} const getToday = (): Date => { - const today = new Date(); - today.setHours(0, 0, 0, 0); - return today; -}; - -const parseDate = (date: DateValue | undefined | null, fromFormat = 'Y-m-d H:i:S', timeless?: boolean, customLocale?: DateLocale): Date | undefined => { + const today = new Date() + today.setHours(0, 0, 0, 0) + return today +} + +const parseDate = ( + date: DateValue | undefined | null, + fromFormat = 'Y-m-d H:i:S', + timeless?: boolean, + customLocale?: DateLocale +): Date | undefined => { if (date !== 0 && !date) { - return undefined; + return undefined } if (date === 'today') { - return getToday(); + return getToday() } - const locale = customLocale || English; + const locale = customLocale || English - let parsedDate: Date | undefined; - const originalDate = date; + let parsedDate: Date | undefined + const originalDate = date if (date instanceof Date) { - parsedDate = clone(date); + parsedDate = clone(date) } else if (isTimestamp(date)) { // New date from timestamp - parsedDate = new Date(date); + parsedDate = new Date(date) } else if (typeof date === 'string') { if (isGMTString(date) || isIsoString(date)) { - parsedDate = new Date(date); + parsedDate = new Date(date) } else { - const operations = getTokenParsingOperationsFromFormat(date, fromFormat, locale); + const operations = getTokenParsingOperationsFromFormat(date, fromFormat, locale) if (operations.length === 0) { - parsedDate = undefined; + parsedDate = undefined } else { - parsedDate = new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0); + parsedDate = new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) operations.forEach((operation) => { - const { fn, match } = operation; - parsedDate = fn(parsedDate as Date, String(match), locale) || parsedDate; - }); + const { fn, match } = operation + parsedDate = fn(parsedDate as Date, String(match), locale) || parsedDate + }) } } } else { - throw new Error(`Invalid date provided: ${originalDate}`); + throw new Error(`Invalid date provided: ${originalDate}`) } // eslint-disable-next-line no-restricted-globals if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) { - throw new Error(`Invalid date provided: ${originalDate}`); + throw new Error(`Invalid date provided: ${originalDate}`) } if (timeless === true) { - parsedDate.setHours(0, 0, 0, 0); + parsedDate.setHours(0, 0, 0, 0) } - return parsedDate; -}; + return parsedDate +} -export default parseDate; +export default parseDate diff --git a/src/dates/visibleDaysInMonthView.ts b/src/dates/visibleDaysInMonthView.ts index c03c3c8..e32f876 100644 --- a/src/dates/visibleDaysInMonthView.ts +++ b/src/dates/visibleDaysInMonthView.ts @@ -1,49 +1,65 @@ -import { WeekDay } from '../types/Dates'; +import { WeekDay } from '../types/Dates' -import getDateInDayNumber from './getDateInDayNumber'; -import getFirstDayOfMonth from './getFirstDayOfMonth'; -import getFirstDayOfNextMonth from './getFirstDayOfNextMonth'; -import getFirstDayOfPrevMonth from './getFirstDayOfPrevMonth'; -import getLastDayOfMonth from './getLastDayOfMonth'; -import getLastDayOfPrevMonth from './getLastDayOfPrevMonth'; +import getDateInDayNumber from './getDateInDayNumber' +import getFirstDayOfMonth from './getFirstDayOfMonth' +import getFirstDayOfNextMonth from './getFirstDayOfNextMonth' +import getFirstDayOfPrevMonth from './getFirstDayOfPrevMonth' +import getLastDayOfMonth from './getLastDayOfMonth' +import getLastDayOfPrevMonth from './getLastDayOfPrevMonth' -const getNextMonthDays = (firstDayOfNextMonth: Date, monthDays: Date[], prevMonthDays: Date[]): Date[] => { - const nextMonthTotalDays = 7 - ((monthDays.length + prevMonthDays.length) % 7); +const getNextMonthDays = ( + firstDayOfNextMonth: Date, + monthDays: Date[], + prevMonthDays: Date[] +): Date[] => { + const nextMonthTotalDays = 7 - ((monthDays.length + prevMonthDays.length) % 7) if (nextMonthTotalDays === 7) { - return []; + return [] } - return Array.from({ length: nextMonthTotalDays }, (_x, i) => i + 1) - .map((day) => getDateInDayNumber(firstDayOfNextMonth, day)); -}; + return Array.from({ length: nextMonthTotalDays }, (_x, i) => i + 1).map((day) => + getDateInDayNumber(firstDayOfNextMonth, day) + ) +} -const getMonthDays = (month: Date, lastDayOfMonth: Date): Date[] => Array - .from({ length: lastDayOfMonth.getDate() }, (_x, i) => i + 1) - .map((day) => getDateInDayNumber(month, day)); +const getMonthDays = (month: Date, lastDayOfMonth: Date): Date[] => + Array.from({ length: lastDayOfMonth.getDate() }, (_x, i) => i + 1).map((day) => + getDateInDayNumber(month, day) + ) -const getPreviousMonthDays = (month: Date, firstDayOfPrevMonth: Date, lastDayOfPrevMonth: Date, weekstart: WeekDay): Date[] => { - let prevMonthTotalDays = getFirstDayOfMonth(month).getDay() - weekstart; +const getPreviousMonthDays = ( + month: Date, + firstDayOfPrevMonth: Date, + lastDayOfPrevMonth: Date, + weekstart: WeekDay +): Date[] => { + let prevMonthTotalDays = getFirstDayOfMonth(month).getDay() - weekstart if (prevMonthTotalDays < 0) { - prevMonthTotalDays = 7 + prevMonthTotalDays; + prevMonthTotalDays = 7 + prevMonthTotalDays } return Array.from({ length: prevMonthTotalDays }, (_x, i) => lastDayOfPrevMonth.getDate() - i) .reverse() - .map((day) => getDateInDayNumber(firstDayOfPrevMonth, day)); -}; + .map((day) => getDateInDayNumber(firstDayOfPrevMonth, day)) +} const visibleDaysInMonthView = (month: Date, weekstart: WeekDay = WeekDay.Sunday): Date[] => { - const firstDayOfPrevMonth = getFirstDayOfPrevMonth(month); - const lastDayOfPrevMonth = getLastDayOfPrevMonth(month); - const lastDayOfMonth = getLastDayOfMonth(month); - const firstDayOfNextMonth = getFirstDayOfNextMonth(month); + const firstDayOfPrevMonth = getFirstDayOfPrevMonth(month) + const lastDayOfPrevMonth = getLastDayOfPrevMonth(month) + const lastDayOfMonth = getLastDayOfMonth(month) + const firstDayOfNextMonth = getFirstDayOfNextMonth(month) - const prevMonthDays = getPreviousMonthDays(month, firstDayOfPrevMonth, lastDayOfPrevMonth, weekstart); - const monthDays = getMonthDays(month, lastDayOfMonth); - const nextMonthDays = getNextMonthDays(firstDayOfNextMonth, monthDays, prevMonthDays); + const prevMonthDays = getPreviousMonthDays( + month, + firstDayOfPrevMonth, + lastDayOfPrevMonth, + weekstart + ) + const monthDays = getMonthDays(month, lastDayOfMonth) + const nextMonthDays = getNextMonthDays(firstDayOfNextMonth, monthDays, prevMonthDays) - return prevMonthDays.concat(monthDays, nextMonthDays); -}; + return prevMonthDays.concat(monthDays, nextMonthDays) +} -export default visibleDaysInMonthView; +export default visibleDaysInMonthView diff --git a/src/filterOptions.ts b/src/filterOptions.ts index 360162c..688bc6b 100644 --- a/src/filterOptions.ts +++ b/src/filterOptions.ts @@ -1,8 +1,8 @@ -import { NormalizedOption, NormalizedOptions } from './types'; +import { NormalizedOption, NormalizedOptions } from './types' const filterOptions = (options: NormalizedOptions, query: string): NormalizedOptions => { if (query === '') { - return options; + return options } return options @@ -13,21 +13,22 @@ const filterOptions = (options: NormalizedOptions, query: string): NormalizedOpt ...{ children: filterOptions(option.children, query), }, - }; - return newOption; + } + return newOption } - return option; - }).filter((option: NormalizedOption): boolean => { + return option + }) + .filter((option: NormalizedOption): boolean => { const foundText = String(option.text) .toUpperCase() .trim() - .includes(query.toUpperCase().trim()); + .includes(query.toUpperCase().trim()) - const hasChildren = option.children && option.children.length > 0; + const hasChildren = option.children && option.children.length > 0 - return hasChildren || foundText; - }); -}; + return hasChildren || foundText + }) +} -export default filterOptions; +export default filterOptions diff --git a/src/flattenOptions.ts b/src/flattenOptions.ts index 959b5a7..bb65e6e 100644 --- a/src/flattenOptions.ts +++ b/src/flattenOptions.ts @@ -1,11 +1,12 @@ -import { NormalizedOption, NormalizedOptions } from './types'; +import { NormalizedOption, NormalizedOptions } from './types' -const flattenOptions = (options: NormalizedOptions): NormalizedOptions => options.flatMap((option: NormalizedOption) => { - if (option.children) { - return flattenOptions(option.children); - } +const flattenOptions = (options: NormalizedOptions): NormalizedOptions => + options.flatMap((option: NormalizedOption) => { + if (option.children) { + return flattenOptions(option.children) + } - return option; -}); + return option + }) -export default flattenOptions; +export default flattenOptions diff --git a/src/helpers/addToArray.ts b/src/helpers/addToArray.ts index 0869b27..2695e78 100644 --- a/src/helpers/addToArray.ts +++ b/src/helpers/addToArray.ts @@ -3,10 +3,10 @@ const addToArray =

>(arr: any, value: any): P => { if (!Array.isArray(arr)) { - return [value] as P; + return [value] as P } - return [...arr, value] as P; -}; + return [...arr, value] as P +} -export default addToArray; +export default addToArray diff --git a/src/helpers/clone.ts b/src/helpers/clone.ts index 7b6ff97..886abc3 100644 --- a/src/helpers/clone.ts +++ b/src/helpers/clone.ts @@ -1,10 +1,10 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any -const clone =

(obj: P): P => { +const clone =

(obj: P): P => { if (obj instanceof Date) { - return new Date(obj.valueOf()) as P; + return new Date(obj.valueOf()) as P } - return JSON.parse(JSON.stringify(obj)); -}; + return JSON.parse(JSON.stringify(obj)) +} -export default clone; +export default clone diff --git a/src/helpers/debounce.ts b/src/helpers/debounce.ts index b26f285..fa1ea8c 100644 --- a/src/helpers/debounce.ts +++ b/src/helpers/debounce.ts @@ -1,33 +1,33 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -type DebounceFn = (...args: any[]) => void; +type DebounceFn = (...args: any[]) => void export type DebouncedFn = { - cancel: () => void, -} & DebounceFn; + cancel: () => void +} & DebounceFn const debounce = (func: (...args: any[]) => void, wait = 200): DebouncedFn => { - let timeout: ReturnType | undefined; + let timeout: ReturnType | undefined const cancel: () => void = () => { if (timeout) { - clearTimeout(timeout); + clearTimeout(timeout) } - }; + } const debounceFn: DebounceFn = (...args: any[]) => { - cancel(); + cancel() timeout = setTimeout(() => { - timeout = undefined; - func(args); - }, wait); + timeout = undefined + func(args) + }, wait) if (!wait) { - func(args); + func(args) } - }; + } - return Object.assign(debounceFn, { cancel }); -}; + return Object.assign(debounceFn, { cancel }) +} -export default debounce; +export default debounce diff --git a/src/helpers/elementIsTargetOrTargetChild.ts b/src/helpers/elementIsTargetOrTargetChild.ts index 784ec09..cc79f16 100644 --- a/src/helpers/elementIsTargetOrTargetChild.ts +++ b/src/helpers/elementIsTargetOrTargetChild.ts @@ -1,9 +1,12 @@ -const elementIsTargetOrTargetChild = (target: EventTarget | null, wrapper: HTMLElement) : boolean => { +const elementIsTargetOrTargetChild = ( + target: EventTarget | null, + wrapper: HTMLElement +): boolean => { if (!(target instanceof Element)) { - return false; + return false } - return wrapper.contains(target); -}; + return wrapper.contains(target) +} -export default elementIsTargetOrTargetChild; +export default elementIsTargetOrTargetChild diff --git a/src/helpers/get.ts b/src/helpers/get.ts index c50b9b5..2da14f1 100644 --- a/src/helpers/get.ts +++ b/src/helpers/get.ts @@ -1,18 +1,22 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -const get = (object: T, path: string | number | symbol, defaultValue?: unknown): K | undefined => { +const get = ( + object: T, + path: string | number | symbol, + defaultValue?: unknown +): K | undefined => { const result = String(path) .replace(/\[/g, '.') .replace(/\]/g, '') .split('.') .reduce((objectSoFar: T | any, step: string) => { if (typeof objectSoFar === 'object' || Array.isArray(objectSoFar)) { - return objectSoFar[step]; + return objectSoFar[step] } - return undefined; - }, object); + return undefined + }, object) - return result === undefined ? defaultValue : result; -}; + return result === undefined ? defaultValue : result +} -export default get; +export default get diff --git a/src/helpers/getFocusableElements.ts b/src/helpers/getFocusableElements.ts index 97bcf73..ca1cf10 100644 --- a/src/helpers/getFocusableElements.ts +++ b/src/helpers/getFocusableElements.ts @@ -1,7 +1,8 @@ -const getFocusableElements = (element: HTMLElement): Array => Array - .from(element.querySelectorAll( - 'a, button, input, textarea, select, details, [contenteditable], [tabindex]:not([tabindex="-1"])', - )) - .filter((el) => !el.hasAttribute('disabled')) as Array; +const getFocusableElements = (element: HTMLElement): Array => + Array.from( + element.querySelectorAll( + 'a, button, input, textarea, select, details, [contenteditable], [tabindex]:not([tabindex="-1"])' + ) + ).filter((el) => !el.hasAttribute('disabled')) as Array -export default getFocusableElements; +export default getFocusableElements diff --git a/src/helpers/hasProperty.ts b/src/helpers/hasProperty.ts index af98060..314fd05 100644 --- a/src/helpers/hasProperty.ts +++ b/src/helpers/hasProperty.ts @@ -1,4 +1,8 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any -const hasProperty = (obj: X | undefined, prop: Y): obj is X & Record => obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, prop); +const hasProperty = ( + obj: X | undefined, + prop: Y +): obj is X & Record => + obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, prop) -export default hasProperty; +export default hasProperty diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 917ee96..cdc7361 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,17 +1,17 @@ -export { default as get } from './get'; -export { default as pick } from './pick'; -export { default as isPrimitive } from './isPrimitive'; -export { default as isEqual } from './isEqual'; -export { default as clone } from './clone'; -export { default as debounce, DebouncedFn } from './debounce'; -export { default as throttle } from './throttle'; -export { default as addToArray } from './addToArray'; -export { default as substractFromArray } from './substractFromArray'; -export { default as elementIsTargetOrTargetChild } from './elementIsTargetOrTargetChild'; -export { default as getFocusableElements } from './getFocusableElements'; -export { default as isTouchOnlyDevice } from './isTouchOnlyDevice'; -export { default as normalizeMeasure } from './normalizeMeasure'; -export { default as normalizedOptionIsDisabled } from './normalizedOptionIsDisabled'; -export { default as hasProperty } from './hasProperty'; -export { default as promisify } from './promisify'; -export { default as promisifyFunctionResult } from './promisifyFunctionResult'; +export { default as get } from './get' +export { default as pick } from './pick' +export { default as isPrimitive } from './isPrimitive' +export { default as isEqual } from './isEqual' +export { default as clone } from './clone' +export { default as debounce, DebouncedFn } from './debounce' +export { default as throttle } from './throttle' +export { default as addToArray } from './addToArray' +export { default as substractFromArray } from './substractFromArray' +export { default as elementIsTargetOrTargetChild } from './elementIsTargetOrTargetChild' +export { default as getFocusableElements } from './getFocusableElements' +export { default as isTouchOnlyDevice } from './isTouchOnlyDevice' +export { default as normalizeMeasure } from './normalizeMeasure' +export { default as normalizedOptionIsDisabled } from './normalizedOptionIsDisabled' +export { default as hasProperty } from './hasProperty' +export { default as promisify } from './promisify' +export { default as promisifyFunctionResult } from './promisifyFunctionResult' diff --git a/src/helpers/isEqual.ts b/src/helpers/isEqual.ts index 38d0418..a48083d 100644 --- a/src/helpers/isEqual.ts +++ b/src/helpers/isEqual.ts @@ -1,3 +1,3 @@ -const isEqual = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b); +const isEqual = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b) -export default isEqual; +export default isEqual diff --git a/src/helpers/isObject.ts b/src/helpers/isObject.ts index 75ff499..1b59736 100644 --- a/src/helpers/isObject.ts +++ b/src/helpers/isObject.ts @@ -1,17 +1,17 @@ const isObject = , U>(value: T | U): value is T => { if (!value) { - return false; + return false } if (typeof value !== 'object') { - return false; + return false } if (Array.isArray(value)) { - return false; + return false } - return true; -}; + return true +} -export default isObject; +export default isObject diff --git a/src/helpers/isPrimitive.ts b/src/helpers/isPrimitive.ts index 5aff5fb..f45a234 100644 --- a/src/helpers/isPrimitive.ts +++ b/src/helpers/isPrimitive.ts @@ -1,9 +1,9 @@ const isPrimitive = (value: unknown): boolean => { if (value === null) { - return true; + return true } - return !['array', 'function', 'object'].includes(typeof value); -}; + return !['array', 'function', 'object'].includes(typeof value) +} -export default isPrimitive; +export default isPrimitive diff --git a/src/helpers/isTouchOnlyDevice.ts b/src/helpers/isTouchOnlyDevice.ts index 8355dbb..4fdecb1 100644 --- a/src/helpers/isTouchOnlyDevice.ts +++ b/src/helpers/isTouchOnlyDevice.ts @@ -1,14 +1,14 @@ const isTouchOnlyDevice = (w?: Window): boolean => { if (w === undefined) { if (window === undefined) { - return false; + return false } // eslint-disable-next-line no-param-reassign - w = window; + w = window } - return !!(w.matchMedia && w.matchMedia('(any-hover: none)').matches); -}; + return !!(w.matchMedia && w.matchMedia('(any-hover: none)').matches) +} -export default isTouchOnlyDevice; +export default isTouchOnlyDevice diff --git a/src/helpers/normalizeMeasure.ts b/src/helpers/normalizeMeasure.ts index 5c67d9d..a93ffdf 100644 --- a/src/helpers/normalizeMeasure.ts +++ b/src/helpers/normalizeMeasure.ts @@ -1,19 +1,19 @@ -import { Measure } from '../types'; +import { Measure } from '../types' const normalizeMeasure = (measure?: Measure | null | undefined): string | undefined => { if (measure === null || measure === undefined) { - return undefined; + return undefined } if (typeof measure === 'number') { - return `${measure}px`; + return `${measure}px` } if (String(Number(measure)) === measure) { - return `${Number(measure)}px`; + return `${Number(measure)}px` } - return measure; -}; + return measure +} -export default normalizeMeasure; +export default normalizeMeasure diff --git a/src/helpers/normalizedOptionIsDisabled.ts b/src/helpers/normalizedOptionIsDisabled.ts index 6be741e..f47a172 100644 --- a/src/helpers/normalizedOptionIsDisabled.ts +++ b/src/helpers/normalizedOptionIsDisabled.ts @@ -1,5 +1,6 @@ -import { NormalizedOption } from '../types'; +import { NormalizedOption } from '../types' -const normalizedOptionIsDisabled = (option: NormalizedOption): boolean => option.disabled === true || option.disabled === 'disabled'; +const normalizedOptionIsDisabled = (option: NormalizedOption): boolean => + option.disabled === true || option.disabled === 'disabled' -export default normalizedOptionIsDisabled; +export default normalizedOptionIsDisabled diff --git a/src/helpers/pick.ts b/src/helpers/pick.ts index 2d07f5f..8d79506 100644 --- a/src/helpers/pick.ts +++ b/src/helpers/pick.ts @@ -1,12 +1,15 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -const pick = (object: T, condition: (value: T[K], key: K) => boolean = (value) => !!value): T => { - const newObject = { ...object }; +const pick = ( + object: T, + condition: (value: T[K], key: K) => boolean = (value) => !!value +): T => { + const newObject = { ...object } Object.keys(object) .filter((key) => !condition(newObject[key as K], key as K)) - .forEach((key) => delete newObject[key as K]); + .forEach((key) => delete newObject[key as K]) - return newObject; -}; + return newObject +} -export default pick; +export default pick diff --git a/src/helpers/promisify.ts b/src/helpers/promisify.ts index 1bc8046..4834c0b 100644 --- a/src/helpers/promisify.ts +++ b/src/helpers/promisify.ts @@ -1,9 +1,9 @@ -const promisify =

(value: Promise

| P) : Promise

=> { +const promisify =

(value: Promise

| P): Promise

=> { if (value instanceof Promise) { - return value; + return value } - return Promise.resolve(value); -}; + return Promise.resolve(value) +} -export default promisify; +export default promisify diff --git a/src/helpers/promisifyFunctionResult.ts b/src/helpers/promisifyFunctionResult.ts index d5af79b..d882cc6 100644 --- a/src/helpers/promisifyFunctionResult.ts +++ b/src/helpers/promisifyFunctionResult.ts @@ -1,10 +1,13 @@ -import promisify from './promisify'; +import promisify from './promisify' /* eslint-disable @typescript-eslint/no-explicit-any */ -const promisifyFunctionResult =

(fn: (...args: P) => K | Promise, ...args: P) : Promise => { - const result = fn(...args); +const promisifyFunctionResult =

( + fn: (...args: P) => K | Promise, + ...args: P +): Promise => { + const result = fn(...args) - return promisify(result); -}; + return promisify(result) +} -export default promisifyFunctionResult; +export default promisifyFunctionResult diff --git a/src/helpers/substractFromArray.ts b/src/helpers/substractFromArray.ts index e1663d6..17e1b72 100644 --- a/src/helpers/substractFromArray.ts +++ b/src/helpers/substractFromArray.ts @@ -1,23 +1,23 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import isEqual from './isEqual'; +import isEqual from './isEqual' const substractFromArray =

(arr: any, value: any): P => { if (!Array.isArray(arr)) { - return [] as any; + return [] as any } - const index = arr.findIndex((valueInOriginal) => isEqual(valueInOriginal, value)); + const index = arr.findIndex((valueInOriginal) => isEqual(valueInOriginal, value)) if (index === -1) { - return arr as P; + return arr as P } - const newArray = [...arr]; + const newArray = [...arr] - newArray.splice(index, 1); + newArray.splice(index, 1) - return newArray as P; -}; + return newArray as P +} -export default substractFromArray; +export default substractFromArray diff --git a/src/helpers/throttle.ts b/src/helpers/throttle.ts index 111f17e..3585b49 100644 --- a/src/helpers/throttle.ts +++ b/src/helpers/throttle.ts @@ -1,16 +1,16 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -const throttle = (func: (...args: any[]) => void, wait = 200): (...args: any[]) => void => { - let isCalled = false; +const throttle = (func: (...args: any[]) => void, wait = 200): ((...args: any[]) => void) => { + let isCalled = false return (...args: any[]) => { if (!isCalled) { - func(...args); - isCalled = true; + func(...args) + isCalled = true setTimeout(() => { - isCalled = false; - }, wait); + isCalled = false + }, wait) } - }; -}; + } +} -export default throttle; +export default throttle diff --git a/src/index.ts b/src/index.ts index e0bca20..fc4a7f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ -export { default as mergeClasses } from './mergeClasses'; -export { default as parseVariant } from './parseVariant'; -export { default as parseVariantWithClassesList } from './parseVariantWithClassesList'; -export { default as normalizeOptions } from './normalizeOptions'; -export { default as flattenOptions } from './flattenOptions'; -export { default as filterOptions } from './filterOptions'; -export * from './config'; -export * from './helpers'; -export * from './dates'; -export * from './types'; +export { default as mergeClasses } from './mergeClasses' +export { default as parseVariant } from './parseVariant' +export { default as parseVariantWithClassesList } from './parseVariantWithClassesList' +export { default as normalizeOptions } from './normalizeOptions' +export { default as flattenOptions } from './flattenOptions' +export { default as filterOptions } from './filterOptions' +export * from './config' +export * from './helpers' +export * from './dates' +export * from './types' diff --git a/src/mergeClasses.ts b/src/mergeClasses.ts index 22776d5..243af06 100644 --- a/src/mergeClasses.ts +++ b/src/mergeClasses.ts @@ -1,53 +1,54 @@ -import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass'; +import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass' -export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => Object.keys(classesObject).filter((className: string) => !!classesObject[className]); +export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => + Object.keys(classesObject).filter((className: string) => !!classesObject[className]) const mergeClasses = (...classes: CSSClasses): string => { - const mergedClasses = new Set(); + const mergedClasses = new Set() // We use a local function to iterate over the classes so we can pass the // currently mergeed classes to functional definitions const merge = (...nestedClasses: CSSClasses) => { nestedClasses.forEach((className) => { if (!className) { - return; + return } if (typeof className === 'boolean') { - return; + return } if (typeof className === 'string' || typeof className === 'undefined') { - mergedClasses.add(`${className || ''}`.replace(/ +/g, ' ').trim()); - return; + mergedClasses.add(`${className || ''}`.replace(/ +/g, ' ').trim()) + return } if (Array.isArray(className)) { - merge(...className); - return; + merge(...className) + return } if (typeof className === 'function') { className({ clear() { - mergedClasses.clear(); + mergedClasses.clear() }, add(cssClass: string) { - merge(...cssClass.split(' ')); + merge(...cssClass.split(' ')) }, remove(cssClass: string) { - mergedClasses.delete(cssClass); + mergedClasses.delete(cssClass) }, - }); - return; + }) + return } - merge(...selectClasses(className)); - }); - }; - merge(...classes); + merge(...selectClasses(className)) + }) + } + merge(...classes) - return Array.from(mergedClasses).join(' '); -}; + return Array.from(mergedClasses).join(' ') +} -export default mergeClasses; +export default mergeClasses diff --git a/src/normalizeOptions.ts b/src/normalizeOptions.ts index 787c60c..5189947 100644 --- a/src/normalizeOptions.ts +++ b/src/normalizeOptions.ts @@ -1,4 +1,4 @@ -import get from './helpers/get'; +import get from './helpers/get' import { InputOptions, @@ -8,96 +8,96 @@ import { InputOptionValue, InputOptionText, InputOptionObject, -} from './types'; +} from './types' const guessOptionValue = (option: InputOptionObject, valueAttribute?: string): InputOptionValue => { if (valueAttribute) { - const value = get(option, valueAttribute); + const value = get(option, valueAttribute) if (value === null) { - return null; + return null } if (typeof value === 'undefined') { - return undefined; + return undefined } if (typeof value === 'number' || typeof value === 'string') { - return value; + return value } - return String(value); + return String(value) } - return option.value; -}; + return option.value +} const guessOptionText = (option: InputOptionObject, textAttribute?: string): InputOptionText => { if (textAttribute) { - const text = get(option, textAttribute); + const text = get(option, textAttribute) if (typeof text === 'undefined' || text === null) { - return ''; + return '' } if (typeof text === 'number' || typeof text === 'string') { - return text; + return text } - return String(text); + return String(text) } - return option.text; -}; + return option.text +} const normalizeOption = ( option: InputOption, textAttribute?: string, - valueAttribute?: string, + valueAttribute?: string ): NormalizedOption => { if (typeof option === 'string' || typeof option === 'number') { return { value: option, text: option, raw: option, - }; + } } const normalizedOption: NormalizedOption = { value: guessOptionValue(option, valueAttribute), text: guessOptionText(option, textAttribute), raw: option, - }; + } if (option.disabled) { - normalizedOption.disabled = true; + normalizedOption.disabled = true } if (option.children) { // eslint-disable-next-line @typescript-eslint/no-use-before-define - normalizedOption.children = normalizeOptions(option.children, textAttribute, valueAttribute); + normalizedOption.children = normalizeOptions(option.children, textAttribute, valueAttribute) } - return normalizedOption; -}; + return normalizedOption +} const normalizeOptions = ( options?: InputOptions, textAttribute?: string, - valueAttribute?: string, + valueAttribute?: string ): NormalizedOptions => { if (Array.isArray(options)) { - return options.map((option) => normalizeOption(option, textAttribute, valueAttribute)); + return options.map((option) => normalizeOption(option, textAttribute, valueAttribute)) } if (typeof options === 'object') { return Object.keys(options).map((optionKey) => ({ value: optionKey, text: options[optionKey], - })); + })) } - return []; -}; + return [] +} -export default normalizeOptions; +export default normalizeOptions diff --git a/src/parseVariant.ts b/src/parseVariant.ts index a939faf..d6519d5 100644 --- a/src/parseVariant.ts +++ b/src/parseVariant.ts @@ -1,46 +1,44 @@ -import { ObjectWithClassName, Variants, WithVariantProps } from './types/Variants'; -import mergeClasses from './mergeClasses'; +import { ObjectWithClassName, Variants, WithVariantProps } from './types/Variants' +import mergeClasses from './mergeClasses' const getCustomPropsFromVariant =

( variants?: Variants

, - variant?: string, + variant?: string ): WithVariantProps

| undefined => { if (variant !== undefined && variants) { - return variants[variant]; + return variants[variant] } - return undefined; -}; + return undefined +} const parseVariant =

( props: WithVariantProps

, globalConfiguration?: WithVariantProps

, - defaultConfiguration?: WithVariantProps

, + defaultConfiguration?: WithVariantProps

): P => { const { variants, variant, ...mainProps } = { ...defaultConfiguration, ...globalConfiguration, ...props, - }; + } - const customProps = getCustomPropsFromVariant(variants, variant); + const customProps = getCustomPropsFromVariant(variants, variant) const mergedProps = { ...mainProps, ...customProps, - }; + } - const { - classes, fixedClasses, class: className, ...componentProps - } = mergedProps; + const { classes, fixedClasses, class: className, ...componentProps } = mergedProps - const mergedClasses: string = mergeClasses(className, classes, fixedClasses); + const mergedClasses: string = mergeClasses(className, classes, fixedClasses) if (mergedClasses) { - (componentProps as P).class = mergedClasses; + ;(componentProps as P).class = mergedClasses } - return componentProps as P; -}; + return componentProps as P +} -export default parseVariant; +export default parseVariant diff --git a/src/parseVariantWithClassesList.ts b/src/parseVariantWithClassesList.ts index 9fe014d..7f38034 100644 --- a/src/parseVariantWithClassesList.ts +++ b/src/parseVariantWithClassesList.ts @@ -3,241 +3,244 @@ import { VariantsWithClassesList, WithVariantPropsAndClassesList, WithVariantProps, -} from './types/Variants'; -import pick from './helpers/pick'; +} from './types/Variants' +import pick from './helpers/pick' -import mergeClasses from './mergeClasses'; -import { CSSClassesList, CSSRawClassesList } from './types'; -import hasProperty from './helpers/hasProperty'; -import isObject from './helpers/isObject'; +import mergeClasses from './mergeClasses' +import { CSSClassesList, CSSRawClassesList } from './types' +import hasProperty from './helpers/hasProperty' +import isObject from './helpers/isObject' const getCustomPropsFromVariant =

( variants?: VariantsWithClassesList, - variant?: string, + variant?: string ): WithVariantPropsAndClassesList | undefined => { if (variant !== undefined && variants) { - return variants[variant]; + return variants[variant] } - return undefined; -}; + return undefined +} const getShouldClearClasses =

( props: WithVariantPropsAndClassesList, key: string, - variant: string | undefined, + variant: string | undefined ): boolean => { if (variant === undefined) { - return hasProperty(props, key) && (props[key] === undefined || props[key] === null); + return hasProperty(props, key) && (props[key] === undefined || props[key] === null) } if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

; + const propsVariant = props.variants[variant] as WithVariantProps

return ( - hasProperty(propsVariant, key) - && (propsVariant[key] === undefined || propsVariant[key] === null) - ); + hasProperty(propsVariant, key) && + (propsVariant[key] === undefined || propsVariant[key] === null) + ) } - return false; -}; + return false +} const parseVariantWithClassesList =

( props: WithVariantPropsAndClassesList, classesListKeys: Readonly>, globalConfiguration?: WithVariantPropsAndClassesList, - defaultConfiguration?: WithVariantPropsAndClassesList, + defaultConfiguration?: WithVariantPropsAndClassesList ): P => { const { variants, variant, ...mainProps } = { ...defaultConfiguration, ...globalConfiguration, ...props, - }; + } - const classes: Partial> = {}; - const fixedClasses: Partial> = {}; + const classes: Partial> = {} + const fixedClasses: Partial> = {} - const clearClasses = getShouldClearClasses(props, 'classes', variant); + const clearClasses = getShouldClearClasses(props, 'classes', variant) - const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant); + const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant) if (clearClasses) { classesListKeys.forEach((classItemKey) => { - classes[classItemKey] = undefined; - }); + classes[classItemKey] = undefined + }) } else { classesListKeys.forEach((classItemKey) => { // Get classes from global configuration or alternatively from library configuration if ( - globalConfiguration - && isObject(globalConfiguration.classes) - && classItemKey in globalConfiguration.classes + globalConfiguration && + isObject(globalConfiguration.classes) && + classItemKey in globalConfiguration.classes ) { - classes[classItemKey] = globalConfiguration.classes[classItemKey]; + classes[classItemKey] = globalConfiguration.classes[classItemKey] } else if ( - defaultConfiguration - && isObject(defaultConfiguration.classes) - && classItemKey in defaultConfiguration.classes + defaultConfiguration && + isObject(defaultConfiguration.classes) && + classItemKey in defaultConfiguration.classes ) { - classes[classItemKey] = defaultConfiguration.classes[classItemKey]; + classes[classItemKey] = defaultConfiguration.classes[classItemKey] } // Get classes from props and merge them with the previous ones if (isObject(props.classes) && classItemKey in props.classes) { if (typeof props.classes[classItemKey] !== 'undefined') { - classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]]; + classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]] } else { - classes[classItemKey] = undefined; + classes[classItemKey] = undefined } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

; + const propsVariant = props.variants[variant] as WithVariantProps

if (isObject(propsVariant.classes) && classItemKey in propsVariant.classes) { - classes[classItemKey] = propsVariant.classes[classItemKey]; + classes[classItemKey] = propsVariant.classes[classItemKey] } } else if ( - globalConfiguration - && isObject(globalConfiguration.variants) - && variant in globalConfiguration.variants + globalConfiguration && + isObject(globalConfiguration.variants) && + variant in globalConfiguration.variants ) { const globalConfigurationVariant = globalConfiguration.variants[ variant - ] as WithVariantProps

; + ] as WithVariantProps

if ( - globalConfigurationVariant.classes - && isObject(globalConfigurationVariant.classes) - && classItemKey in globalConfigurationVariant.classes + globalConfigurationVariant.classes && + isObject(globalConfigurationVariant.classes) && + classItemKey in globalConfigurationVariant.classes ) { - classes[classItemKey] = globalConfigurationVariant.classes[classItemKey]; + classes[classItemKey] = globalConfigurationVariant.classes[classItemKey] } } else if ( - defaultConfiguration !== undefined - && defaultConfiguration.variants !== undefined - && defaultConfiguration.variants[variant] !== undefined + defaultConfiguration !== undefined && + defaultConfiguration.variants !== undefined && + defaultConfiguration.variants[variant] !== undefined ) { const defaultConfigurationVariant = defaultConfiguration.variants[ variant - ] as WithVariantProps

; + ] as WithVariantProps

if ( - defaultConfigurationVariant.classes - && isObject(defaultConfigurationVariant.classes) - && classItemKey in defaultConfigurationVariant.classes + defaultConfigurationVariant.classes && + isObject(defaultConfigurationVariant.classes) && + classItemKey in defaultConfigurationVariant.classes ) { - classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey]; + classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey] } } } - }); + }) } if (clearFixedClasses) { classesListKeys.forEach((classItemKey) => { - fixedClasses[classItemKey] = undefined; - }); + fixedClasses[classItemKey] = undefined + }) } else { classesListKeys.forEach((classItemKey) => { // Get classes from global configuration or alternatively from library configuration if ( - globalConfiguration - && isObject(globalConfiguration.fixedClasses) - && classItemKey in globalConfiguration.fixedClasses + globalConfiguration && + isObject(globalConfiguration.fixedClasses) && + classItemKey in globalConfiguration.fixedClasses ) { - fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey]; + fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey] } else if ( - defaultConfiguration - && isObject(defaultConfiguration.fixedClasses) - && classItemKey in defaultConfiguration.fixedClasses + defaultConfiguration && + isObject(defaultConfiguration.fixedClasses) && + classItemKey in defaultConfiguration.fixedClasses ) { - fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey]; + fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey] } // Get classes from props and merge them with the previous ones if (isObject(props.fixedClasses) && classItemKey in props.fixedClasses) { if (typeof props.fixedClasses[classItemKey] !== 'undefined') { - fixedClasses[classItemKey] = [fixedClasses[classItemKey], props.fixedClasses[classItemKey]]; + fixedClasses[classItemKey] = [ + fixedClasses[classItemKey], + props.fixedClasses[classItemKey], + ] } else { - classes[classItemKey] = undefined; + classes[classItemKey] = undefined } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

; + const propsVariant = props.variants[variant] as WithVariantProps

if (isObject(propsVariant.fixedClasses) && classItemKey in propsVariant.fixedClasses) { - fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey]; + fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey] } } else if ( - globalConfiguration !== undefined - && globalConfiguration.variants !== undefined - && globalConfiguration.variants[variant] !== undefined + globalConfiguration !== undefined && + globalConfiguration.variants !== undefined && + globalConfiguration.variants[variant] !== undefined ) { const globalConfigurationVariant = globalConfiguration.variants[ variant - ] as WithVariantProps

; + ] as WithVariantProps

if ( - isObject(globalConfigurationVariant.fixedClasses) - && classItemKey in globalConfigurationVariant.fixedClasses + isObject(globalConfigurationVariant.fixedClasses) && + classItemKey in globalConfigurationVariant.fixedClasses ) { - fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey]; + fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey] } } else if ( - defaultConfiguration !== undefined - && defaultConfiguration.variants !== undefined - && defaultConfiguration.variants[variant] !== undefined + defaultConfiguration !== undefined && + defaultConfiguration.variants !== undefined && + defaultConfiguration.variants[variant] !== undefined ) { const defaultConfigurationVariant = defaultConfiguration.variants[ variant - ] as WithVariantProps

; + ] as WithVariantProps

if ( - isObject(defaultConfigurationVariant.fixedClasses) - && classItemKey in defaultConfigurationVariant.fixedClasses + isObject(defaultConfigurationVariant.fixedClasses) && + classItemKey in defaultConfigurationVariant.fixedClasses ) { - fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey]; + fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey] } } } - }); + }) } - const customProps = getCustomPropsFromVariant(variants, variant); + const customProps = getCustomPropsFromVariant(variants, variant) const mergedProps = { ...mainProps, ...customProps, - }; + } - delete mergedProps.fixedClasses; + delete mergedProps.fixedClasses - delete mergedProps.classes; + delete mergedProps.classes - const mergedClasses: CSSClassesList = {}; + const mergedClasses: CSSClassesList = {} classesListKeys.forEach((classItemKey) => { - const classesForTheCurrentKey = classes[classItemKey]; - const fixedClassesForTheCurrentKey = fixedClasses[classItemKey]; + const classesForTheCurrentKey = classes[classItemKey] + const fixedClassesForTheCurrentKey = fixedClasses[classItemKey] mergedClasses[classItemKey as string] = mergeClasses( classesForTheCurrentKey, - fixedClassesForTheCurrentKey, - ); - }); + fixedClassesForTheCurrentKey + ) + }) - const result = pick(mergedClasses); + const result = pick(mergedClasses) if (Object.keys(result).length > 0) { - (mergedProps as P).classesList = result; + ;(mergedProps as P).classesList = result } - return mergedProps as P; -}; + return mergedProps as P +} -export default parseVariantWithClassesList; +export default parseVariantWithClassesList diff --git a/src/types/CSSClass.ts b/src/types/CSSClass.ts index 418811f..fc76c8c 100644 --- a/src/types/CSSClass.ts +++ b/src/types/CSSClass.ts @@ -1,8 +1,8 @@ export type CSSClassKeyValuePair = { [key: string]: CSSClass -}; +} -export type CSSClasses = CSSClass[]; +export type CSSClasses = CSSClass[] export type CSSClass = | CSSClassKeyValuePair @@ -12,15 +12,15 @@ export type CSSClass = | null | boolean | ((modifiers: { - clear: () => void - add: (cssClass: string) => void - remove: (cssClass: string) => void - }) => void); + clear: () => void + add: (cssClass: string) => void + remove: (cssClass: string) => void + }) => void) export type CSSRawClassesList = { [key in ClassesKeys]?: CSSClass -}; +} export type CSSClassesList = { [key in ClassesKeys]?: CSSClass -}; +} diff --git a/src/types/Dates.ts b/src/types/Dates.ts index b1652d9..7e24e23 100644 --- a/src/types/Dates.ts +++ b/src/types/Dates.ts @@ -11,13 +11,13 @@ export enum WeekDay { Saturday = 6, } -export type DateValue = Date | string | number; +export type DateValue = Date | string | number export type DateLocale = { weekdays: { - shorthand: [string, string, string, string, string, string, string]; - longhand: [string, string, string, string, string, string, string]; - }; + shorthand: [string, string, string, string, string, string, string] + longhand: [string, string, string, string, string, string, string] + } months: { shorthand: [ string, @@ -31,8 +31,8 @@ export type DateLocale = { string, string, string, - string, - ]; + string + ] longhand: [ string, string, @@ -45,9 +45,9 @@ export type DateLocale = { string, string, string, - string, - ]; - }; + string + ] + } daysInMonth: [ number, number, @@ -60,39 +60,39 @@ export type DateLocale = { number, number, number, - number, - ]; - firstDayOfWeek: number; - ordinal: (nth: number) => string; - rangeSeparator: string; - weekAbbreviation: string; - amPM: [string, string]; - yearAriaLabel: string; - monthAriaLabel: string; - hourAriaLabel: string; - minuteAriaLabel: string; - time24hr: boolean; - timeLabel: string; - okLabel: string; -}; + number + ] + firstDayOfWeek: number + ordinal: (nth: number) => string + rangeSeparator: string + weekAbbreviation: string + amPM: [string, string] + yearAriaLabel: string + monthAriaLabel: string + hourAriaLabel: string + minuteAriaLabel: string + time24hr: boolean + timeLabel: string + okLabel: string +} export type CustomDateLocale = { - ordinal?: DateLocale['ordinal']; - daysInMonth?: DateLocale['daysInMonth']; - firstDayOfWeek?: DateLocale['firstDayOfWeek']; - rangeSeparator?: DateLocale['rangeSeparator']; - weekAbbreviation?: DateLocale['weekAbbreviation']; - yearAriaLabel?: string; - hourAriaLabel?: string; - minuteAriaLabel?: string; - amPM?: DateLocale['amPM']; - time24hr?: DateLocale['time24hr']; - timeLabel?: DateLocale['timeLabel']; - okLabel?: DateLocale['okLabel']; + ordinal?: DateLocale['ordinal'] + daysInMonth?: DateLocale['daysInMonth'] + firstDayOfWeek?: DateLocale['firstDayOfWeek'] + rangeSeparator?: DateLocale['rangeSeparator'] + weekAbbreviation?: DateLocale['weekAbbreviation'] + yearAriaLabel?: string + hourAriaLabel?: string + minuteAriaLabel?: string + amPM?: DateLocale['amPM'] + time24hr?: DateLocale['time24hr'] + timeLabel?: DateLocale['timeLabel'] + okLabel?: DateLocale['okLabel'] weekdays: { - shorthand: [string, string, string, string, string, string, string]; - longhand: [string, string, string, string, string, string, string]; - }; + shorthand: [string, string, string, string, string, string, string] + longhand: [string, string, string, string, string, string, string] + } months: { shorthand: [ string, @@ -106,8 +106,8 @@ export type CustomDateLocale = { string, string, string, - string, - ]; + string + ] longhand: [ string, string, @@ -120,10 +120,10 @@ export type CustomDateLocale = { string, string, string, - string, - ]; - }; -}; + string + ] + } +} export type DateLocaleName = | 'ar' @@ -187,11 +187,11 @@ export type DateLocaleName = | 'zh' | 'uz' | 'uz_latn' - | 'zh_tw'; + | 'zh_tw' export type DateLocales = { [key in DateLocaleName]: DateLocale -}; +} export type DateToken = | 'D' @@ -215,36 +215,36 @@ export type DateToken = | 'n' | 's' | 'w' - | 'y'; + | 'y' export type TokenParsingFunction = ( date: Date, data: string, locale: DateLocale -) => Date | void | undefined; +) => Date | void | undefined -export type TokenParsingFunctions = Record; +export type TokenParsingFunctions = Record -export type TokenRegex = { [k in DateToken]: string }; +export type TokenRegex = { [k in DateToken]: string } export type TokenFormattingFunctions = Record< -DateToken, -(date: Date, locale: DateLocale) => string | number ->; + DateToken, + (date: Date, locale: DateLocale) => string | number +> export type DateParser = ( date: DateValue | null | undefined, givenFormat?: string, timeless?: boolean, - customLocale?: DateLocale, -) => Date | undefined; + customLocale?: DateLocale +) => Date | undefined export type DateFormatter = ( date: Date | null | undefined, format?: string, - overrideLocale?: DateLocale, -) => string; + overrideLocale?: DateLocale +) => string -export type DateCondition = DateValue | ((date: Date) => boolean); +export type DateCondition = DateValue | ((date: Date) => boolean) -export type DateConditions = DateCondition | DateCondition[]; +export type DateConditions = DateCondition | DateCondition[] diff --git a/src/types/InputOptions.ts b/src/types/InputOptions.ts index e74f099..bc870e9 100644 --- a/src/types/InputOptions.ts +++ b/src/types/InputOptions.ts @@ -1,8 +1,8 @@ -export type NormalizedOptions = Array; +export type NormalizedOptions = Array -export type InputOptionValue = string | number | undefined | null; +export type InputOptionValue = string | number | undefined | null -export type InputOptionText = string | number | undefined; +export type InputOptionText = string | number | undefined export type NormalizedOption = { value: InputOptionValue @@ -11,9 +11,9 @@ export type NormalizedOption = { raw?: any children?: NormalizedOptions disabled?: boolean | 'disabled' -}; +} -export type InputOptions = Array | { [key: string]: InputOptionText }; +export type InputOptions = Array | { [key: string]: InputOptionText } export type InputOptionObject = { value?: InputOptionValue @@ -22,6 +22,6 @@ export type InputOptionObject = { children?: InputOptions // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any -}; +} -export type InputOption = InputOptionObject | string | number; +export type InputOption = InputOptionObject | string | number diff --git a/src/types/Misc.ts b/src/types/Misc.ts index 1526cea..a3d68a1 100644 --- a/src/types/Misc.ts +++ b/src/types/Misc.ts @@ -1,6 +1,6 @@ -type Measure = string | number; -type Data = Record; +type Measure = string | number +type Data = Record // eslint-disable-next-line @typescript-eslint/no-explicit-any -type PromiseRejectFn = ((reason?: any) => void); +type PromiseRejectFn = (reason?: any) => void -export { Measure, Data, PromiseRejectFn }; +export { Measure, Data, PromiseRejectFn } diff --git a/src/types/Modify.ts b/src/types/Modify.ts index c009594..e97fc8e 100644 --- a/src/types/Modify.ts +++ b/src/types/Modify.ts @@ -1 +1 @@ -export type Modify = Omit & R; +export type Modify = Omit & R diff --git a/src/types/Variants.ts b/src/types/Variants.ts index 3440294..7a8e4fb 100644 --- a/src/types/Variants.ts +++ b/src/types/Variants.ts @@ -1,4 +1,4 @@ -import { CSSClass, CSSClassesList } from './CSSClass'; +import { CSSClass, CSSClassesList } from './CSSClass' export type WithVariantProps

= { classes?: CSSClass @@ -6,7 +6,7 @@ export type WithVariantProps

= { variants?: Variants

variant?: string class?: string -} & P; +} & P export interface Variants

{ [key: string]: WithVariantProps

| undefined @@ -14,15 +14,15 @@ export interface Variants

{ export type ObjectWithClassName = { class?: string -}; +} export type ObjectWithClassesList = ObjectWithClassName & { classesList?: CSSClassesList -}; +} export type WithVariantPropsAndClassesList = WithVariantProps

& { classesList?: CSSClassesList -}; +} export interface VariantsWithClassesList { [key: string]: WithVariantPropsAndClassesList | undefined } diff --git a/src/types/index.ts b/src/types/index.ts index 72fec1b..6fe22d4 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,6 @@ -export * from './CSSClass'; -export * from './Variants'; -export * from './InputOptions'; -export * from './Modify'; -export * from './Misc'; -export * from './Dates'; +export * from './CSSClass' +export * from './Variants' +export * from './InputOptions' +export * from './Modify' +export * from './Misc' +export * from './Dates' diff --git a/yarn.lock b/yarn.lock index ea31d78..5be4656 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4344,6 +4344,11 @@ prepend-http@^2.0.0: resolved "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz" integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= +prettier@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a" + integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg== + pretty-format@^27.0.0, pretty-format@^27.0.6: version "27.0.6" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.0.6.tgz#ab770c47b2c6f893a21aefc57b75da63ef49a11f" From 09533abaa6da9a88f61e9e2b45462504e3fdbc1f Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Thu, 9 Dec 2021 14:46:07 +0100 Subject: [PATCH 4/5] fix: split classes by space --- src/__tests__/addToArray.test.ts | 20 +- src/__tests__/clone.test.ts | 38 +- src/__tests__/config.test.ts | 12 +- src/__tests__/dateIsPartOfTheRange.test.ts | 94 ++--- src/__tests__/dates/addDays.test.ts | 46 +-- src/__tests__/dates/addMonths.test.ts | 58 +-- src/__tests__/dates/addYears.test.ts | 42 +-- .../dates/buildDateFormatter.test.ts | 26 +- src/__tests__/dates/buildDateParser.test.ts | 26 +- .../dates/dayIsPartOfTheConditions.test.ts | 82 ++--- src/__tests__/dates/formatDate.test.ts | 164 ++++----- .../dates/getDateInDayNumber.test.ts | 20 +- .../dates/getFirstDayOfMonth.test.ts | 26 +- .../dates/getFirstDayOfNextMonth.test.ts | 32 +- .../dates/getFirstDayOfPrevMonth.test.ts | 32 +- src/__tests__/dates/getLastDayOfMonth.test.ts | 44 +-- .../dates/getLastDayOfPrevMonth.test.ts | 32 +- src/__tests__/dates/isSameDay.test.ts | 60 ++-- src/__tests__/dates/isSameMonth.test.ts | 60 ++-- src/__tests__/dates/isToday.test.ts | 26 +- src/__tests__/dates/parseDate.test.ts | 220 ++++++------ .../dates/visibleDaysInMonthView.test.ts | 100 +++--- src/__tests__/debounce.test.ts | 82 ++--- .../elementIsTargetOrTargetChild.test.ts | 50 +-- src/__tests__/filterOptions.test.ts | 20 +- src/__tests__/flattenOptions.test.ts | 28 +- src/__tests__/get.test.ts | 86 ++--- src/__tests__/getFocusableElements.test.ts | 152 ++++---- src/__tests__/hasProperty.test.ts | 36 +- src/__tests__/index.test.ts | 74 ++-- src/__tests__/isEqual.test.ts | 100 +++--- src/__tests__/isPrimitive.test.ts | 40 +-- src/__tests__/isTouchOnlyDevice.test.ts | 30 +- src/__tests__/mergeClasses.test.ts | 43 +-- src/__tests__/normalizeMeasure.test.ts | 36 +- src/__tests__/normalizeOptions.test.ts | 178 +++++----- .../normalizedOptionIsDisabled.test.ts | 30 +- src/__tests__/parseVariant.test.ts | 88 ++--- .../parseVariantWithClassesList.test.ts | 330 +++++++++--------- src/__tests__/pick.test.ts | 22 +- src/__tests__/promisify.test.ts | 28 +- src/__tests__/promisifyFunctionResult.test.ts | 83 +++-- src/__tests__/substractFromArray.test.ts | 28 +- src/__tests__/throttle.test.ts | 52 +-- src/config/TAlertConfig.ts | 10 +- src/config/TButtonConfig.ts | 4 +- src/config/TCardConfig.ts | 8 +- src/config/TCheckboxConfig.ts | 4 +- src/config/TDatepickerConfig.ts | 8 +- src/config/TDialogConfig.ts | 34 +- src/config/TDropdownConfig.ts | 14 +- src/config/TInputConfig.ts | 4 +- src/config/TInputGroupConfig.ts | 8 +- src/config/TModalConfig.ts | 12 +- src/config/TRadioConfig.ts | 4 +- src/config/TRichSelectConfig.ts | 10 +- src/config/TSelectConfig.ts | 4 +- src/config/TTagConfig.ts | 4 +- src/config/TTextareaConfig.ts | 4 +- src/config/TToggleConfig.ts | 8 +- src/config/TWrappedCheckboxConfig.ts | 12 +- src/config/TWrappedRadioConfig.ts | 12 +- src/config/index.ts | 36 +- src/config/transitions.ts | 2 +- src/dates/addDays.ts | 12 +- src/dates/addMonths.ts | 16 +- src/dates/addYears.ts | 16 +- src/dates/buildDateFormatter.ts | 20 +- src/dates/buildDateParser.ts | 20 +- src/dates/dateIsPartOfTheRange.ts | 24 +- src/dates/dayIsPartOfTheConditions.ts | 24 +- src/dates/formatDate.ts | 59 ++-- src/dates/getDateInDayNumber.ts | 5 +- src/dates/getFirstDayOfMonth.ts | 5 +- src/dates/getFirstDayOfNextMonth.ts | 5 +- src/dates/getFirstDayOfPrevMonth.ts | 5 +- src/dates/getLastDayOfMonth.ts | 5 +- src/dates/getLastDayOfPrevMonth.ts | 5 +- src/dates/index.ts | 28 +- src/dates/isSameDay.ts | 14 +- src/dates/isSameMonth.ts | 8 +- src/dates/isToday.ts | 6 +- src/dates/l10n/ar.ts | 6 +- src/dates/l10n/at.ts | 6 +- src/dates/l10n/az.ts | 6 +- src/dates/l10n/be.ts | 8 +- src/dates/l10n/bg.ts | 6 +- src/dates/l10n/bn.ts | 6 +- src/dates/l10n/bs.ts | 6 +- src/dates/l10n/cat.ts | 20 +- src/dates/l10n/cs.ts | 8 +- src/dates/l10n/cy.ts | 22 +- src/dates/l10n/da.ts | 6 +- src/dates/l10n/de.ts | 6 +- src/dates/l10n/default.ts | 16 +- src/dates/l10n/eo.ts | 6 +- src/dates/l10n/es.ts | 6 +- src/dates/l10n/et.ts | 8 +- src/dates/l10n/fa.ts | 6 +- src/dates/l10n/fi.ts | 6 +- src/dates/l10n/fo.ts | 6 +- src/dates/l10n/fr.ts | 10 +- src/dates/l10n/ga.ts | 6 +- src/dates/l10n/gr.ts | 8 +- src/dates/l10n/he.ts | 6 +- src/dates/l10n/hi.ts | 6 +- src/dates/l10n/hr.ts | 6 +- src/dates/l10n/hu.ts | 8 +- src/dates/l10n/id.ts | 6 +- src/dates/l10n/index.ts | 126 +++---- src/dates/l10n/is.ts | 6 +- src/dates/l10n/it.ts | 6 +- src/dates/l10n/ja.ts | 6 +- src/dates/l10n/ka.ts | 8 +- src/dates/l10n/km.ts | 6 +- src/dates/l10n/ko.ts | 6 +- src/dates/l10n/kz.ts | 8 +- src/dates/l10n/lt.ts | 8 +- src/dates/l10n/lv.ts | 6 +- src/dates/l10n/mk.ts | 6 +- src/dates/l10n/mn.ts | 6 +- src/dates/l10n/ms.ts | 6 +- src/dates/l10n/my.ts | 6 +- src/dates/l10n/nl.ts | 10 +- src/dates/l10n/no.ts | 6 +- src/dates/l10n/pa.ts | 6 +- src/dates/l10n/pl.ts | 6 +- src/dates/l10n/pt.ts | 6 +- src/dates/l10n/ro.ts | 6 +- src/dates/l10n/ru.ts | 8 +- src/dates/l10n/si.ts | 6 +- src/dates/l10n/sk.ts | 8 +- src/dates/l10n/sl.ts | 8 +- src/dates/l10n/sq.ts | 6 +- src/dates/l10n/sr-cyr.ts | 6 +- src/dates/l10n/sr.ts | 6 +- src/dates/l10n/sv.ts | 6 +- src/dates/l10n/th.ts | 6 +- src/dates/l10n/tr.ts | 6 +- src/dates/l10n/uk.ts | 6 +- src/dates/l10n/uz.ts | 8 +- src/dates/l10n/uz_latn.ts | 8 +- src/dates/l10n/vn.ts | 6 +- src/dates/l10n/zh-tw.ts | 6 +- src/dates/l10n/zh.ts | 6 +- src/dates/parseDate.ts | 150 ++++---- src/dates/visibleDaysInMonthView.ts | 63 ++-- src/filterOptions.ts | 22 +- src/flattenOptions.ts | 17 +- src/helpers/addToArray.ts | 8 +- src/helpers/clone.ts | 8 +- src/helpers/debounce.ts | 28 +- src/helpers/elementIsTargetOrTargetChild.ts | 10 +- src/helpers/get.ts | 14 +- src/helpers/getFocusableElements.ts | 13 +- src/helpers/hasProperty.ts | 7 +- src/helpers/index.ts | 34 +- src/helpers/isEqual.ts | 4 +- src/helpers/isObject.ts | 12 +- src/helpers/isPrimitive.ts | 8 +- src/helpers/isTouchOnlyDevice.ts | 10 +- src/helpers/normalizeMeasure.ts | 14 +- src/helpers/normalizedOptionIsDisabled.ts | 7 +- src/helpers/pick.ts | 12 +- src/helpers/promisify.ts | 8 +- src/helpers/promisifyFunctionResult.ts | 10 +- src/helpers/substractFromArray.ts | 18 +- src/helpers/throttle.ts | 16 +- src/index.ts | 20 +- src/mergeClasses.ts | 52 +-- src/normalizeOptions.ts | 56 +-- src/parseVariant.ts | 34 +- src/parseVariantWithClassesList.ts | 198 +++++------ src/types/CSSClass.ts | 16 +- src/types/Dates.ts | 42 +-- src/types/InputOptions.ts | 14 +- src/types/Misc.ts | 8 +- src/types/Modify.ts | 2 +- src/types/Variants.ts | 10 +- src/types/index.ts | 12 +- 180 files changed, 2434 insertions(+), 2450 deletions(-) diff --git a/src/__tests__/addToArray.test.ts b/src/__tests__/addToArray.test.ts index f75631c..db87c78 100644 --- a/src/__tests__/addToArray.test.ts +++ b/src/__tests__/addToArray.test.ts @@ -1,22 +1,22 @@ -import addToArray from '../helpers/addToArray' +import addToArray from '../helpers/addToArray'; describe('addToArray', () => { it('adds a new item ', () => { - const arr = [1, 2, 3] - expect(addToArray(arr, 4)).toEqual([1, 2, 3, 4]) - }) + const arr = [1, 2, 3]; + expect(addToArray(arr, 4)).toEqual([1, 2, 3, 4]); + }); it('adds a new item for objects', () => { - const arr = [{ a: 1 }, { b: '2' }, { three: '3' }] + const arr = [{ a: 1 }, { b: '2' }, { three: '3' }]; expect(addToArray(arr, { 'some-thing': { test: 1 } })).toEqual([ { a: 1 }, { b: '2' }, { three: '3' }, { 'some-thing': { test: 1 } }, - ]) - }) + ]); + }); it('returns an array with the item if parameter is not an array', () => { - expect(addToArray(null, 'whatever')).toEqual(['whatever']) - }) -}) + expect(addToArray(null, 'whatever')).toEqual(['whatever']); + }); +}); diff --git a/src/__tests__/clone.test.ts b/src/__tests__/clone.test.ts index 4b30e8d..08f7655 100644 --- a/src/__tests__/clone.test.ts +++ b/src/__tests__/clone.test.ts @@ -1,22 +1,22 @@ -import clone from '../helpers/clone' +import clone from '../helpers/clone'; describe('clone', () => { it('clones an array', () => { - const arr = [1, 2, 3] - expect(clone(arr)).toEqual(arr) - }) + const arr = [1, 2, 3]; + expect(clone(arr)).toEqual(arr); + }); it('clones a date', () => { - const originalDate = new Date(2020, 3, 15, 11, 30, 59) - const date = new Date(2020, 3, 15, 11, 30, 59) - expect(clone(date)).toEqual(originalDate) - expect(date).toEqual(originalDate) - }) + const originalDate = new Date(2020, 3, 15, 11, 30, 59); + const date = new Date(2020, 3, 15, 11, 30, 59); + expect(clone(date)).toEqual(originalDate); + expect(date).toEqual(originalDate); + }); it('clones an array with mixed values', () => { - const arr = [1, '2', null, '', { a: 1 }] - expect(clone(arr)).toEqual(arr) - }) + const arr = [1, '2', null, '', { a: 1 }]; + expect(clone(arr)).toEqual(arr); + }); it('clones an object with mixed values', () => { const obj = { @@ -25,9 +25,9 @@ describe('clone', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - } - expect(clone(obj)).toEqual(obj) - }) + }; + expect(clone(obj)).toEqual(obj); + }); it('makes a deep clone', () => { const obj = [ @@ -43,8 +43,8 @@ describe('clone', () => { null, [], { a: 1, b: 2, c: 3 }, - ] + ]; - expect(clone(obj)).toEqual(obj) - }) -}) + expect(clone(obj)).toEqual(obj); + }); +}); diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index e0feb0d..81d4890 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -1,4 +1,4 @@ -import * as config from '../config/index' +import * as config from '../config/index'; it('exports all the configs and keys', () => { const keys = [ @@ -36,12 +36,12 @@ it('exports all the configs and keys', () => { 'TWrappedRadioClassesKeys', 'TWrappedCheckboxConfig', 'TWrappedCheckboxClassesKeys', - ] + ]; - expect(Object.keys(config)).toEqual(keys) + expect(Object.keys(config)).toEqual(keys); keys.forEach((key) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - expect((config as any)[key]).toBeTruthy() - }) -}) + expect((config as any)[key]).toBeTruthy(); + }); +}); diff --git a/src/__tests__/dateIsPartOfTheRange.test.ts b/src/__tests__/dateIsPartOfTheRange.test.ts index 48d74d1..fce6ada 100644 --- a/src/__tests__/dateIsPartOfTheRange.test.ts +++ b/src/__tests__/dateIsPartOfTheRange.test.ts @@ -1,75 +1,75 @@ -import dateIsPartOfTheRange from '../dates/dateIsPartOfTheRange' +import dateIsPartOfTheRange from '../dates/dateIsPartOfTheRange'; describe('dateIsPartOfTheRange', () => { it('returns true if date is exactly the same date as the min date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0) - const min = new Date(2010, 0, 1, 0, 0, 0, 0) - const max = new Date(2010, 0, 1, 0, 0, 0, 1) + const date = new Date(2010, 0, 1, 0, 0, 0, 0); + const min = new Date(2010, 0, 1, 0, 0, 0, 0); + const max = new Date(2010, 0, 1, 0, 0, 0, 1); - expect(dateIsPartOfTheRange(date, min, max)).toBe(true) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(true); + }); it('returns true if date is exactly the same date as the min date and max date is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0) - const min = new Date(2010, 0, 1, 0, 0, 0, 0) - const max = undefined + const date = new Date(2010, 0, 1, 0, 0, 0, 0); + const min = new Date(2010, 0, 1, 0, 0, 0, 0); + const max = undefined; - expect(dateIsPartOfTheRange(date, min, max)).toBe(true) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(true); + }); it('returns true if date is exactly the max date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1) - const min = new Date(2010, 0, 1, 0, 0, 0, 0) - const max = new Date(2010, 0, 1, 0, 0, 0, 1) + const date = new Date(2010, 0, 1, 0, 0, 0, 1); + const min = new Date(2010, 0, 1, 0, 0, 0, 0); + const max = new Date(2010, 0, 1, 0, 0, 0, 1); - expect(dateIsPartOfTheRange(date, min, max)).toBe(true) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(true); + }); it('returns true if date is exactly the max date and min date is undefined', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1) - const min = undefined - const max = new Date(2010, 0, 1, 0, 0, 0, 1) + const date = new Date(2010, 0, 1, 0, 0, 0, 1); + const min = undefined; + const max = new Date(2010, 0, 1, 0, 0, 0, 1); - expect(dateIsPartOfTheRange(date, min, max)).toBe(true) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(true); + }); it('returns false if date is before the min date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0) - const min = new Date(2010, 0, 1, 0, 0, 0, 1) - const max = new Date(2010, 0, 1, 0, 0, 0, 2) + const date = new Date(2010, 0, 1, 0, 0, 0, 0); + const min = new Date(2010, 0, 1, 0, 0, 0, 1); + const max = new Date(2010, 0, 1, 0, 0, 0, 2); - expect(dateIsPartOfTheRange(date, min, max)).toBe(false) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(false); + }); it('returns false if date is before the min date and max date is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 0) - const min = new Date(2010, 0, 1, 0, 0, 0, 1) - const max = undefined + const date = new Date(2010, 0, 1, 0, 0, 0, 0); + const min = new Date(2010, 0, 1, 0, 0, 0, 1); + const max = undefined; - expect(dateIsPartOfTheRange(date, min, max)).toBe(false) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(false); + }); it('returns false if date is after the max date ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 2) - const min = new Date(2010, 0, 1, 0, 0, 0, 1) - const max = new Date(2010, 0, 1, 0, 0, 0, 1) + const date = new Date(2010, 0, 1, 0, 0, 0, 2); + const min = new Date(2010, 0, 1, 0, 0, 0, 1); + const max = new Date(2010, 0, 1, 0, 0, 0, 1); - expect(dateIsPartOfTheRange(date, min, max)).toBe(false) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(false); + }); it('returns false if date is after the max date and min is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1) - const min = undefined - const max = new Date(2010, 0, 1, 0, 0, 0, 0) + const date = new Date(2010, 0, 1, 0, 0, 0, 1); + const min = undefined; + const max = new Date(2010, 0, 1, 0, 0, 0, 0); - expect(dateIsPartOfTheRange(date, min, max)).toBe(false) - }) + expect(dateIsPartOfTheRange(date, min, max)).toBe(false); + }); it('returns true if max and min is undefined ', async () => { - const date = new Date(2010, 0, 1, 0, 0, 0, 1) - const min = undefined - const max = undefined + const date = new Date(2010, 0, 1, 0, 0, 0, 1); + const min = undefined; + const max = undefined; - expect(dateIsPartOfTheRange(date, min, max)).toBe(true) - }) -}) + expect(dateIsPartOfTheRange(date, min, max)).toBe(true); + }); +}); diff --git a/src/__tests__/dates/addDays.test.ts b/src/__tests__/dates/addDays.test.ts index 6e567e4..41d2861 100644 --- a/src/__tests__/dates/addDays.test.ts +++ b/src/__tests__/dates/addDays.test.ts @@ -1,39 +1,39 @@ -import addDays from '../../dates/addDays' +import addDays from '../../dates/addDays'; describe('addDays', () => { it('adds 1 day by default', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2020, 0, 16) + const date = new Date(2020, 0, 15); + const expected = new Date(2020, 0, 16); - expect(addDays(date)).toEqual(expected) - }) + expect(addDays(date)).toEqual(expected); + }); it('changes the month if last day of month', () => { - const date = new Date(2021, 9, 31) - const expected = new Date(2021, 10, 1) + const date = new Date(2021, 9, 31); + const expected = new Date(2021, 10, 1); - expect(addDays(date)).toEqual(expected) - }) + expect(addDays(date)).toEqual(expected); + }); it('accepts a custom amount of days', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2020, 0, 18) + const date = new Date(2020, 0, 15); + const expected = new Date(2020, 0, 18); - expect(addDays(date, 3)).toEqual(expected) - }) + expect(addDays(date, 3)).toEqual(expected); + }); it('accepts a negative amount of days', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2020, 0, 12) + const date = new Date(2020, 0, 15); + const expected = new Date(2020, 0, 12); - expect(addDays(date, -3)).toEqual(expected) - }) + expect(addDays(date, -3)).toEqual(expected); + }); it('doesnt affect the original date', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2020, 0, 16) + const date = new Date(2020, 0, 15); + const expected = new Date(2020, 0, 16); - expect(addDays(date)).toEqual(expected) - expect(date).toEqual(new Date(2020, 0, 15)) - }) -}) + expect(addDays(date)).toEqual(expected); + expect(date).toEqual(new Date(2020, 0, 15)); + }); +}); diff --git a/src/__tests__/dates/addMonths.test.ts b/src/__tests__/dates/addMonths.test.ts index f157824..a4d30c5 100644 --- a/src/__tests__/dates/addMonths.test.ts +++ b/src/__tests__/dates/addMonths.test.ts @@ -1,51 +1,51 @@ -import addMonths from '../../dates/addMonths' +import addMonths from '../../dates/addMonths'; describe('addMonths', () => { it('adds 1 month by default', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2020, 1, 15) + const date = new Date(2020, 0, 15); + const expected = new Date(2020, 1, 15); - expect(addMonths(date)).toEqual(expected) - }) + expect(addMonths(date)).toEqual(expected); + }); it('changes the year if last month', () => { - const date = new Date(2021, 11, 15) - const expected = new Date(2022, 0, 15) + const date = new Date(2021, 11, 15); + const expected = new Date(2022, 0, 15); - expect(addMonths(date)).toEqual(expected) - }) + expect(addMonths(date)).toEqual(expected); + }); it('uses the last day of next month if doesnt have an equivalent', () => { - const date = new Date(2021, 9, 31) - const expected = new Date(2021, 10, 30) + const date = new Date(2021, 9, 31); + const expected = new Date(2021, 10, 30); - expect(addMonths(date)).toEqual(expected) - }) + expect(addMonths(date)).toEqual(expected); + }); it('uses the last day of next month if doesnt have an equivalent for a month with 28 days', () => { - const date = new Date(2021, 0, 31) - const expected = new Date(2021, 1, 28) + const date = new Date(2021, 0, 31); + const expected = new Date(2021, 1, 28); - expect(addMonths(date)).toEqual(expected) - }) + expect(addMonths(date)).toEqual(expected); + }); it('accepts a custom amount of months', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2020, 3, 15) + const date = new Date(2020, 0, 15); + const expected = new Date(2020, 3, 15); - expect(addMonths(date, 3)).toEqual(expected) - }) + expect(addMonths(date, 3)).toEqual(expected); + }); it('accepts a negative amount of months', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2019, 9, 15) + const date = new Date(2020, 0, 15); + const expected = new Date(2019, 9, 15); - expect(addMonths(date, -3)).toEqual(expected) - }) + expect(addMonths(date, -3)).toEqual(expected); + }); it('doesnt affect the original date', () => { - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(date).toEqual(new Date(2020, 0, 15)) - }) -}) + expect(date).toEqual(new Date(2020, 0, 15)); + }); +}); diff --git a/src/__tests__/dates/addYears.test.ts b/src/__tests__/dates/addYears.test.ts index 9a193e2..37ed012 100644 --- a/src/__tests__/dates/addYears.test.ts +++ b/src/__tests__/dates/addYears.test.ts @@ -1,37 +1,37 @@ -import addYears from '../../dates/addYears' +import addYears from '../../dates/addYears'; describe('addYears', () => { it('adds 1 year by default', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2021, 0, 15) + const date = new Date(2020, 0, 15); + const expected = new Date(2021, 0, 15); - expect(addYears(date)).toEqual(expected) - }) + expect(addYears(date)).toEqual(expected); + }); it('uses the last day of same month if doesnt have an equivalent', () => { - const date = new Date(2024, 1, 29) - const expected = new Date(2025, 1, 28) + const date = new Date(2024, 1, 29); + const expected = new Date(2025, 1, 28); - expect(addYears(date)).toEqual(expected) - }) + expect(addYears(date)).toEqual(expected); + }); it('accepts a custom amount of years', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2023, 0, 15) + const date = new Date(2020, 0, 15); + const expected = new Date(2023, 0, 15); - expect(addYears(date, 3)).toEqual(expected) - }) + expect(addYears(date, 3)).toEqual(expected); + }); it('accepts a negative amount of years', () => { - const date = new Date(2020, 0, 15) - const expected = new Date(2017, 0, 15) + const date = new Date(2020, 0, 15); + const expected = new Date(2017, 0, 15); - expect(addYears(date, -3)).toEqual(expected) - }) + expect(addYears(date, -3)).toEqual(expected); + }); it('doesnt affect the original date', () => { - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(date).toEqual(new Date(2020, 0, 15)) - }) -}) + expect(date).toEqual(new Date(2020, 0, 15)); + }); +}); diff --git a/src/__tests__/dates/buildDateFormatter.test.ts b/src/__tests__/dates/buildDateFormatter.test.ts index d5ae967..f6a596c 100644 --- a/src/__tests__/dates/buildDateFormatter.test.ts +++ b/src/__tests__/dates/buildDateFormatter.test.ts @@ -1,18 +1,18 @@ -import { DateFormatter } from '../../types/Dates' -import buildDateFormatter from '../../dates/buildDateFormatter' -import { English } from '../../dates/l10n/default' +import { DateFormatter } from '../../types/Dates'; +import buildDateFormatter from '../../dates/buildDateFormatter'; +import { English } from '../../dates/l10n/default'; describe('buildDateFormatter', () => { it('it returns the default formatter', () => { - const date = new Date(2021, 1, 3, 4, 5, 6) - const expected = '2021-02-03 04:05:06' - expect(buildDateFormatter(English)(date)).toEqual(expected) - }) + const date = new Date(2021, 1, 3, 4, 5, 6); + const expected = '2021-02-03 04:05:06'; + expect(buildDateFormatter(English)(date)).toEqual(expected); + }); it('it returns the custom formatter', () => { - const date = new Date(2021, 1, 3, 4, 5, 6) - const expected = 'format-like-this' - const customFormatter: DateFormatter = () => expected - expect(buildDateFormatter(English, customFormatter)(date)).toEqual(expected) - }) -}) + const date = new Date(2021, 1, 3, 4, 5, 6); + const expected = 'format-like-this'; + const customFormatter: DateFormatter = () => expected; + expect(buildDateFormatter(English, customFormatter)(date)).toEqual(expected); + }); +}); diff --git a/src/__tests__/dates/buildDateParser.test.ts b/src/__tests__/dates/buildDateParser.test.ts index 3fb1773..708a5c3 100644 --- a/src/__tests__/dates/buildDateParser.test.ts +++ b/src/__tests__/dates/buildDateParser.test.ts @@ -1,18 +1,18 @@ -import { DateParser } from '../../types/Dates' -import buildDateParser from '../../dates/buildDateParser' -import { English } from '../../dates/l10n/default' +import { DateParser } from '../../types/Dates'; +import buildDateParser from '../../dates/buildDateParser'; +import { English } from '../../dates/l10n/default'; describe('buildDateParser', () => { it('it returns the default parser', () => { - const date = '2021-02-03 04:05:06' - const expected = new Date(2021, 1, 3, 4, 5, 6) - expect(buildDateParser(English)(date)).toEqual(expected) - }) + const date = '2021-02-03 04:05:06'; + const expected = new Date(2021, 1, 3, 4, 5, 6); + expect(buildDateParser(English)(date)).toEqual(expected); + }); it('it returns the a custom parser', () => { - const date = '2021-02-03 04:05:06' - const expected = new Date(2021, 1, 3, 4, 5, 6) - const customParser: DateParser = () => expected - expect(buildDateParser(English, customParser)(date)).toEqual(expected) - }) -}) + const date = '2021-02-03 04:05:06'; + const expected = new Date(2021, 1, 3, 4, 5, 6); + const customParser: DateParser = () => expected; + expect(buildDateParser(English, customParser)(date)).toEqual(expected); + }); +}); diff --git a/src/__tests__/dates/dayIsPartOfTheConditions.test.ts b/src/__tests__/dates/dayIsPartOfTheConditions.test.ts index e46c840..5992d1d 100644 --- a/src/__tests__/dates/dayIsPartOfTheConditions.test.ts +++ b/src/__tests__/dates/dayIsPartOfTheConditions.test.ts @@ -1,68 +1,68 @@ -import dayIsPartOfTheConditions from '../../dates/dayIsPartOfTheConditions' -import dateParser from '../../dates/parseDate' +import dayIsPartOfTheConditions from '../../dates/dayIsPartOfTheConditions'; +import dateParser from '../../dates/parseDate'; describe('dayIsPartOfTheConditions', () => { it('returns false for a null values', () => { - const condition = '' - expect(dayIsPartOfTheConditions(null, condition, dateParser)).toBe(false) - }) + const condition = ''; + expect(dayIsPartOfTheConditions(null, condition, dateParser)).toBe(false); + }); it('returns false for undefined value', () => { - const condition = '' - expect(dayIsPartOfTheConditions(undefined, condition, dateParser)).toBe(false) - }) + const condition = ''; + expect(dayIsPartOfTheConditions(undefined, condition, dateParser)).toBe(false); + }); it('accept a custom condition to check the date', () => { - const date = new Date(2019, 1, 1) - const condition = (d: Date) => d.getFullYear() === 2019 - expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(true) - }) + const date = new Date(2019, 1, 1); + const condition = (d: Date) => d.getFullYear() === 2019; + expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(true); + }); it('accept a custom condition to check the date that return false', () => { - const date = new Date(2019, 1, 1) - const condition = (d: Date) => d.getFullYear() === 2018 - expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false) - }) + const date = new Date(2019, 1, 1); + const condition = (d: Date) => d.getFullYear() === 2018; + expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false); + }); it('returns true is date is in the same date as the condition', () => { - const date = new Date(2019, 1, 1, 10, 0, 0) - const conditonDate = new Date(2019, 1, 1, 10, 0, 0) + const date = new Date(2019, 1, 1, 10, 0, 0); + const conditonDate = new Date(2019, 1, 1, 10, 0, 0); - expect(dayIsPartOfTheConditions(date, conditonDate, dateParser)).toBe(true) - }) + expect(dayIsPartOfTheConditions(date, conditonDate, dateParser)).toBe(true); + }); it('returns true is date is in the same date as the condition using the date parser', () => { - const date = new Date(2019, 0, 1, 10, 0, 0) - const conditonDate = '2019-01-01' + const date = new Date(2019, 0, 1, 10, 0, 0); + const conditonDate = '2019-01-01'; - expect(dayIsPartOfTheConditions(date, conditonDate, dateParser, 'Y-m-d')).toBe(true) - }) + expect(dayIsPartOfTheConditions(date, conditonDate, dateParser, 'Y-m-d')).toBe(true); + }); it('handles an array of conditions', () => { - const date = new Date(2019, 0, 1) - const conditions = [(d: Date) => d.getFullYear() === 2019, '2019-01-01', new Date(2019, 0, 1)] + const date = new Date(2019, 0, 1); + const conditions = [(d: Date) => d.getFullYear() === 2019, '2019-01-01', new Date(2019, 0, 1)]; - expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true) - }) + expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true); + }); it('handles an array of conditions if one condition is false', () => { - const date = new Date(2019, 0, 1) - const conditions = [(d: Date) => d.getFullYear() !== 2019, '2019-01-01', new Date(2019, 0, 1)] + const date = new Date(2019, 0, 1); + const conditions = [(d: Date) => d.getFullYear() !== 2019, '2019-01-01', new Date(2019, 0, 1)]; - expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true) - }) + expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(true); + }); it('handles an array of conditions if all condition are false', () => { - const date = new Date(2019, 0, 1) - const conditions = [(d: Date) => d.getFullYear() !== 2019, '2019-02-01', new Date(2010, 0, 1)] + const date = new Date(2019, 0, 1); + const conditions = [(d: Date) => d.getFullYear() !== 2019, '2019-02-01', new Date(2010, 0, 1)]; - expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(false) - }) + expect(dayIsPartOfTheConditions(date, conditions, dateParser, 'Y-m-d')).toBe(false); + }); it('returns false if invalid condition', () => { - const date = new Date(2019, 0, 1) - const condition = 1 + const date = new Date(2019, 0, 1); + const condition = 1; - expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false) - }) -}) + expect(dayIsPartOfTheConditions(date, condition, dateParser)).toBe(false); + }); +}); diff --git a/src/__tests__/dates/formatDate.test.ts b/src/__tests__/dates/formatDate.test.ts index 58ede07..de4165b 100644 --- a/src/__tests__/dates/formatDate.test.ts +++ b/src/__tests__/dates/formatDate.test.ts @@ -1,153 +1,153 @@ -import { DateLocale } from '../../types/Dates' -import formatDate from '../../dates/formatDate' -import { English as defaultLocale } from '../../dates/l10n/default' -import { Spanish } from '../../dates/l10n/es' +import { DateLocale } from '../../types/Dates'; +import formatDate from '../../dates/formatDate'; +import { English as defaultLocale } from '../../dates/l10n/default'; +import { Spanish } from '../../dates/l10n/es'; describe('formatDate', () => { - const format = 'Y-m-d H:i:S' + const format = 'Y-m-d H:i:S'; it('returns an empty string if for null values', () => { - expect(formatDate(null, format)).toBe('') - }) + expect(formatDate(null, format)).toBe(''); + }); it('formats the date', () => { - const date = new Date(2021, 6, 1, 12, 30, 45) - expect(formatDate(date, format)).toBe('2021-07-01 12:30:45') - }) + const date = new Date(2021, 6, 1, 12, 30, 45); + expect(formatDate(date, format)).toBe('2021-07-01 12:30:45'); + }); it('formats considering an escaped token', () => { - const date = new Date(2021, 6, 1, 12, 30, 45) - expect(formatDate(date, '\\Y-m-d H:i:S')).toBe('Y-07-01 12:30:45') - }) + const date = new Date(2021, 6, 1, 12, 30, 45); + expect(formatDate(date, '\\Y-m-d H:i:S')).toBe('Y-07-01 12:30:45'); + }); describe('format a single token', () => { - const date = new Date(2021, 6, 1, 20, 11, 8) + const date = new Date(2021, 6, 1, 20, 11, 8); // d / Day of the month, 2 digits with leading zeros / 01 to 31 it('d', () => { - expect(formatDate(date, 'd')).toEqual('01') - }) + expect(formatDate(date, 'd')).toEqual('01'); + }); // D / A textual representation of a day / Mon through Sun it('D', () => { // Doesnt affect the date when parsing - expect(formatDate(date, 'D')).toEqual('Thu') - }) + expect(formatDate(date, 'D')).toEqual('Thu'); + }); // l (lowercase 'L') / A full textual representation of the day of the week / Sunday through Saturday it('l', () => { // Doesnt affect the date when parsing - expect(formatDate(date, 'l')).toEqual('Thursday') - }) + expect(formatDate(date, 'l')).toEqual('Thursday'); + }); // j / Day of the month without leading zeros / 1 to 31 it('j', () => { - expect(formatDate(date, 'j')).toEqual('1') - }) + expect(formatDate(date, 'j')).toEqual('1'); + }); // J / Day of the month without leading zeros and ordinal suffix / 1st, 2nd, to 31st it('J', () => { - expect(formatDate(date, 'J')).toEqual('1st') - }) + expect(formatDate(date, 'J')).toEqual('1st'); + }); it('J nd', () => { - const date2d = new Date(2021, 6, 2) - expect(formatDate(date2d, 'J')).toEqual('2nd') - }) + const date2d = new Date(2021, 6, 2); + expect(formatDate(date2d, 'J')).toEqual('2nd'); + }); it('J rd', () => { - const date3d = new Date(2021, 6, 3) - expect(formatDate(date3d, 'J')).toEqual('3rd') - }) + const date3d = new Date(2021, 6, 3); + expect(formatDate(date3d, 'J')).toEqual('3rd'); + }); it('J th', () => { - const date3d = new Date(2021, 6, 4) - expect(formatDate(date3d, 'J')).toEqual('4th') - }) + const date3d = new Date(2021, 6, 4); + expect(formatDate(date3d, 'J')).toEqual('4th'); + }); // w / Numeric representation of the day of the week / 0 (for Sunday) through 6 (for Saturday) it('w', () => { // Doesnt affect the date when parsing - expect(formatDate(date, 'w')).toEqual('4') - }) + expect(formatDate(date, 'w')).toEqual('4'); + }); // W / Numeric representation of the week / 0 (first week of the year) through 52 (last week of the year) it('W', () => { - expect(formatDate(date, 'W')).toEqual('26') - }) + expect(formatDate(date, 'W')).toEqual('26'); + }); // F / A full textual representation of a month / January through December it('F', () => { - expect(formatDate(date, 'F')).toEqual('July') - }) + expect(formatDate(date, 'F')).toEqual('July'); + }); // m / Numeric representation of a month, with leading zero / 01 through 12 it('m', () => { - expect(formatDate(date, 'm')).toEqual('07') - }) + expect(formatDate(date, 'm')).toEqual('07'); + }); // n / Numeric representation of a month, without leading zeros / 1 through 12 it('n', () => { // Timezone affected because the daylight saving - expect(formatDate(date, 'n')).toEqual('7') - }) + expect(formatDate(date, 'n')).toEqual('7'); + }); // M / A short textual representation of a month / Jan through Dec it('M', () => { - expect(formatDate(date, 'M')).toEqual('Jul') - }) + expect(formatDate(date, 'M')).toEqual('Jul'); + }); // U / The number of seconds since the Unix Epoch / 1413704993 it('U', () => { - expect(formatDate(date, 'U')).toEqual('1625188268') - }) + expect(formatDate(date, 'U')).toEqual('1625188268'); + }); // y / A two digit representation of a year / 99 or 03 it('y', () => { - expect(formatDate(date, 'y')).toEqual('21') - }) + expect(formatDate(date, 'y')).toEqual('21'); + }); // Y / A full numeric representation of a year, 4 digits / 1999 or 2003 it('Y', () => { - expect(formatDate(date, 'Y')).toEqual('2021') - }) + expect(formatDate(date, 'Y')).toEqual('2021'); + }); // Z / ISO Date format / 2017-03-04T01:23:43.000Z it('Z', () => { - expect(formatDate(date, 'Z')).toEqual('2021-07-02T01:11:08.000Z') - }) + expect(formatDate(date, 'Z')).toEqual('2021-07-02T01:11:08.000Z'); + }); // H / Hours (24 hours) / 00 to 23 it('H', () => { - expect(formatDate(date, 'H')).toEqual('20') - }) + expect(formatDate(date, 'H')).toEqual('20'); + }); // h / Hours / 1 to 12 it('h', () => { - expect(formatDate(date, 'h')).toEqual('8') - }) + expect(formatDate(date, 'h')).toEqual('8'); + }); it('h at 12', () => { - const dateAfter12 = new Date(2021, 6, 1, 12) - expect(formatDate(dateAfter12, 'h')).toEqual('12') - }) + const dateAfter12 = new Date(2021, 6, 1, 12); + expect(formatDate(dateAfter12, 'h')).toEqual('12'); + }); // G / Hours, 2 digits with leading zeros / 1 to 12 it('G', () => { - expect(formatDate(date, 'G')).toEqual('08') - }) + expect(formatDate(date, 'G')).toEqual('08'); + }); // i / Minutes / 00 to 59 it('i', () => { - expect(formatDate(date, 'i')).toEqual('11') - }) + expect(formatDate(date, 'i')).toEqual('11'); + }); // S / Seconds, 2 digits / 00 to 59 it('S', () => { - expect(formatDate(date, 'S')).toEqual('08') - }) + expect(formatDate(date, 'S')).toEqual('08'); + }); // s / Seconds / 0, 1 to 59 it('s', () => { - expect(formatDate(date, 's')).toEqual('8') - }) + expect(formatDate(date, 's')).toEqual('8'); + }); // K / AM/PM / AM or PM it('K', () => { - expect(formatDate(date, 'K')).toEqual('PM') - }) + expect(formatDate(date, 'K')).toEqual('PM'); + }); it('K for AM', () => { - const dateAM = new Date(2021, 6, 1, 10, 11, 8) - expect(formatDate(dateAM, 'K')).toEqual('AM') - }) - }) + const dateAM = new Date(2021, 6, 1, 10, 11, 8); + expect(formatDate(dateAM, 'K')).toEqual('AM'); + }); + }); describe('Custom locale', () => { const allTokens = [ @@ -173,17 +173,17 @@ describe('formatDate', () => { 's', 'w', 'y', - ] + ]; it('Spanish', () => { - const date = new Date(2021, 6, 2, 8, 11, 8) + const date = new Date(2021, 6, 2, 8, 11, 8); const customLocale: DateLocale = { ...defaultLocale, ...Spanish, - } + }; expect(formatDate(date, allTokens.join('-'), customLocale)).toEqual( - 'Vie-Julio-08-08-2º-AM-Jul-08-1625231468-26-2021-2021-07-02T13:11:08.000Z-02-8-11-2-Viernes-07-7-8-5-21' - ) - }) - }) -}) + 'Vie-Julio-08-08-2º-AM-Jul-08-1625231468-26-2021-2021-07-02T13:11:08.000Z-02-8-11-2-Viernes-07-7-8-5-21', + ); + }); + }); +}); diff --git a/src/__tests__/dates/getDateInDayNumber.test.ts b/src/__tests__/dates/getDateInDayNumber.test.ts index cd6153c..5f00657 100644 --- a/src/__tests__/dates/getDateInDayNumber.test.ts +++ b/src/__tests__/dates/getDateInDayNumber.test.ts @@ -1,19 +1,19 @@ -import getDateInDayNumber from '../../dates/getDateInDayNumber' +import getDateInDayNumber from '../../dates/getDateInDayNumber'; describe('getDateInDayNumber', () => { it('gets the same date in a day number', () => { // 2020-01-15 - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(getDateInDayNumber(date, 10)).toEqual(new Date(2020, 0, 10)) - }) + expect(getDateInDayNumber(date, 10)).toEqual(new Date(2020, 0, 10)); + }); it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12) - const date = new Date(2020, 0, 15, 10, 11, 12) + const originalDate = new Date(2020, 0, 15, 10, 11, 12); + const date = new Date(2020, 0, 15, 10, 11, 12); - getDateInDayNumber(date, 12) + getDateInDayNumber(date, 12); - expect(date).toEqual(originalDate) - }) -}) + expect(date).toEqual(originalDate); + }); +}); diff --git a/src/__tests__/dates/getFirstDayOfMonth.test.ts b/src/__tests__/dates/getFirstDayOfMonth.test.ts index 199fbbe..5c30ebb 100644 --- a/src/__tests__/dates/getFirstDayOfMonth.test.ts +++ b/src/__tests__/dates/getFirstDayOfMonth.test.ts @@ -1,26 +1,26 @@ -import getFirstDayOfMonth from '../../dates/getFirstDayOfMonth' +import getFirstDayOfMonth from '../../dates/getFirstDayOfMonth'; describe('getFirstDayOfMonth', () => { it('gets the first day of a month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 0, 1)) - }) + expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 0, 1)); + }); it('gets the first day of a month if pass the first day', () => { // 2020-04-01 - const date = new Date(2020, 3, 1) + const date = new Date(2020, 3, 1); - expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 3, 1)) - }) + expect(getFirstDayOfMonth(date)).toEqual(new Date(2020, 3, 1)); + }); it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12) - const date = new Date(2020, 0, 15, 10, 11, 12) + const originalDate = new Date(2020, 0, 15, 10, 11, 12); + const date = new Date(2020, 0, 15, 10, 11, 12); - getFirstDayOfMonth(date) + getFirstDayOfMonth(date); - expect(date).toEqual(originalDate) - }) -}) + expect(date).toEqual(originalDate); + }); +}); diff --git a/src/__tests__/dates/getFirstDayOfNextMonth.test.ts b/src/__tests__/dates/getFirstDayOfNextMonth.test.ts index 7bf35fa..f0c01d8 100644 --- a/src/__tests__/dates/getFirstDayOfNextMonth.test.ts +++ b/src/__tests__/dates/getFirstDayOfNextMonth.test.ts @@ -1,33 +1,33 @@ -import getFirstDayOfNextMonth from '../../dates/getFirstDayOfNextMonth' +import getFirstDayOfNextMonth from '../../dates/getFirstDayOfNextMonth'; describe('getFirstDayOfNextMonth', () => { it('gets the first day of next month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)) - }) + expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)); + }); it('gets the first day of next month for last month', () => { // 2020-12-15 - const date = new Date(2020, 11, 15) + const date = new Date(2020, 11, 15); - expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2021, 0, 1)) - }) + expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2021, 0, 1)); + }); it('gets the first day of next month if last day', () => { // 2020-01-31 - const date = new Date(2020, 0, 31) + const date = new Date(2020, 0, 31); - expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)) - }) + expect(getFirstDayOfNextMonth(date)).toEqual(new Date(2020, 1, 1)); + }); it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12) - const date = new Date(2020, 0, 15, 10, 11, 12) + const originalDate = new Date(2020, 0, 15, 10, 11, 12); + const date = new Date(2020, 0, 15, 10, 11, 12); - getFirstDayOfNextMonth(date) + getFirstDayOfNextMonth(date); - expect(date).toEqual(originalDate) - }) -}) + expect(date).toEqual(originalDate); + }); +}); diff --git a/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts b/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts index acb8266..815c35c 100644 --- a/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts +++ b/src/__tests__/dates/getFirstDayOfPrevMonth.test.ts @@ -1,33 +1,33 @@ -import getFirstDayOfPrevMonth from '../../dates/getFirstDayOfPrevMonth' +import getFirstDayOfPrevMonth from '../../dates/getFirstDayOfPrevMonth'; describe('getFirstDayOfPrevMonth', () => { it('gets the first day of prev month if is first month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 1)) - }) + expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 1)); + }); it('gets the first day of prev month if is last month', () => { // 2020-01-15 - const date = new Date(2020, 11, 15) + const date = new Date(2020, 11, 15); - expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)) - }) + expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)); + }); it('gets the first day of prev month when first day', () => { // 2020-01-1 - const date = new Date(2020, 11, 1) + const date = new Date(2020, 11, 1); - expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)) - }) + expect(getFirstDayOfPrevMonth(date)).toEqual(new Date(2020, 10, 1)); + }); it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12) - const date = new Date(2020, 0, 15, 10, 11, 12) + const originalDate = new Date(2020, 0, 15, 10, 11, 12); + const date = new Date(2020, 0, 15, 10, 11, 12); - getFirstDayOfPrevMonth(date) + getFirstDayOfPrevMonth(date); - expect(date).toEqual(originalDate) - }) -}) + expect(date).toEqual(originalDate); + }); +}); diff --git a/src/__tests__/dates/getLastDayOfMonth.test.ts b/src/__tests__/dates/getLastDayOfMonth.test.ts index 88f0b78..825e3d3 100644 --- a/src/__tests__/dates/getLastDayOfMonth.test.ts +++ b/src/__tests__/dates/getLastDayOfMonth.test.ts @@ -1,47 +1,47 @@ -import getLastDayOfMonth from '../../dates/getLastDayOfMonth' +import getLastDayOfMonth from '../../dates/getLastDayOfMonth'; describe('getLastDayOfMonth', () => { it('gets the last day of a month that have 31 days', () => { // 2020-01-15 - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 0, 31)) - }) + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 0, 31)); + }); it('gets the last day of a month that have 28 days', () => { // 2020-02-15 - const date = new Date(2020, 1, 15) + const date = new Date(2020, 1, 15); - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 1, 29)) - }) + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 1, 29)); + }); it('gets the last day of a month that have 30 days', () => { // 2020-04-15 - const date = new Date(2020, 3, 15) + const date = new Date(2020, 3, 15); - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)) - }) + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)); + }); it('gets the last day of a month if pass the last day', () => { // 2020-04-30 - const date = new Date(2020, 3, 30) + const date = new Date(2020, 3, 30); - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)) - }) + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)); + }); it('gets the last day of a month if pass the first day', () => { // 2020-04-30 - const date = new Date(2020, 3, 1) + const date = new Date(2020, 3, 1); - expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)) - }) + expect(getLastDayOfMonth(date)).toEqual(new Date(2020, 3, 30)); + }); it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12) - const date = new Date(2020, 0, 15, 10, 11, 12) + const originalDate = new Date(2020, 0, 15, 10, 11, 12); + const date = new Date(2020, 0, 15, 10, 11, 12); - getLastDayOfMonth(date) + getLastDayOfMonth(date); - expect(date).toEqual(originalDate) - }) -}) + expect(date).toEqual(originalDate); + }); +}); diff --git a/src/__tests__/dates/getLastDayOfPrevMonth.test.ts b/src/__tests__/dates/getLastDayOfPrevMonth.test.ts index 278e799..92ee9d7 100644 --- a/src/__tests__/dates/getLastDayOfPrevMonth.test.ts +++ b/src/__tests__/dates/getLastDayOfPrevMonth.test.ts @@ -1,33 +1,33 @@ -import getLastDayOfPrevMonth from '../../dates/getLastDayOfPrevMonth' +import getLastDayOfPrevMonth from '../../dates/getLastDayOfPrevMonth'; describe('getLastDayOfPrevMonth', () => { it('gets the last day of prev month if is first month', () => { // 2020-01-15 - const date = new Date(2020, 0, 15) + const date = new Date(2020, 0, 15); - expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 31)) - }) + expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2019, 11, 31)); + }); it('gets the last day of prev month if has 29 days', () => { // 2020-03-15 - const date = new Date(2020, 2, 15) + const date = new Date(2020, 2, 15); - expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 1, 29)) - }) + expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 1, 29)); + }); it('gets the last day of prev month if has 30 days', () => { // 2020-07-15 - const date = new Date(2020, 6, 15) + const date = new Date(2020, 6, 15); - expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 5, 30)) - }) + expect(getLastDayOfPrevMonth(date)).toEqual(new Date(2020, 5, 30)); + }); it('doesnt affects the original date', () => { - const originalDate = new Date(2020, 0, 15, 10, 11, 12) - const date = new Date(2020, 0, 15, 10, 11, 12) + const originalDate = new Date(2020, 0, 15, 10, 11, 12); + const date = new Date(2020, 0, 15, 10, 11, 12); - getLastDayOfPrevMonth(date) + getLastDayOfPrevMonth(date); - expect(date).toEqual(originalDate) - }) -}) + expect(date).toEqual(originalDate); + }); +}); diff --git a/src/__tests__/dates/isSameDay.test.ts b/src/__tests__/dates/isSameDay.test.ts index 2e5c69b..781f2c4 100644 --- a/src/__tests__/dates/isSameDay.test.ts +++ b/src/__tests__/dates/isSameDay.test.ts @@ -1,51 +1,51 @@ -import isSameDay from '../../dates/isSameDay' +import isSameDay from '../../dates/isSameDay'; describe('isSameDay', () => { it('determines that is same day for the same date', () => { - const date1 = new Date(2020, 0, 15) - const date2 = new Date(2020, 0, 15) + const date1 = new Date(2020, 0, 15); + const date2 = new Date(2020, 0, 15); - expect(isSameDay(date1, date2)).toBe(true) - }) + expect(isSameDay(date1, date2)).toBe(true); + }); it('determines that is same day if different minute', () => { - const date1 = new Date(2020, 0, 15, 12) - const date2 = new Date(2020, 0, 15, 11) + const date1 = new Date(2020, 0, 15, 12); + const date2 = new Date(2020, 0, 15, 11); - expect(isSameDay(date1, date2)).toBe(true) - }) + expect(isSameDay(date1, date2)).toBe(true); + }); it('determines that a date is not the same if different month', () => { - const date1 = new Date(2020, 0, 15) - const date2 = new Date(2020, 1, 15) + const date1 = new Date(2020, 0, 15); + const date2 = new Date(2020, 1, 15); - expect(isSameDay(date1, date2)).toBe(false) - }) + expect(isSameDay(date1, date2)).toBe(false); + }); it('determines that a date is not in the same day if year is different', () => { - const date1 = new Date(2021, 0, 15) - const date2 = new Date(2020, 0, 15) + const date1 = new Date(2021, 0, 15); + const date2 = new Date(2020, 0, 15); - expect(isSameDay(date1, date2)).toBe(false) - }) + expect(isSameDay(date1, date2)).toBe(false); + }); it('determines that a date is not in the same day if second one is undefined', () => { - const date1 = new Date(2021, 0, 15) - const date2 = undefined + const date1 = new Date(2021, 0, 15); + const date2 = undefined; - expect(isSameDay(date1, date2)).toBe(false) - }) + expect(isSameDay(date1, date2)).toBe(false); + }); it('determines that a date is not in the same day if first one is undefined', () => { - const date1 = undefined - const date2 = new Date(2021, 0, 15) + const date1 = undefined; + const date2 = new Date(2021, 0, 15); - expect(isSameDay(date1, date2)).toBe(false) - }) + expect(isSameDay(date1, date2)).toBe(false); + }); it('determines that a date is not in the same day if both undefined', () => { - const date1 = undefined - const date2 = undefined + const date1 = undefined; + const date2 = undefined; - expect(isSameDay(date1, date2)).toBe(false) - }) -}) + expect(isSameDay(date1, date2)).toBe(false); + }); +}); diff --git a/src/__tests__/dates/isSameMonth.test.ts b/src/__tests__/dates/isSameMonth.test.ts index bdf8584..efed2f4 100644 --- a/src/__tests__/dates/isSameMonth.test.ts +++ b/src/__tests__/dates/isSameMonth.test.ts @@ -1,52 +1,52 @@ -import isSameMonth from '../../dates/isSameMonth' +import isSameMonth from '../../dates/isSameMonth'; describe('isSameMonth', () => { it('determines that the same date is in the same month', () => { - const date1 = new Date(2020, 0, 15) - const date2 = new Date(2020, 0, 15) + const date1 = new Date(2020, 0, 15); + const date2 = new Date(2020, 0, 15); - expect(isSameMonth(date1, date2)).toBe(true) - }) + expect(isSameMonth(date1, date2)).toBe(true); + }); it('determines that a date is in the same month if day is different', () => { - const date1 = new Date(2020, 0, 15) - const date2 = new Date(2020, 0, 15) + const date1 = new Date(2020, 0, 15); + const date2 = new Date(2020, 0, 15); - expect(isSameMonth(date1, date2)).toBe(true) - }) + expect(isSameMonth(date1, date2)).toBe(true); + }); it('determines that a date is not in the same month if year is different', () => { - const date1 = new Date(2021, 0, 15) - const date2 = new Date(2020, 0, 15) + const date1 = new Date(2021, 0, 15); + const date2 = new Date(2020, 0, 15); - expect(isSameMonth(date1, date2)).toBe(false) - }) + expect(isSameMonth(date1, date2)).toBe(false); + }); it('determines that a date is not in the same month', () => { - const date1 = new Date(2021, 0, 15) - const date2 = new Date(2021, 1, 15) + const date1 = new Date(2021, 0, 15); + const date2 = new Date(2021, 1, 15); - expect(isSameMonth(date1, date2)).toBe(false) - }) + expect(isSameMonth(date1, date2)).toBe(false); + }); it('determines that a date is not in the same month if second one is undefined', () => { - const date1 = new Date(2021, 0, 15) - const date2 = undefined + const date1 = new Date(2021, 0, 15); + const date2 = undefined; - expect(isSameMonth(date1, date2)).toBe(false) - }) + expect(isSameMonth(date1, date2)).toBe(false); + }); it('determines that a date is not in the same month if first one is undefined', () => { - const date1 = undefined - const date2 = new Date(2021, 0, 15) + const date1 = undefined; + const date2 = new Date(2021, 0, 15); - expect(isSameMonth(date1, date2)).toBe(false) - }) + expect(isSameMonth(date1, date2)).toBe(false); + }); it('determines that a date is not in the same month if both undefined', () => { - const date1 = undefined - const date2 = undefined + const date1 = undefined; + const date2 = undefined; - expect(isSameMonth(date1, date2)).toBe(false) - }) -}) + expect(isSameMonth(date1, date2)).toBe(false); + }); +}); diff --git a/src/__tests__/dates/isToday.test.ts b/src/__tests__/dates/isToday.test.ts index 6b80472..a8622d2 100644 --- a/src/__tests__/dates/isToday.test.ts +++ b/src/__tests__/dates/isToday.test.ts @@ -1,22 +1,22 @@ -import isToday from '../../dates/isToday' +import isToday from '../../dates/isToday'; describe('isToday', () => { it('determines that is same day for current date', () => { - const date = new Date() + const date = new Date(); - expect(isToday(date)).toBe(true) - }) + expect(isToday(date)).toBe(true); + }); it('determines that is same day for a date at the end of the day', () => { - const date = new Date() - const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999) + const date = new Date(); + const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999); - expect(isToday(today)).toBe(true) - }) + expect(isToday(today)).toBe(true); + }); it('determines that is same day for a date at the start of the day', () => { - const date = new Date() - const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0) + const date = new Date(); + const today = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0); - expect(isToday(today)).toBe(true) - }) -}) + expect(isToday(today)).toBe(true); + }); +}); diff --git a/src/__tests__/dates/parseDate.test.ts b/src/__tests__/dates/parseDate.test.ts index 6755bb6..454ae85 100644 --- a/src/__tests__/dates/parseDate.test.ts +++ b/src/__tests__/dates/parseDate.test.ts @@ -1,25 +1,25 @@ -import parseDate from '../../dates/parseDate' +import parseDate from '../../dates/parseDate'; describe('parseDate', () => { - const defaultFormat = 'Y-m-d H:i:S' - const timeless = true + const defaultFormat = 'Y-m-d H:i:S'; + const timeless = true; describe('String parsing', () => { it('returns undefined if empty date string', () => { - expect(parseDate('')).toBeUndefined() - }) + expect(parseDate('')).toBeUndefined(); + }); it('returns undefined if NaN', () => { - expect(parseDate(NaN)).toBeUndefined() - }) + expect(parseDate(NaN)).toBeUndefined(); + }); it('returns undefined if passes a function', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const fn = (() => {}) as any + const fn = (() => {}) as any; - const parser = () => parseDate(fn) - expect(parser).toThrow(new Error('Invalid date provided: () => { }')) - }) + const parser = () => parseDate(fn); + expect(parser).toThrow(new Error('Invalid date provided: () => { }')); + }); it('returns today date if passed `today`', () => { const today = new Date( @@ -29,204 +29,204 @@ describe('parseDate', () => { 0, 0, 0, - 0 - ) - expect(parseDate('today')).toEqual(today) - }) + 0, + ); + expect(parseDate('today')).toEqual(today); + }); it('parses gmt dates', () => { expect(parseDate('Sat, 23 Oct 2021 20:58:00 GMT')).toEqual( - new Date(Date.UTC(2021, 9, 23, 20, 58, 0, 0)) - ) - }) + new Date(Date.UTC(2021, 9, 23, 20, 58, 0, 0)), + ); + }); it('parses iso dates', () => { expect(parseDate('2021-10-23T20:58:11.733Z')).toEqual( - new Date(Date.UTC(2021, 9, 23, 20, 58, 11, 733)) - ) - }) + new Date(Date.UTC(2021, 9, 23, 20, 58, 11, 733)), + ); + }); it('parses a date in the default format', () => { - expect(parseDate('2020-02-18 12:34:56')).toEqual(new Date(2020, 1, 18, 12, 34, 56)) - }) + expect(parseDate('2020-02-18 12:34:56')).toEqual(new Date(2020, 1, 18, 12, 34, 56)); + }); it('parses a date ignoring time', () => { expect(parseDate('2020-02-18 12:34:56', defaultFormat, timeless)).toEqual( - new Date(2020, 1, 18, 0, 0, 0) - ) - }) + new Date(2020, 1, 18, 0, 0, 0), + ); + }); it('escapes the token', () => { expect(parseDate('2020Y-02-18 12m:34:56', 'Y\\Y-m-d H\\m:i:S')).toEqual( - new Date(2020, 1, 18, 12, 34, 56) - ) - }) + new Date(2020, 1, 18, 12, 34, 56), + ); + }); it('returns undefined if using an invalid format', () => { - const parser = () => parseDate('2020-11-12', 'X') + const parser = () => parseDate('2020-11-12', 'X'); - expect(parser).toThrow(new Error('Invalid date provided: 2020-11-12')) - }) + expect(parser).toThrow(new Error('Invalid date provided: 2020-11-12')); + }); it('returns undefined if dates doesnt matchs the format', () => { - const parser = () => parseDate('18021987', 'K') + const parser = () => parseDate('18021987', 'K'); - expect(parser).toThrow(new Error('Invalid date provided: 18021987')) - }) + expect(parser).toThrow(new Error('Invalid date provided: 18021987')); + }); describe('parse a single token', () => { - let baseDate: Date + let baseDate: Date; beforeEach(() => { - baseDate = new Date('2021-01-01T06:00:00.000Z') + baseDate = new Date('2021-01-01T06:00:00.000Z'); - jest.useFakeTimers().setSystemTime(baseDate.getTime()) - }) + jest.useFakeTimers().setSystemTime(baseDate.getTime()); + }); afterEach(() => { - jest.useRealTimers() - }) + jest.useRealTimers(); + }); // d / Day of the month, 2 digits with leading zeros / 01 to 31 it('d', () => { - expect(parseDate('05', 'd')).toEqual(new Date('2021-01-05T06:00:00.000Z')) - }) + expect(parseDate('05', 'd')).toEqual(new Date('2021-01-05T06:00:00.000Z')); + }); // D / A textual representation of a day / Mon through Sun it('D', () => { // Doesnt affect the date when parsing - expect(parseDate('Tue', 'D')).toEqual(new Date('2021-01-01T06:00:00.000Z')) - }) + expect(parseDate('Tue', 'D')).toEqual(new Date('2021-01-01T06:00:00.000Z')); + }); // l (lowercase 'L') / A full textual representation of the day of the week / Sunday through Saturday it('l', () => { // Doesnt affect the date when parsing - expect(parseDate('Saturday', 'l')).toEqual(new Date('2021-01-01T06:00:00.000Z')) - }) + expect(parseDate('Saturday', 'l')).toEqual(new Date('2021-01-01T06:00:00.000Z')); + }); // j / Day of the month without leading zeros / 1 to 31 it('j', () => { - expect(parseDate('10', 'j')).toEqual(new Date('2021-01-10T06:00:00.000Z')) - }) + expect(parseDate('10', 'j')).toEqual(new Date('2021-01-10T06:00:00.000Z')); + }); // J / Day of the month without leading zeros and ordinal suffix / 1st, 2nd, to 31st it('J', () => { - expect(parseDate('22nd', 'J')).toEqual(new Date('2021-01-22T06:00:00.000Z')) - }) + expect(parseDate('22nd', 'J')).toEqual(new Date('2021-01-22T06:00:00.000Z')); + }); // w / Numeric representation of the day of the week / 0 (for Sunday) through 6 (for Saturday) it('w', () => { // Doesnt affect the date when parsing - expect(parseDate('4', 'w')).toEqual(new Date('2021-01-01T06:00:00.000Z')) - }) + expect(parseDate('4', 'w')).toEqual(new Date('2021-01-01T06:00:00.000Z')); + }); // W / Numeric representation of the week / 0 (first week of the year) through 52 (last week of the year) it('W', () => { - expect(parseDate('32', 'W')).toEqual(new Date('2021-08-01T05:00:00.000Z')) - }) + expect(parseDate('32', 'W')).toEqual(new Date('2021-08-01T05:00:00.000Z')); + }); // F / A full textual representation of a month / January through December it('F', () => { - expect(parseDate('November', 'F')).toEqual(new Date('2021-11-01T06:00:00.000Z')) - }) + expect(parseDate('November', 'F')).toEqual(new Date('2021-11-01T06:00:00.000Z')); + }); // m / Numeric representation of a month, with leading zero / 01 through 12 it('m', () => { - expect(parseDate('11', 'm')).toEqual(new Date('2021-11-01T06:00:00.000Z')) - }) + expect(parseDate('11', 'm')).toEqual(new Date('2021-11-01T06:00:00.000Z')); + }); // n / Numeric representation of a month, without leading zeros / 1 through 12 it('n', () => { // Timezone affected because the daylight saving - expect(parseDate('9', 'n')).toEqual(new Date('2021-09-01T05:00:00.000Z')) - }) + expect(parseDate('9', 'n')).toEqual(new Date('2021-09-01T05:00:00.000Z')); + }); // M / A short textual representation of a month / Jan through Dec it('M', () => { - expect(parseDate('Feb', 'M')).toEqual(new Date('2021-02-01T06:00:00.000Z')) - }) + expect(parseDate('Feb', 'M')).toEqual(new Date('2021-02-01T06:00:00.000Z')); + }); // U / The number of seconds since the Unix Epoch / 1413704993 it('U', () => { - expect(parseDate('1635080656', 'U')).toEqual(new Date('2021-10-24T13:04:16.000Z')) - }) + expect(parseDate('1635080656', 'U')).toEqual(new Date('2021-10-24T13:04:16.000Z')); + }); // y / A two digit representation of a year / 99 or 03 it('y', () => { - expect(parseDate('20', 'y')).toEqual(new Date('2020-01-01T06:00:00.000Z')) - }) + expect(parseDate('20', 'y')).toEqual(new Date('2020-01-01T06:00:00.000Z')); + }); // Y / A full numeric representation of a year, 4 digits / 1999 or 2003 it('Y', () => { - expect(parseDate('2019', 'Y')).toEqual(new Date('2019-01-01T06:00:00.000Z')) - }) + expect(parseDate('2019', 'Y')).toEqual(new Date('2019-01-01T06:00:00.000Z')); + }); // Z / ISO Date format / 2017-03-04T01:23:43.000Z it('Z', () => { expect(parseDate('2020-01-01T06:00:00.000', 'Z')).toEqual( - new Date('2020-01-01T12:00:00.000Z') - ) - }) + new Date('2020-01-01T12:00:00.000Z'), + ); + }); // H / Hours (24 hours) / 00 to 23 it('H', () => { - expect(parseDate('14', 'H')).toEqual(new Date('2021-01-01T20:00:00.000Z')) - }) + expect(parseDate('14', 'H')).toEqual(new Date('2021-01-01T20:00:00.000Z')); + }); // h / Hours / 1 to 12 it('h', () => { - expect(parseDate('6', 'h')).toEqual(new Date('2021-01-01T12:00:00.000Z')) - }) + expect(parseDate('6', 'h')).toEqual(new Date('2021-01-01T12:00:00.000Z')); + }); // G / Hours, 2 digits with leading zeros / 1 to 12 it('G', () => { - expect(parseDate('10', 'G')).toEqual(new Date('2021-01-01T16:00:00.000Z')) - }) + expect(parseDate('10', 'G')).toEqual(new Date('2021-01-01T16:00:00.000Z')); + }); // i / Minutes / 00 to 59 it('i', () => { - expect(parseDate('35', 'i')).toEqual(new Date('2021-01-01T06:35:00.000Z')) - }) + expect(parseDate('35', 'i')).toEqual(new Date('2021-01-01T06:35:00.000Z')); + }); // S / Seconds, 2 digits / 00 to 59 it('S', () => { - expect(parseDate('42', 'S')).toEqual(new Date('2021-01-01T06:00:42.000Z')) - }) + expect(parseDate('42', 'S')).toEqual(new Date('2021-01-01T06:00:42.000Z')); + }); // s / Seconds / 0, 1 to 59 it('s', () => { - expect(parseDate('18', 's')).toEqual(new Date('2021-01-01T06:00:18.000Z')) - }) + expect(parseDate('18', 's')).toEqual(new Date('2021-01-01T06:00:18.000Z')); + }); // K / AM/PM / AM or PM it('K', () => { - expect(parseDate('PM', 'K')).toEqual(new Date('2021-01-01T18:00:00.000Z')) - }) + expect(parseDate('PM', 'K')).toEqual(new Date('2021-01-01T18:00:00.000Z')); + }); it('K for AM', () => { - expect(parseDate('AM', 'K')).toEqual(new Date('2021-01-01T06:00:00.000Z')) - }) - }) - }) + expect(parseDate('AM', 'K')).toEqual(new Date('2021-01-01T06:00:00.000Z')); + }); + }); + }); describe('Numeric values parsing', () => { it('returns a 0 date if passed `0` as a param', () => { - expect(parseDate(0)).toEqual(new Date(0)) - }) - }) + expect(parseDate(0)).toEqual(new Date(0)); + }); + }); describe('Date instances parsing', () => { it('returns a clone of the date passed as a paramenter', () => { - const date = new Date(2020, 2, 15) + const date = new Date(2020, 2, 15); - expect(parseDate(date)).toEqual(new Date(2020, 2, 15)) - }) + expect(parseDate(date)).toEqual(new Date(2020, 2, 15)); + }); it('returns same date but with the time reset if timeless', () => { - const date = new Date(2020, 2, 15, 12, 30, 45) + const date = new Date(2020, 2, 15, 12, 30, 45); - expect(parseDate(date, defaultFormat, timeless)).toEqual(new Date(2020, 2, 15, 0, 0, 0, 0)) - }) - }) + expect(parseDate(date, defaultFormat, timeless)).toEqual(new Date(2020, 2, 15, 0, 0, 0, 0)); + }); + }); describe('Timestamp instances parsing', () => { it('returns a date when passing the timestamp ', () => { - const date = new Date(2020, 2, 15) + const date = new Date(2020, 2, 15); - expect(parseDate(date.getTime())).toEqual(new Date(2020, 2, 15)) - }) + expect(parseDate(date.getTime())).toEqual(new Date(2020, 2, 15)); + }); it('returns a date when passing the timestamp as number ', () => { - const date = new Date(2020, 2, 15) + const date = new Date(2020, 2, 15); - expect(parseDate(+date)).toEqual(new Date(2020, 2, 15)) - }) + expect(parseDate(+date)).toEqual(new Date(2020, 2, 15)); + }); it('returns a date when passing the timestamp as a regular number ', () => { - expect(parseDate(1584252000000)).toEqual(new Date(2020, 2, 15)) - }) - }) -}) + expect(parseDate(1584252000000)).toEqual(new Date(2020, 2, 15)); + }); + }); +}); diff --git a/src/__tests__/dates/visibleDaysInMonthView.test.ts b/src/__tests__/dates/visibleDaysInMonthView.test.ts index 5e321e7..a453c9c 100644 --- a/src/__tests__/dates/visibleDaysInMonthView.test.ts +++ b/src/__tests__/dates/visibleDaysInMonthView.test.ts @@ -1,82 +1,82 @@ -import { WeekDay } from '../../types/Dates' -import visibleDaysInMonthView from '../../dates/visibleDaysInMonthView' +import { WeekDay } from '../../types/Dates'; +import visibleDaysInMonthView from '../../dates/visibleDaysInMonthView'; describe('visibleDaysInMonthView', () => { it('returns 42 items by adding the days on the next month and the prev month', () => { // 2021-10-23 - const date = new Date(2021, 9, 23) + const date = new Date(2021, 9, 23); - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(42) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 8, 26)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 8, 30)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[5]).toEqual(new Date(2021, 9, 1)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[35]).toEqual(new Date(2021, 9, 31)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[36]).toEqual(new Date(2021, 10, 1)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[41]).toEqual(new Date(2021, 10, 6)) - }) + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(42); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 8, 26)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 8, 30)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[5]).toEqual(new Date(2021, 9, 1)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[35]).toEqual(new Date(2021, 9, 31)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[36]).toEqual(new Date(2021, 10, 1)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[41]).toEqual(new Date(2021, 10, 6)); + }); it('uses monday as default start of week', () => { // 2021-10-23 - const date = new Date(2021, 9, 23) + const date = new Date(2021, 9, 23); - expect(visibleDaysInMonthView(date).length).toBe(42) - expect(visibleDaysInMonthView(date)[0]).toEqual(new Date(2021, 8, 26)) - expect(visibleDaysInMonthView(date)[41]).toEqual(new Date(2021, 10, 6)) - }) + expect(visibleDaysInMonthView(date).length).toBe(42); + expect(visibleDaysInMonthView(date)[0]).toEqual(new Date(2021, 8, 26)); + expect(visibleDaysInMonthView(date)[41]).toEqual(new Date(2021, 10, 6)); + }); it('returns 35 items by adding the days on the next month and the prev month using a custom start of week', () => { // 2021-10-23 - const date = new Date(2021, 9, 23) + const date = new Date(2021, 9, 23); - expect(visibleDaysInMonthView(date, WeekDay.Tuesday).length).toBe(35) - expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[0]).toEqual(new Date(2021, 8, 28)) - expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[6]).toEqual(new Date(2021, 9, 4)) - expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[34]).toEqual(new Date(2021, 10, 1)) - }) + expect(visibleDaysInMonthView(date, WeekDay.Tuesday).length).toBe(35); + expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[0]).toEqual(new Date(2021, 8, 28)); + expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[6]).toEqual(new Date(2021, 9, 4)); + expect(visibleDaysInMonthView(date, WeekDay.Tuesday)[34]).toEqual(new Date(2021, 10, 1)); + }); it('returns 42 items by adding the days on the next month and the prev month using a custom start of week', () => { // 2021-10-23 - const date = new Date(2021, 9, 23) + const date = new Date(2021, 9, 23); - expect(visibleDaysInMonthView(date, WeekDay.Saturday).length).toBe(42) - expect(visibleDaysInMonthView(date, WeekDay.Saturday)[0]).toEqual(new Date(2021, 8, 25)) - expect(visibleDaysInMonthView(date, WeekDay.Saturday)[41]).toEqual(new Date(2021, 10, 5)) - }) + expect(visibleDaysInMonthView(date, WeekDay.Saturday).length).toBe(42); + expect(visibleDaysInMonthView(date, WeekDay.Saturday)[0]).toEqual(new Date(2021, 8, 25)); + expect(visibleDaysInMonthView(date, WeekDay.Saturday)[41]).toEqual(new Date(2021, 10, 5)); + }); it('returns 35 items when month ends on last day of week', () => { // 2021-07-23 - const date = new Date(2021, 6, 23) + const date = new Date(2021, 6, 23); - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 5, 27)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 6, 1)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2021, 6, 31)) - }) + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2021, 5, 27)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[4]).toEqual(new Date(2021, 6, 1)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2021, 6, 31)); + }); it('returns 35 items when month start on first day of week', () => { // 2020-11-23 - const date = new Date(2020, 10, 23) + const date = new Date(2020, 10, 23); - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2020, 10, 1)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[29]).toEqual(new Date(2020, 10, 30)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2020, 11, 5)) - }) + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(35); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2020, 10, 1)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[29]).toEqual(new Date(2020, 10, 30)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[34]).toEqual(new Date(2020, 11, 5)); + }); it('get four rows for a month with 28 days that start on sunday', () => { // 2015-02-15 - const date = new Date(2015, 1, 15) + const date = new Date(2015, 1, 15); - expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(28) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2015, 1, 1)) - expect(visibleDaysInMonthView(date, WeekDay.Sunday)[27]).toEqual(new Date(2015, 1, 28)) - }) + expect(visibleDaysInMonthView(date, WeekDay.Sunday).length).toBe(28); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[0]).toEqual(new Date(2015, 1, 1)); + expect(visibleDaysInMonthView(date, WeekDay.Sunday)[27]).toEqual(new Date(2015, 1, 28)); + }); it('get four rows for a month with 28 days and first day matches a custom day of week', () => { - const date = new Date(2021, 1, 15) + const date = new Date(2021, 1, 15); - expect(visibleDaysInMonthView(date, WeekDay.Monday).length).toBe(28) - expect(visibleDaysInMonthView(date, WeekDay.Monday)[0]).toEqual(new Date(2021, 1, 1)) - expect(visibleDaysInMonthView(date, WeekDay.Monday)[27]).toEqual(new Date(2021, 1, 28)) - }) -}) + expect(visibleDaysInMonthView(date, WeekDay.Monday).length).toBe(28); + expect(visibleDaysInMonthView(date, WeekDay.Monday)[0]).toEqual(new Date(2021, 1, 1)); + expect(visibleDaysInMonthView(date, WeekDay.Monday)[27]).toEqual(new Date(2021, 1, 28)); + }); +}); diff --git a/src/__tests__/debounce.test.ts b/src/__tests__/debounce.test.ts index 135cb25..ce77ffa 100644 --- a/src/__tests__/debounce.test.ts +++ b/src/__tests__/debounce.test.ts @@ -1,81 +1,81 @@ -import debounce from '../helpers/debounce' +import debounce from '../helpers/debounce'; describe('debounce', () => { it('runs the function after the default time', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - jest.useFakeTimers() + jest.useFakeTimers(); - debounce(mockFn)() + debounce(mockFn)(); - expect(mockFn).not.toHaveBeenCalled() + expect(mockFn).not.toHaveBeenCalled(); - jest.advanceTimersByTime(199) + jest.advanceTimersByTime(199); - expect(mockFn).not.toHaveBeenCalled() + expect(mockFn).not.toHaveBeenCalled(); - jest.advanceTimersByTime(1) + jest.advanceTimersByTime(1); - expect(mockFn).toHaveBeenCalled() - }) + expect(mockFn).toHaveBeenCalled(); + }); it('reset the time if function called again', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - jest.useFakeTimers() + jest.useFakeTimers(); - const func = debounce(mockFn, 200) + const func = debounce(mockFn, 200); - func() + func(); - expect(mockFn).not.toHaveBeenCalled() + expect(mockFn).not.toHaveBeenCalled(); - jest.advanceTimersByTime(199) + jest.advanceTimersByTime(199); - func() + func(); - jest.advanceTimersByTime(199) + jest.advanceTimersByTime(199); - expect(mockFn).not.toHaveBeenCalled() + expect(mockFn).not.toHaveBeenCalled(); - jest.advanceTimersByTime(1) + jest.advanceTimersByTime(1); - expect(mockFn).toHaveBeenCalled() - }) + expect(mockFn).toHaveBeenCalled(); + }); it('can cancel the call', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - jest.useFakeTimers() + jest.useFakeTimers(); - const func = debounce(mockFn, 200) + const func = debounce(mockFn, 200); - func() + func(); - func.cancel() + func.cancel(); - jest.advanceTimersByTime(300) + jest.advanceTimersByTime(300); - expect(mockFn).not.toHaveBeenCalled() - }) + expect(mockFn).not.toHaveBeenCalled(); + }); it('handle the function params ', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - jest.useFakeTimers() + jest.useFakeTimers(); - debounce(mockFn, 100)('test', 1) + debounce(mockFn, 100)('test', 1); - jest.advanceTimersByTime(100) + jest.advanceTimersByTime(100); - expect(mockFn).toHaveBeenLastCalledWith(['test', 1]) - }) + expect(mockFn).toHaveBeenLastCalledWith(['test', 1]); + }); it('runs the function inmediatly if wait is falsy value', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - debounce(mockFn, 0)() + debounce(mockFn, 0)(); - expect(mockFn).toHaveBeenCalled() - }) -}) + expect(mockFn).toHaveBeenCalled(); + }); +}); diff --git a/src/__tests__/elementIsTargetOrTargetChild.test.ts b/src/__tests__/elementIsTargetOrTargetChild.test.ts index 4b1b22b..5037cd8 100644 --- a/src/__tests__/elementIsTargetOrTargetChild.test.ts +++ b/src/__tests__/elementIsTargetOrTargetChild.test.ts @@ -1,45 +1,45 @@ -import elementIsTargetOrTargetChild from '../helpers/elementIsTargetOrTargetChild' +import elementIsTargetOrTargetChild from '../helpers/elementIsTargetOrTargetChild'; describe('elementIsTargetOrTargetChild', () => { it('returns `true` if the element is the same ', () => { - const div = document.createElement('div') + const div = document.createElement('div'); - const relatedTarget: EventTarget = div + const relatedTarget: EventTarget = div; - expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true) - }) + expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true); + }); it('returns `true` if the element is a child of the wrapper ', () => { - const div = document.createElement('div') - const button = document.createElement('button') - const span = document.createElement('span') + const div = document.createElement('div'); + const button = document.createElement('button'); + const span = document.createElement('span'); - div.appendChild(button) - button.appendChild(span) + div.appendChild(button); + button.appendChild(span); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const relatedTarget: EventTarget = div.querySelector('span')! + const relatedTarget: EventTarget = div.querySelector('span')!; - expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true) - }) + expect(elementIsTargetOrTargetChild(relatedTarget, div)).toBe(true); + }); it('returns `false` if the element is not a child of the wrapper ', () => { - const div = document.createElement('div') - const button = document.createElement('button') - const span = document.createElement('span') + const div = document.createElement('div'); + const button = document.createElement('button'); + const span = document.createElement('span'); - div.appendChild(button) - div.appendChild(span) + div.appendChild(button); + div.appendChild(span); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const relatedTarget: EventTarget = div.querySelector('span')! + const relatedTarget: EventTarget = div.querySelector('span')!; - expect(elementIsTargetOrTargetChild(relatedTarget, button)).toBe(false) - }) + expect(elementIsTargetOrTargetChild(relatedTarget, button)).toBe(false); + }); it('returns `false` if the element is null', () => { - const div = document.createElement('div') + const div = document.createElement('div'); - expect(elementIsTargetOrTargetChild(null, div)).toBe(false) - }) -}) + expect(elementIsTargetOrTargetChild(null, div)).toBe(false); + }); +}); diff --git a/src/__tests__/filterOptions.test.ts b/src/__tests__/filterOptions.test.ts index 07e9fa2..2c2dd76 100644 --- a/src/__tests__/filterOptions.test.ts +++ b/src/__tests__/filterOptions.test.ts @@ -1,5 +1,5 @@ -import { filterOptions } from '../index' -import { NormalizedOptions } from '../types' +import { filterOptions } from '../index'; +import { NormalizedOptions } from '../types'; describe('filterOptions', () => { const options: NormalizedOptions = [ @@ -21,15 +21,15 @@ describe('filterOptions', () => { }, { value: 'C', text: 'C' }, { value: 'redy', text: 'Reddy' }, - ] + ]; it('returns the same options is no query', () => { - const filteredOptions = filterOptions(options, '') - expect(filteredOptions).toEqual(options) - }) + const filteredOptions = filterOptions(options, ''); + expect(filteredOptions).toEqual(options); + }); it('filters deep', () => { - const filteredOptions = filterOptions(options, 'red') + const filteredOptions = filterOptions(options, 'red'); expect(filteredOptions).toEqual([ { value: 'B', @@ -43,6 +43,6 @@ describe('filterOptions', () => { ], }, { value: 'redy', text: 'Reddy' }, - ]) - }) -}) + ]); + }); +}); diff --git a/src/__tests__/flattenOptions.test.ts b/src/__tests__/flattenOptions.test.ts index d4bad3d..4e12985 100644 --- a/src/__tests__/flattenOptions.test.ts +++ b/src/__tests__/flattenOptions.test.ts @@ -1,11 +1,11 @@ -import { flattenOptions } from '../index' -import normalizeOptions from '../normalizeOptions' +import { flattenOptions } from '../index'; +import normalizeOptions from '../normalizeOptions'; describe('flattenOptions', () => { it('returns the same array if no deep values', () => { - const options = normalizeOptions([1, 2, 4, 'A', 'B']) - expect(flattenOptions(options)).toEqual(options) - }) + const options = normalizeOptions([1, 2, 4, 'A', 'B']); + expect(flattenOptions(options)).toEqual(options); + }); it('returns the a flattened array of options', () => { const options = normalizeOptions([ @@ -19,16 +19,16 @@ describe('flattenOptions', () => { ], }, { value: 'C', text: 'C' }, - ]) + ]); const expcetedOptions = normalizeOptions([ { value: 'A', text: 'A' }, { value: 1, text: 'Option 1' }, { value: 2, text: 'Option 2' }, { value: 'C', text: 'C' }, - ]) + ]); - expect(flattenOptions(options)).toEqual(expcetedOptions) - }) + expect(flattenOptions(options)).toEqual(expcetedOptions); + }); it('flatten deep options', () => { const options = normalizeOptions([ @@ -49,15 +49,15 @@ describe('flattenOptions', () => { ], }, { value: 'C', text: 'C' }, - ]) + ]); const expcetedOptions = normalizeOptions([ { value: 'A', text: 'A' }, { value: 'red', text: 'Red' }, { value: 'blue', text: 'Blue' }, { value: 2, text: 'Option 2' }, { value: 'C', text: 'C' }, - ]) + ]); - expect(flattenOptions(options)).toEqual(expcetedOptions) - }) -}) + expect(flattenOptions(options)).toEqual(expcetedOptions); + }); +}); diff --git a/src/__tests__/get.test.ts b/src/__tests__/get.test.ts index 9ff6178..62a2c99 100644 --- a/src/__tests__/get.test.ts +++ b/src/__tests__/get.test.ts @@ -1,38 +1,38 @@ -import get from '../helpers/get' +import get from '../helpers/get'; describe('get', () => { it('get the value of an object', () => { const obj = { name: 'Alfonso', - } - expect(get(obj, 'name')).toBe('Alfonso') - }) + }; + expect(get(obj, 'name')).toBe('Alfonso'); + }); it('return the default value if the attribute is not found', () => { const obj = { name: 'Alfonso', - } + }; - const defaultValue = 'default' - expect(get(obj, 'age', defaultValue)).toBe(defaultValue) - }) + const defaultValue = 'default'; + expect(get(obj, 'age', defaultValue)).toBe(defaultValue); + }); it('return undefined if the attribute is not found', () => { const obj = { name: 'Alfonso', - } + }; - expect(get(obj, 'user')).toBeUndefined() - }) + expect(get(obj, 'user')).toBeUndefined(); + }); it('return null if the attribute is null', () => { const obj = { name: 'Alfonso', id: null, - } + }; - expect(get(obj, 'id')).toBeNull() - }) + expect(get(obj, 'id')).toBeNull(); + }); it('return null if the attribute is null deeply within an array', () => { const obj = { @@ -45,10 +45,10 @@ describe('get', () => { id: null, }, ], - } + }; - expect(get(obj, 'roles.1.id')).toBeNull() - }) + expect(get(obj, 'roles.1.id')).toBeNull(); + }); it('return null if the attribute is null deeply', () => { const obj = { @@ -56,28 +56,28 @@ describe('get', () => { role: { id: null, }, - } + }; - expect(get(obj, 'role.id')).toBeNull() - }) + expect(get(obj, 'role.id')).toBeNull(); + }); it('return undefined if the attribute is not found deeply', () => { const obj = { name: 'Alfonso', - } + }; - expect(get(obj, 'name.initials')).toBeUndefined() - }) + expect(get(obj, 'name.initials')).toBeUndefined(); + }); it('return the default value if the attribute is not found deeply', () => { const obj = { name: 'Alfonso', - } + }; - const defaultValue = { default: 'value ' } + const defaultValue = { default: 'value ' }; - expect(get(obj, 'name.initials', defaultValue)).toEqual(defaultValue) - }) + expect(get(obj, 'name.initials', defaultValue)).toEqual(defaultValue); + }); it('get a deep value of an object', () => { const obj = { @@ -89,16 +89,16 @@ describe('get', () => { edit: true, }, }, - } + }; - expect(get(obj, 'role.permissions.edit')).toBe(true) - }) + expect(get(obj, 'role.permissions.edit')).toBe(true); + }); it('get the value of an array by index', () => { - const arr = ['hello', 'world'] + const arr = ['hello', 'world']; - expect(get(arr, '1')).toBe('world') - }) + expect(get(arr, '1')).toBe('world'); + }); it('get the value of an array deeply', () => { const arr = [ @@ -107,10 +107,10 @@ describe('get', () => { ['hello', 'world'], ['hola', 'mundo'], ], - ] + ]; - expect(get(arr, '1.1.1')).toBe('mundo') - }) + expect(get(arr, '1.1.1')).toBe('mundo'); + }); it('get the value of an array inside an object', () => { const obj = { @@ -121,10 +121,10 @@ describe('get', () => { ['hola', 'mundo'], ], ], - } + }; - expect(get(obj, 'arr.1.1.1')).toBe('mundo') - }) + expect(get(obj, 'arr.1.1.1')).toBe('mundo'); + }); it('get the value of an object inside an array', () => { const arr = [ @@ -138,8 +138,8 @@ describe('get', () => { }, ], ], - ] + ]; - expect(get(arr, '1.1.1.name')).toBe('Alfonso') - }) -}) + expect(get(arr, '1.1.1.name')).toBe('Alfonso'); + }); +}); diff --git a/src/__tests__/getFocusableElements.test.ts b/src/__tests__/getFocusableElements.test.ts index 43e7cbd..c697c85 100644 --- a/src/__tests__/getFocusableElements.test.ts +++ b/src/__tests__/getFocusableElements.test.ts @@ -1,129 +1,129 @@ -import elementIsTargetOrTargetChild from '../helpers/getFocusableElements' +import elementIsTargetOrTargetChild from '../helpers/getFocusableElements'; describe('elementIsTargetOrTargetChild', () => { it('returns a link ', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('a') + const focusable = document.createElement('a'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns a button', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('button') + const focusable = document.createElement('button'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns a input', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('input') + const focusable = document.createElement('input'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns a textarea', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('textarea') + const focusable = document.createElement('textarea'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns a select', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('select') + const focusable = document.createElement('select'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns a details', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('details') + const focusable = document.createElement('details'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns a contenteditable div', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('div') - focusable.setAttribute('contenteditable', 'true') + const focusable = document.createElement('div'); + focusable.setAttribute('contenteditable', 'true'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns an element with a tab index of 0', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('div') - focusable.setAttribute('tabindex', '0') + const focusable = document.createElement('div'); + focusable.setAttribute('tabindex', '0'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('returns an element with a positive tab index ', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('div') - focusable.setAttribute('tabindex', '1') + const focusable = document.createElement('div'); + focusable.setAttribute('tabindex', '1'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([focusable]); + }); it('doesnt returns an element with a -1 tab index ', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const focusable = document.createElement('div') - focusable.setAttribute('tabindex', '-1') + const focusable = document.createElement('div'); + focusable.setAttribute('tabindex', '-1'); - el.appendChild(focusable) + el.appendChild(focusable); - expect(elementIsTargetOrTargetChild(el)).toEqual([]) - }) + expect(elementIsTargetOrTargetChild(el)).toEqual([]); + }); it('doesnt return any element that is disabled ', () => { - const el = document.createElement('div') + const el = document.createElement('div'); - const els = ['a', 'button', 'input', 'textarea', 'select', 'details'] + const els = ['a', 'button', 'input', 'textarea', 'select', 'details']; els.forEach((tagName) => { - const focusable = document.createElement(tagName) - focusable.setAttribute('disabled', 'disabled') - el.appendChild(focusable) - }) - - const tabIndex = document.createElement('div') - tabIndex.setAttribute('tabindex', '0') - tabIndex.setAttribute('disabled', 'disabled') - el.appendChild(tabIndex) - - const contentEditable = document.createElement('div') - contentEditable.setAttribute('contenteditable', 'true') - contentEditable.setAttribute('tabindex', '0') - contentEditable.setAttribute('disabled', 'disabled') - el.appendChild(contentEditable) - - expect(elementIsTargetOrTargetChild(el).length).toBe(0) - }) -}) + const focusable = document.createElement(tagName); + focusable.setAttribute('disabled', 'disabled'); + el.appendChild(focusable); + }); + + const tabIndex = document.createElement('div'); + tabIndex.setAttribute('tabindex', '0'); + tabIndex.setAttribute('disabled', 'disabled'); + el.appendChild(tabIndex); + + const contentEditable = document.createElement('div'); + contentEditable.setAttribute('contenteditable', 'true'); + contentEditable.setAttribute('tabindex', '0'); + contentEditable.setAttribute('disabled', 'disabled'); + el.appendChild(contentEditable); + + expect(elementIsTargetOrTargetChild(el).length).toBe(0); + }); +}); diff --git a/src/__tests__/hasProperty.test.ts b/src/__tests__/hasProperty.test.ts index 0dcad29..5bd3ea7 100644 --- a/src/__tests__/hasProperty.test.ts +++ b/src/__tests__/hasProperty.test.ts @@ -1,43 +1,43 @@ -import hasProperty from '../helpers/hasProperty' +import hasProperty from '../helpers/hasProperty'; describe('hasProperty', () => { it('returns `true` if the object has the property ', () => { const obj = { foo: 'bar', - } + }; - expect(hasProperty(obj, 'foo')).toBe(true) - }) + expect(hasProperty(obj, 'foo')).toBe(true); + }); it('returns `true` if the object has the property even when it is null ', () => { const obj = { foo: null, - } + }; - expect(hasProperty(obj, 'foo')).toBe(true) - }) + expect(hasProperty(obj, 'foo')).toBe(true); + }); it('returns `true` if the object has the property even when it is `undefined` ', () => { const obj = { foo: undefined, - } + }; - expect(hasProperty(obj, 'foo')).toBe(true) - }) + expect(hasProperty(obj, 'foo')).toBe(true); + }); it('returns `false` if the object doesnt have the property ', () => { const obj = { bar: 'foo', - } + }; - expect(hasProperty(obj, 'foo')).toBe(false) - }) + expect(hasProperty(obj, 'foo')).toBe(false); + }); it('returns `false` if undefined object ', () => { - expect(hasProperty(undefined, 'foo')).toBe(false) - }) + expect(hasProperty(undefined, 'foo')).toBe(false); + }); it('returns `false` if passes `null`', () => { - expect(hasProperty(null, 'foo')).toBe(false) - }) -}) + expect(hasProperty(null, 'foo')).toBe(false); + }); +}); diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 4429563..0100f81 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -1,43 +1,43 @@ -import * as helpers from '../helpers/index' -import * as dateHelpers from '../dates/index' +import * as helpers from '../helpers/index'; +import * as dateHelpers from '../dates/index'; it('exports all the helpers', () => { - expect(Object.keys(helpers).length).toBe(17) + expect(Object.keys(helpers).length).toBe(17); - expect(typeof helpers.get).toBe('function') - expect(typeof helpers.pick).toBe('function') - expect(typeof helpers.clone).toBe('function') - expect(typeof helpers.isPrimitive).toBe('function') - expect(typeof helpers.isEqual).toBe('function') - expect(typeof helpers.hasProperty).toBe('function') - expect(typeof helpers.debounce).toBe('function') - expect(typeof helpers.throttle).toBe('function') - expect(typeof helpers.addToArray).toBe('function') - expect(typeof helpers.substractFromArray).toBe('function') - expect(typeof helpers.elementIsTargetOrTargetChild).toBe('function') - expect(typeof helpers.getFocusableElements).toBe('function') - expect(typeof helpers.isTouchOnlyDevice).toBe('function') - expect(typeof helpers.normalizeMeasure).toBe('function') - expect(typeof helpers.normalizedOptionIsDisabled).toBe('function') - expect(typeof helpers.promisify).toBe('function') - expect(typeof helpers.promisifyFunctionResult).toBe('function') -}) + expect(typeof helpers.get).toBe('function'); + expect(typeof helpers.pick).toBe('function'); + expect(typeof helpers.clone).toBe('function'); + expect(typeof helpers.isPrimitive).toBe('function'); + expect(typeof helpers.isEqual).toBe('function'); + expect(typeof helpers.hasProperty).toBe('function'); + expect(typeof helpers.debounce).toBe('function'); + expect(typeof helpers.throttle).toBe('function'); + expect(typeof helpers.addToArray).toBe('function'); + expect(typeof helpers.substractFromArray).toBe('function'); + expect(typeof helpers.elementIsTargetOrTargetChild).toBe('function'); + expect(typeof helpers.getFocusableElements).toBe('function'); + expect(typeof helpers.isTouchOnlyDevice).toBe('function'); + expect(typeof helpers.normalizeMeasure).toBe('function'); + expect(typeof helpers.normalizedOptionIsDisabled).toBe('function'); + expect(typeof helpers.promisify).toBe('function'); + expect(typeof helpers.promisifyFunctionResult).toBe('function'); +}); it('exports all the date-related helpers', () => { - expect(Object.keys(dateHelpers).length).toBe(14) + expect(Object.keys(dateHelpers).length).toBe(14); - expect(typeof dateHelpers.dateEnglishLocale).toBe('object') - expect(typeof dateHelpers.visibleDaysInMonthView).toBe('function') - expect(typeof dateHelpers.isSameDay).toBe('function') - expect(typeof dateHelpers.isSameMonth).toBe('function') - expect(typeof dateHelpers.isToday).toBe('function') - expect(typeof dateHelpers.addDays).toBe('function') - expect(typeof dateHelpers.addMonths).toBe('function') - expect(typeof dateHelpers.addYears).toBe('function') - expect(typeof dateHelpers.dateIsPartOfTheRange).toBe('function') - expect(typeof dateHelpers.dayIsPartOfTheConditions).toBe('function') - expect(typeof dateHelpers.parseDate).toBe('function') - expect(typeof dateHelpers.formatDate).toBe('function') - expect(typeof dateHelpers.buildDateParser).toBe('function') - expect(typeof dateHelpers.buildDateFormatter).toBe('function') -}) + expect(typeof dateHelpers.dateEnglishLocale).toBe('object'); + expect(typeof dateHelpers.visibleDaysInMonthView).toBe('function'); + expect(typeof dateHelpers.isSameDay).toBe('function'); + expect(typeof dateHelpers.isSameMonth).toBe('function'); + expect(typeof dateHelpers.isToday).toBe('function'); + expect(typeof dateHelpers.addDays).toBe('function'); + expect(typeof dateHelpers.addMonths).toBe('function'); + expect(typeof dateHelpers.addYears).toBe('function'); + expect(typeof dateHelpers.dateIsPartOfTheRange).toBe('function'); + expect(typeof dateHelpers.dayIsPartOfTheConditions).toBe('function'); + expect(typeof dateHelpers.parseDate).toBe('function'); + expect(typeof dateHelpers.formatDate).toBe('function'); + expect(typeof dateHelpers.buildDateParser).toBe('function'); + expect(typeof dateHelpers.buildDateFormatter).toBe('function'); +}); diff --git a/src/__tests__/isEqual.test.ts b/src/__tests__/isEqual.test.ts index 5f2ccf2..4401051 100644 --- a/src/__tests__/isEqual.test.ts +++ b/src/__tests__/isEqual.test.ts @@ -1,69 +1,69 @@ -import isEqual from '../helpers/isEqual' +import isEqual from '../helpers/isEqual'; describe('isEqual', () => { it('considers that a number is not equal to a string', () => { - expect(isEqual('12', 12)).toBe(false) - }) + expect(isEqual('12', 12)).toBe(false); + }); it('considers that a number is equal to the same number', () => { - expect(isEqual(12, 12)).toBe(true) - }) + expect(isEqual(12, 12)).toBe(true); + }); it('considers that a numeric string is equal to the same numeric string', () => { - expect(isEqual('12', '12')).toBe(true) - }) + expect(isEqual('12', '12')).toBe(true); + }); it('considers that a regular string is equal to the same regular string', () => { - expect(isEqual('Hello World! 🤨', 'Hello World! 🤨')).toBe(true) - }) + expect(isEqual('Hello World! 🤨', 'Hello World! 🤨')).toBe(true); + }); it('considers that an empty array is equal to another empty array', () => { - expect(isEqual([], [])).toBe(true) - }) + expect(isEqual([], [])).toBe(true); + }); it('considers that an array with same values to be equal', () => { expect( - isEqual([1, '12', 'string', true, undefined], [1, '12', 'string', true, undefined]) - ).toBe(true) - }) + isEqual([1, '12', 'string', true, undefined], [1, '12', 'string', true, undefined]), + ).toBe(true); + }); it('considers that an array with same values in different order to no be equal', () => { expect( - isEqual([1, '12', 'string', true, undefined], ['12', 1, 'string', true, undefined]) - ).toBe(false) - }) + isEqual([1, '12', 'string', true, undefined], ['12', 1, 'string', true, undefined]), + ).toBe(false); + }); it('considers that `undefined` is equal to `undefined`', () => { - expect(isEqual(undefined, undefined)).toBe(true) - }) + expect(isEqual(undefined, undefined)).toBe(true); + }); it('considers that `null` is equal to `null`', () => { - expect(isEqual(null, null)).toBe(true) - }) + expect(isEqual(null, null)).toBe(true); + }); it('considers that `NaN` is equal to `NaN`', () => { - expect(isEqual(NaN, NaN)).toBe(true) - }) + expect(isEqual(NaN, NaN)).toBe(true); + }); it('considers that `undefined` is different to `null`', () => { - expect(isEqual(undefined, null)).toBe(false) - }) + expect(isEqual(undefined, null)).toBe(false); + }); it('considers that `null` is different to an empty string', () => { - expect(isEqual('', null)).toBe(false) - }) + expect(isEqual('', null)).toBe(false); + }); it('considers that `true` is equal to `true`', () => { - expect(isEqual(true, true)).toBe(true) - }) + expect(isEqual(true, true)).toBe(true); + }); it('considers that `false` is equal to `false`', () => { - expect(isEqual(false, false)).toBe(true) - }) + expect(isEqual(false, false)).toBe(true); + }); it('considers that `false` is different to `false`', () => { - expect(isEqual(true, false)).toBe(false) - }) + expect(isEqual(true, false)).toBe(false); + }); it('considers that an object with same properties is equal', () => { const a = { @@ -72,7 +72,7 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - } + }; const b = { a: 1, @@ -80,10 +80,10 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - } + }; - expect(isEqual(a, b)).toBe(true) - }) + expect(isEqual(a, b)).toBe(true); + }); it('considers that an object with a different property is not equal', () => { const a = { @@ -92,7 +92,7 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - } + }; const b = { a: '1', @@ -100,10 +100,10 @@ describe('isEqual', () => { 'some-propery': 'some-value', 'other-value': undefined, oneMore: null, - } + }; - expect(isEqual(a, b)).toBe(false) - }) + expect(isEqual(a, b)).toBe(false); + }); it('makes a deep comparison', () => { const a = [ @@ -120,7 +120,7 @@ describe('isEqual', () => { null, [], { a: 1, b: 2, c: 3 }, - ] + ]; const b = [ undefined, @@ -136,10 +136,10 @@ describe('isEqual', () => { null, [], { a: 1, b: 2, c: 3 }, - ] + ]; - expect(isEqual(a, b)).toBe(true) - }) + expect(isEqual(a, b)).toBe(true); + }); it('makes a deep comparison for something that is not equal', () => { const a = [ @@ -156,7 +156,7 @@ describe('isEqual', () => { null, [], { a: 1, b: 2, c: 3 }, - ] + ]; const b = [ undefined, @@ -173,8 +173,8 @@ describe('isEqual', () => { null, [], { a: 1, b: 2, c: 3 }, - ] + ]; - expect(isEqual(a, b)).toBe(false) - }) -}) + expect(isEqual(a, b)).toBe(false); + }); +}); diff --git a/src/__tests__/isPrimitive.test.ts b/src/__tests__/isPrimitive.test.ts index 6735d18..0c7d1fa 100644 --- a/src/__tests__/isPrimitive.test.ts +++ b/src/__tests__/isPrimitive.test.ts @@ -1,38 +1,38 @@ -import isPrimitive from '../helpers/isPrimitive' +import isPrimitive from '../helpers/isPrimitive'; describe('isPrimitive', () => { it('detects null as primitive', () => { - expect(isPrimitive(null)).toBe(true) - }) + expect(isPrimitive(null)).toBe(true); + }); it('detects number as primitive', () => { - expect(isPrimitive(1)).toBe(true) - }) + expect(isPrimitive(1)).toBe(true); + }); it('detects string as primitive', () => { - expect(isPrimitive('a string')).toBe(true) - }) + expect(isPrimitive('a string')).toBe(true); + }); it('detects boolean as primitive', () => { - expect(isPrimitive(true)).toBe(true) - }) + expect(isPrimitive(true)).toBe(true); + }); it('detects undefined as primitive', () => { - expect(isPrimitive(undefined)).toBe(true) - }) + expect(isPrimitive(undefined)).toBe(true); + }); it('detects symbol as primitive', () => { - expect(isPrimitive(Symbol('foo'))).toBe(true) - }) + expect(isPrimitive(Symbol('foo'))).toBe(true); + }); it('detects an object as not primitive', () => { - expect(isPrimitive({})).toBe(false) - }) + expect(isPrimitive({})).toBe(false); + }); it('detects a function as not primitive', () => { - expect(isPrimitive(() => {})).toBe(false) - }) + expect(isPrimitive(() => {})).toBe(false); + }); it('detects an array as not primitive', () => { - expect(isPrimitive([])).toBe(false) - }) -}) + expect(isPrimitive([])).toBe(false); + }); +}); diff --git a/src/__tests__/isTouchOnlyDevice.test.ts b/src/__tests__/isTouchOnlyDevice.test.ts index 7c10072..0fd1a14 100644 --- a/src/__tests__/isTouchOnlyDevice.test.ts +++ b/src/__tests__/isTouchOnlyDevice.test.ts @@ -1,4 +1,4 @@ -import isTouchOnlyDevice from '../helpers/isTouchOnlyDevice' +import isTouchOnlyDevice from '../helpers/isTouchOnlyDevice'; describe('isTouchOnlyDevice.', () => { it('returns `true` if matchMedia return matches', () => { @@ -7,9 +7,9 @@ describe('isTouchOnlyDevice.', () => { matchMedia: () => ({ matches: true, }), - } - expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(true) - }) + }; + expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(true); + }); it('returns `true` if matchMedia doesnt return matches', () => { const windowMock = { @@ -17,20 +17,20 @@ describe('isTouchOnlyDevice.', () => { matchMedia: () => ({ matches: false, }), - } - expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(false) - }) + }; + expect(isTouchOnlyDevice(windowMock as unknown as Window)).toBe(false); + }); it('uses the global window and navigator by default', () => { - expect(isTouchOnlyDevice()).toBe(false) - }) + expect(isTouchOnlyDevice()).toBe(false); + }); it('returns `false` if window is not defined', () => { - const windowSpy = jest.spyOn(window, 'window', 'get') - windowSpy.mockImplementation(() => undefined as unknown as Window & typeof globalThis) + const windowSpy = jest.spyOn(window, 'window', 'get'); + windowSpy.mockImplementation(() => undefined as unknown as Window & typeof globalThis); - expect(isTouchOnlyDevice()).toBe(false) + expect(isTouchOnlyDevice()).toBe(false); - windowSpy.mockRestore() - }) -}) + windowSpy.mockRestore(); + }); +}); diff --git a/src/__tests__/mergeClasses.test.ts b/src/__tests__/mergeClasses.test.ts index c4dff0b..ef3bbd2 100644 --- a/src/__tests__/mergeClasses.test.ts +++ b/src/__tests__/mergeClasses.test.ts @@ -1,37 +1,37 @@ -import { mergeClasses } from '../index' +import { mergeClasses } from '../index'; describe('merge classes function', () => { it('merges two string classes', () => { - expect(mergeClasses('hello', 'world')).toBe('hello world') - }) + expect(mergeClasses('hello', 'world')).toBe('hello world'); + }); it('accepts undefined values', () => { - expect(mergeClasses('hello', undefined)).toBe('hello') - }) + expect(mergeClasses('hello', undefined)).toBe('hello'); + }); it('merges two array classes', () => { - expect(mergeClasses(['hello'], ['world'])).toBe('hello world') - }) + expect(mergeClasses(['hello'], ['world'])).toBe('hello world'); + }); it('allows functions that can manipulate the classes interactively', () => { expect( mergeClasses( ['hello'], ({ clear, add }) => { - clear() - add('no') + clear(); + add('no'); }, ['world'], ({ remove }) => { - remove('world') - } - ) - ).toBe('no') - }) + remove('world'); + }, + ), + ).toBe('no'); + }); it('does not allowe duplicates', () => { - expect(mergeClasses(['hello'], ['hello'])).toBe('hello') - }) + expect(mergeClasses(['hello'], ['hello'])).toBe('hello'); + }); it('merges the truthy values from an object format', () => { expect( @@ -43,8 +43,9 @@ describe('merge classes function', () => { { world: 1, universe: null, - } as unknown - ) - ).toBe('hello world') - }) -}) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any, + ), + ).toBe('hello world'); + }); +}); diff --git a/src/__tests__/normalizeMeasure.test.ts b/src/__tests__/normalizeMeasure.test.ts index b19e1b5..f2ab2e6 100644 --- a/src/__tests__/normalizeMeasure.test.ts +++ b/src/__tests__/normalizeMeasure.test.ts @@ -1,35 +1,35 @@ -import normalizeMeasure from '../helpers/normalizeMeasure' +import normalizeMeasure from '../helpers/normalizeMeasure'; describe('normalizeMeasure', () => { it('converts a number into px', () => { - expect(normalizeMeasure(12)).toBe('12px') - }) + expect(normalizeMeasure(12)).toBe('12px'); + }); it('converts a decimal into px', () => { - expect(normalizeMeasure(12.34)).toBe('12.34px') - }) + expect(normalizeMeasure(12.34)).toBe('12.34px'); + }); it('keeps the amount in px as it is ', () => { - expect(normalizeMeasure('12.34px')).toBe('12.34px') - }) + expect(normalizeMeasure('12.34px')).toBe('12.34px'); + }); it('converts a numeric string to px', () => { - expect(normalizeMeasure('1234')).toBe('1234px') - }) + expect(normalizeMeasure('1234')).toBe('1234px'); + }); it('converts a numeric string with decimals px', () => { - expect(normalizeMeasure('12.34')).toBe('12.34px') - }) + expect(normalizeMeasure('12.34')).toBe('12.34px'); + }); it('keeps any random string as it is', () => { - expect(normalizeMeasure('123,456')).toBe('123,456') - }) + expect(normalizeMeasure('123,456')).toBe('123,456'); + }); it('keeps undefined values ', () => { - expect(normalizeMeasure(undefined)).toBe(undefined) - }) + expect(normalizeMeasure(undefined)).toBe(undefined); + }); it('converts a null value to undefined ', () => { - expect(normalizeMeasure(null)).toBe(undefined) - }) -}) + expect(normalizeMeasure(null)).toBe(undefined); + }); +}); diff --git a/src/__tests__/normalizeOptions.test.ts b/src/__tests__/normalizeOptions.test.ts index 0f52dcc..2e10e8a 100644 --- a/src/__tests__/normalizeOptions.test.ts +++ b/src/__tests__/normalizeOptions.test.ts @@ -1,37 +1,37 @@ -import { normalizeOptions } from '../index' -import { InputOptions, NormalizedOptions } from '../types' +import { normalizeOptions } from '../index'; +import { InputOptions, NormalizedOptions } from '../types'; describe('options as strings', () => { it('returns an empty array if no value', () => { - expect(normalizeOptions()).toEqual([]) - }) + expect(normalizeOptions()).toEqual([]); + }); it('accepts the options as array of strings', () => { - const options: InputOptions = ['Option A', 'Option B', 'Option C'] + const options: InputOptions = ['Option A', 'Option B', 'Option C']; const expectedOptions: NormalizedOptions = [ { value: 'Option A', text: 'Option A', raw: 'Option A' }, { value: 'Option B', text: 'Option B', raw: 'Option B' }, { value: 'Option C', text: 'Option C', raw: 'Option C' }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) -}) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); +}); describe('options as numbers', () => { it('accepts the options as array of numbers', () => { - const options: InputOptions = [1, 2, 5] + const options: InputOptions = [1, 2, 5]; const expectedOptions: NormalizedOptions = [ { value: 1, text: 1, raw: 1 }, { value: 2, text: 2, raw: 2 }, { value: 5, text: 5, raw: 5 }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) -}) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); +}); describe('options as key => value pair', () => { it('accepts the options as key => value pair', () => { @@ -39,17 +39,17 @@ describe('options as key => value pair', () => { 1: 'Option 1', A: 'Option A', 'Option 3': 'Option 3', - } + }; const expectedOptions: NormalizedOptions = [ { value: '1', text: 'Option 1' }, { value: 'A', text: 'Option A' }, { value: 'Option 3', text: 'Option 3' }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) -}) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); +}); describe('options as array of objects', () => { it('accepts the options on the default format', () => { @@ -57,23 +57,23 @@ describe('options as array of objects', () => { { value: 1, text: 'Option 1' }, { value: 'A', text: 'Option A' }, { value: 'Option 3', text: 'Option 3' }, - ] + ]; const expectedOptions: NormalizedOptions = [ { value: 1, text: 'Option 1', raw: { value: 1, text: 'Option 1' } }, { value: 'A', text: 'Option A', raw: { value: 'A', text: 'Option A' } }, { value: 'Option 3', text: 'Option 3', raw: { value: 'Option 3', text: 'Option 3' } }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); it('handles the disabled attribute', () => { const options: InputOptions = [ { value: '1', text: 'Option 1' }, { value: 'A', text: 'Option A', disabled: true }, { value: 'Option 3', text: 'Option 3', disabled: false }, - ] + ]; const expectedOptions: NormalizedOptions = [ { value: '1', text: 'Option 1', raw: { value: '1', text: 'Option 1' } }, @@ -88,11 +88,11 @@ describe('options as array of objects', () => { text: 'Option 3', raw: { value: 'Option 3', text: 'Option 3', disabled: false }, }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) -}) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); +}); describe('options with children', () => { it('handles the children in default format', () => { @@ -105,7 +105,7 @@ describe('options with children', () => { { value: 2, text: 'Children 2' }, ], }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -117,10 +117,10 @@ describe('options with children', () => { ], raw: options[0], }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); it('handles the children as arrays of strings', () => { const options = [ @@ -129,7 +129,7 @@ describe('options with children', () => { text: 'Option A', children: ['Children 1', 'Children 2'], }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -141,10 +141,10 @@ describe('options with children', () => { ], raw: options[0], }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); it('handles the children as arrays of numbers', () => { const options = [ @@ -153,7 +153,7 @@ describe('options with children', () => { text: 'Option A', children: [1, 2, 3], }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -166,10 +166,10 @@ describe('options with children', () => { ], raw: options[0], }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); it('handles the children as value => key pair', () => { const options = [ @@ -181,7 +181,7 @@ describe('options with children', () => { A: 'Option A', }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -193,11 +193,11 @@ describe('options with children', () => { ], raw: options[0], }, - ] + ]; - expect(normalizeOptions(options)).toEqual(expectedOptions) - }) -}) + expect(normalizeOptions(options)).toEqual(expectedOptions); + }); +}); describe('guess option and values', () => { it('get the text with the `textAttribute` param', () => { @@ -210,7 +210,7 @@ describe('guess option and values', () => { value: 'B', label: 'Option B', }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -223,10 +223,10 @@ describe('guess option and values', () => { text: 'Option B', raw: options[1], }, - ] + ]; - expect(normalizeOptions(options, 'label')).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, 'label')).toEqual(expectedOptions); + }); it('get the text with the `textAttribute` param using dot notation', () => { const options = [ @@ -250,7 +250,7 @@ describe('guess option and values', () => { }, }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -263,12 +263,12 @@ describe('guess option and values', () => { text: 'User', raw: options[1], }, - ] + ]; - const textAttribute = 'user.role.label' + const textAttribute = 'user.role.label'; - expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions); + }); it('returns an empty string if the `textAttribute` param doesnt exist', () => { const options = [ @@ -284,7 +284,7 @@ describe('guess option and values', () => { name: 'Sauda', }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -297,12 +297,12 @@ describe('guess option and values', () => { text: '', raw: options[1], }, - ] + ]; - const textAttribute = 'user.role.label' + const textAttribute = 'user.role.label'; - expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions); + }); it('returns the text as an string if the text attribute is not `number` or `string`', () => { const options = [ @@ -326,7 +326,7 @@ describe('guess option and values', () => { }, }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -339,12 +339,12 @@ describe('guess option and values', () => { text: '[object Object]', raw: options[1], }, - ] + ]; - const textAttribute = 'user.role.label' + const textAttribute = 'user.role.label'; - expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, textAttribute)).toEqual(expectedOptions); + }); it('get the value with the `valueAttribute` param', () => { const options = [ @@ -356,7 +356,7 @@ describe('guess option and values', () => { id: 'B', text: 'Option B', }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -369,10 +369,10 @@ describe('guess option and values', () => { text: 'Option B', raw: options[1], }, - ] + ]; - expect(normalizeOptions(options, undefined, 'id')).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, undefined, 'id')).toEqual(expectedOptions); + }); it('get the value with the `valueAttribute` param using dot notation', () => { const options = [ @@ -396,7 +396,7 @@ describe('guess option and values', () => { }, }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -409,12 +409,12 @@ describe('guess option and values', () => { text: 'B', raw: options[1], }, - ] + ]; - const valueAttribute = 'user.role.id' + const valueAttribute = 'user.role.id'; - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); + }); it('returns an `undefined` if the `valueAttribute` param doesnt exist', () => { const options = [ @@ -430,7 +430,7 @@ describe('guess option and values', () => { role: 'user', }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -443,12 +443,12 @@ describe('guess option and values', () => { text: 'Saida', raw: options[1], }, - ] + ]; - const valueAttribute = 'user.role.id' + const valueAttribute = 'user.role.id'; - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); + }); it('returns `null` as value if the `valueAttribute` param is `null`', () => { const options = [ @@ -466,7 +466,7 @@ describe('guess option and values', () => { role: 'user', }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -479,12 +479,12 @@ describe('guess option and values', () => { text: 'Saida', raw: options[1], }, - ] + ]; - const valueAttribute = 'user.id' + const valueAttribute = 'user.id'; - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) - }) + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); + }); it('returns the value as an string if the value attribute is not `number` or `string`', () => { const options = [ @@ -508,7 +508,7 @@ describe('guess option and values', () => { }, }, }, - ] + ]; const expectedOptions: NormalizedOptions = [ { @@ -521,10 +521,10 @@ describe('guess option and values', () => { value: '[object Object]', raw: options[1], }, - ] + ]; - const valueAttribute = 'user.role.label' + const valueAttribute = 'user.role.label'; - expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions) - }) -}) + expect(normalizeOptions(options, undefined, valueAttribute)).toEqual(expectedOptions); + }); +}); diff --git a/src/__tests__/normalizedOptionIsDisabled.test.ts b/src/__tests__/normalizedOptionIsDisabled.test.ts index 8537027..3c83f57 100644 --- a/src/__tests__/normalizedOptionIsDisabled.test.ts +++ b/src/__tests__/normalizedOptionIsDisabled.test.ts @@ -1,5 +1,5 @@ -import { NormalizedOption } from '..' -import normalizedOptionIsDisabled from '../helpers/normalizedOptionIsDisabled' +import { NormalizedOption } from '..'; +import normalizedOptionIsDisabled from '../helpers/normalizedOptionIsDisabled'; describe('normalizedOptionIsDisabled', () => { it('option disabled attribute is "disabled" returns true ', () => { @@ -7,35 +7,35 @@ describe('normalizedOptionIsDisabled', () => { value: 'value', text: 'text', disabled: 'disabled', - } + }; - expect(normalizedOptionIsDisabled(option)).toBe(true) - }) + expect(normalizedOptionIsDisabled(option)).toBe(true); + }); it('option disabled attribute is `true` returns true ', () => { const option: NormalizedOption = { value: 'value', text: 'text', disabled: true, - } + }; - expect(normalizedOptionIsDisabled(option)).toBe(true) - }) + expect(normalizedOptionIsDisabled(option)).toBe(true); + }); it('option disabled attribute is `false` returns false ', () => { const option: NormalizedOption = { value: 'value', text: 'text', disabled: false, - } + }; - expect(normalizedOptionIsDisabled(option)).toBe(false) - }) + expect(normalizedOptionIsDisabled(option)).toBe(false); + }); it('option doesnt have disabled attribute returns false ', () => { const option: NormalizedOption = { value: 'value', text: 'text', - } + }; - expect(normalizedOptionIsDisabled(option)).toBe(false) - }) -}) + expect(normalizedOptionIsDisabled(option)).toBe(false); + }); +}); diff --git a/src/__tests__/parseVariant.test.ts b/src/__tests__/parseVariant.test.ts index 9943d9c..7095bb2 100644 --- a/src/__tests__/parseVariant.test.ts +++ b/src/__tests__/parseVariant.test.ts @@ -1,13 +1,13 @@ -import { parseVariant } from '../index' +import { parseVariant } from '../index'; describe('parse variants function', () => { it('returns the same object if no variants passed', () => { const props = { class: 'text-red-500', type: 'number', - } - expect(parseVariant(props)).toEqual(props) - }) + }; + expect(parseVariant(props)).toEqual(props); + }); it('returns the variant props if a variant is added', () => { const props = { @@ -20,24 +20,24 @@ describe('parse variants function', () => { }, }, variant: 'alt', - } - expect(parseVariant(props)).toEqual(props.variants.alt) - }) + }; + expect(parseVariant(props)).toEqual(props.variants.alt); + }); it('returns the default configuration', () => { - const props = {} - const globalConfiguration = {} + const props = {}; + const globalConfiguration = {}; const defaultConfiguration = { type: 'text', fixedClasses: 'border p-3', classes: 'text-red-500', - } + }; expect(parseVariant(props, globalConfiguration, defaultConfiguration)).toEqual({ type: 'text', class: 'text-red-500 border p-3', - }) - }) + }); + }); it('merge the variant props with the default props', () => { const props = { @@ -51,34 +51,34 @@ describe('parse variants function', () => { }, }, variant: 'alt', - } + }; expect(parseVariant(props)).toEqual({ ...props.variants.alt, ...{ placeholder: props.placeholder, }, - }) - }) + }); + }); it('use the props over the configuration', () => { const props = { class: 'text-red-500', type: 'number', placeholder: 'Hello world', - } + }; const configuration = { class: 'text-blue-500', - } + }; - expect(parseVariant(props, configuration)).toEqual(props) - }) + expect(parseVariant(props, configuration)).toEqual(props); + }); it('use the variant from the configuration', () => { const props = { variant: 'alt', - } + }; const configuration = { class: 'text-blue-500', @@ -88,40 +88,40 @@ describe('parse variants function', () => { type: 'text', }, }, - } + }; - expect(parseVariant(props, configuration)).toEqual(configuration.variants.alt) - }) + expect(parseVariant(props, configuration)).toEqual(configuration.variants.alt); + }); it('use the configuration if no props sent', () => { - const props = {} + const props = {}; const configuration = { class: 'text-blue-500', type: 'text', - } + }; - expect(parseVariant(props, configuration)).toEqual(configuration) - }) + expect(parseVariant(props, configuration)).toEqual(configuration); + }); it('doesnt return the className if class is empty', () => { const props = { class: undefined, type: 'text', - } + }; - expect(parseVariant(props)).not.toHaveProperty('className') - }) + expect(parseVariant(props)).not.toHaveProperty('className'); + }); it('merges className, classes and fixedClasses', () => { const props = { class: 'text-red-500', classes: ['border-red-500'], fixedClasses: { 'border-2': true }, - } + }; - expect(parseVariant(props).class).toBe('text-red-500 border-red-500 border-2') - }) + expect(parseVariant(props).class).toBe('text-red-500 border-red-500 border-2'); + }); it('merges className, fixedClasses and variant classes', () => { const props = { @@ -134,10 +134,10 @@ describe('parse variants function', () => { }, }, variant: 'alt', - } + }; - expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border-2') - }) + expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border-2'); + }); it('merges className and variant fixedClasses and classes', () => { const props = { @@ -151,15 +151,15 @@ describe('parse variants function', () => { }, }, variant: 'alt', - } + }; - expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border') - }) + expect(parseVariant(props).class).toBe('text-red-500 border-blue-500 border'); + }); it('uses the classes from the configuration', () => { const props = { variant: 'error', - } + }; const configuration = { classes: 'text-black', @@ -168,8 +168,8 @@ describe('parse variants function', () => { classes: 'text-red-500', }, }, - } + }; - expect(parseVariant(props, configuration).class).toBe('text-red-500') - }) -}) + expect(parseVariant(props, configuration).class).toBe('text-red-500'); + }); +}); diff --git a/src/__tests__/parseVariantWithClassesList.test.ts b/src/__tests__/parseVariantWithClassesList.test.ts index 827f36e..37f4674 100644 --- a/src/__tests__/parseVariantWithClassesList.test.ts +++ b/src/__tests__/parseVariantWithClassesList.test.ts @@ -1,15 +1,15 @@ -import { parseVariantWithClassesList } from '../index' -import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types' +import { parseVariantWithClassesList } from '../index'; +import { CSSClass, ObjectWithClassesList, WithVariantPropsAndClassesList } from '../types'; describe('parse variants with classes list function', () => { it('returns the same object if no variants passed', () => { const props = { class: 'text-red-500', type: 'number', - } + }; - expect(parseVariantWithClassesList(props, [])).toEqual(props) - }) + expect(parseVariantWithClassesList(props, [])).toEqual(props); + }); it('returns the variant props if a variant is added', () => { const props = { @@ -22,13 +22,13 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - } - expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt) - }) + }; + expect(parseVariantWithClassesList(props, [])).toEqual(props.variants.alt); + }); it('returns the default configuration', () => { - const props = {} - const globalConfiguration = {} + const props = {}; + const globalConfiguration = {}; const defaultConfiguration = { type: 'text', fixedClasses: { @@ -37,20 +37,20 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }) - }) + }); + }); it('returns the global configuration', () => { - const props = {} + const props = {}; const globalConfiguration = { type: 'text', fixedClasses: { @@ -59,7 +59,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; const defaultConfiguration = { type: 'button', @@ -69,17 +69,17 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-blue-500', }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'text', classesList: { wrapper: 'text-red-500 border p-3', }, - }) - }) + }); + }); it('returns the prop configuration from the variant', () => { const props = { @@ -95,7 +95,7 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; const globalConfiguration = { type: 'text', @@ -105,7 +105,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; const defaultConfiguration = { variants: { @@ -119,22 +119,22 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }) - }) + }); + }); it('returns the global configuration from the variant', () => { const props = { variant: 'error', - } + }; const globalConfiguration = { type: 'text', @@ -155,7 +155,7 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; const defaultConfiguration = { variants: { @@ -169,22 +169,22 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }) - }) + }); + }); it('returns the default configuration from the variant', () => { const props = { variant: 'error', - } + }; const globalConfiguration = { type: 'text', fixedClasses: { @@ -193,7 +193,7 @@ describe('parse variants with classes list function', () => { classes: { wrapper: 'text-red-500', }, - } + }; const defaultConfiguration = { variants: { @@ -207,17 +207,17 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper'], globalConfiguration, defaultConfiguration), ).toEqual({ type: 'button', classesList: { wrapper: 'text-blue-500 p-2', }, - }) - }) + }); + }); it('merge the variant props with the default props', () => { const props = { @@ -231,55 +231,55 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - } + }; expect(parseVariantWithClassesList(props, [])).toEqual({ ...props.variants.alt, ...{ placeholder: props.placeholder, }, - }) - }) + }); + }); it('use the props over the configuration', () => { const props = { class: 'text-red-500', type: 'number', placeholder: 'Hello world', - } + }; const configuration = { class: 'text-blue-500', - } + }; - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props) - }) + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(props); + }); it('respects the props for classes list', () => { const props: CSSClass = { classes: { wrapper: 'm-3', body: ({ clear, add }) => { - clear() - add('text-gray-500') + clear(); + add('text-gray-500'); }, }, - } + }; const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { wrapper: 'p-4 m-3', body: 'text-gray-500', }, - }) - }) + }); + }); it('respects only the props defined from the configuration', () => { const props = { @@ -287,14 +287,14 @@ describe('parse variants with classes list function', () => { wrapper: 'm-3', inner: 'p-2', }, - } + }; const configuration = { classes: { wrapper: 'p-4', body: 'text-red-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ classesList: { @@ -302,8 +302,8 @@ describe('parse variants with classes list function', () => { wrapper: 'p-4 m-3', inner: undefined, }, - }) - }) + }); + }); it('accepts undefined values', () => { const props = { @@ -311,58 +311,58 @@ describe('parse variants with classes list function', () => { wrapper: undefined, body: 'text-gray-500', }, - } + }; const configuration = { classes: { wrapper: 'p-4', body: 'bg-red-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], {}, configuration)).toEqual({ classesList: { wrapper: undefined, body: 'bg-red-500 text-gray-500', }, - }) - }) + }); + }); it('pass `undefined` in the classes props clear any value', () => { const props = { classes: undefined, - } + }; const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('pass `undefined` in the fixedClasses props clear any value', () => { const props = { fixedClasses: undefined, - } + }; const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('pass `undefined` in the variant classes props clear any value', () => { const props = { @@ -372,20 +372,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - } + }; const configuration = { classes: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('pass `undefined` in the variant fixedClasses props clear any value', () => { const props = { @@ -395,25 +395,25 @@ describe('parse variants with classes list function', () => { }, }, variant: 'empty', - } + }; const configuration = { fixedClasses: { wrapper: 'p-3', body: 'text-gray-500', }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper', 'body'], configuration)).toEqual({ wrapper: undefined, body: undefined, - }) - }) + }); + }); it('considers not defined values from the configuration variant', () => { const props = { variant: 'error', - } + }; const configuration = { variants: { @@ -426,25 +426,25 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; - const defaultConfiguration = {} + const defaultConfiguration = {}; expect( - parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration), ).toEqual({ classesList: { wrapper: 'border p-3', }, - }) - }) + }); + }); it('considers not defined values from the defaultConfiguration variant', () => { const props = { variant: 'error', - } + }; - const configuration = {} + const configuration = {}; const defaultConfiguration = { variants: { @@ -457,21 +457,21 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect( - parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration) + parseVariantWithClassesList(props, ['wrapper', 'body'], configuration, defaultConfiguration), ).toEqual({ classesList: { wrapper: 'border p-3', }, - }) - }) + }); + }); it('use the variant from the configuration', () => { const props = { variant: 'alt', - } + }; const configuration = { class: 'text-blue-500', @@ -481,23 +481,23 @@ describe('parse variants with classes list function', () => { type: 'text', }, }, - } + }; expect(parseVariantWithClassesList(props, [], configuration)).toEqual( - configuration.variants.alt - ) - }) + configuration.variants.alt, + ); + }); it('use the configuration if no props sent', () => { - const props = {} + const props = {}; const configuration = { class: 'text-blue-500', type: 'text', - } + }; - expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration) - }) + expect(parseVariantWithClassesList(props, [], configuration)).toEqual(configuration); + }); it('merges className and fixedClasses', () => { const props = { @@ -508,20 +508,20 @@ describe('parse variants with classes list function', () => { fixedClasses: { wrapper: { 'border-2': true }, }, - } + }; - const config = parseVariantWithClassesList(props, ['wrapper']) + const config = parseVariantWithClassesList(props, ['wrapper']); expect(config).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-red-500 border-2', }, - }) - }) + }); + }); it('merges fixedClasses and variant classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { class: 'text-red-500', @@ -539,20 +539,20 @@ describe('parse variants with classes list function', () => { }, }, variant: 'alt', - } + }; expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({ class: 'text-red-500', classesList: { wrapper: 'border-blue-500 border-2', }, - }) - }) + }); + }); it('uses the classes from the configuration', () => { const props = { variant: 'error', - } + }; const configuration = { classes: { @@ -565,25 +565,25 @@ describe('parse variants with classes list function', () => { }, }, }, - } + }; expect(parseVariantWithClassesList(props, ['wrapper'], configuration)).toEqual({ classesList: { wrapper: 'text-red-500', }, - }) - }) + }); + }); it('handles undefined classes for a variant', () => { const props = { variant: 'error', - } + }; - expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}) - }) + expect(parseVariantWithClassesList(props, ['wrapper'])).toEqual({}); + }); it('merges only the attributes that are defined from the variant', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { @@ -601,10 +601,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - } + }; expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -612,11 +612,11 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500', input: 'shadow', }, - }) - }) + }); + }); it('merges only the attributes that are defined from the variant and keep the fixed classes', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { fixedClasses: { @@ -640,10 +640,10 @@ describe('parse variants with classes list function', () => { }, }, variant: 'error', - } + }; expect( - parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']) + parseVariantWithClassesList(props, ['wrapper', 'inputWrapper', 'label', 'input']), ).toEqual({ classesList: { wrapper: 'space-x-2 flex items-center', @@ -651,34 +651,33 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-red-500 semibold', input: 'shadow', }, - }) - }) + }); + }); it('merges the only the new attributes to the global configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', }, - } + }; - const globalConfiguration: WithVariantPropsAndClassesList = - { - classes: { - wrapper: 'flex items-center space-x-2', - inputWrapper: 'inline-flex', - label: 'uppercase text-gray-500', - input: '', - }, - } + const globalConfiguration: WithVariantPropsAndClassesList = { + classes: { + wrapper: 'flex items-center space-x-2', + inputWrapper: 'inline-flex', + label: 'uppercase text-gray-500', + input: '', + }, + }; expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], - globalConfiguration - ) + globalConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -686,18 +685,17 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }) - }) + }); + }); it('it merges the new attributes from the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; - const globalConfiguration: WithVariantPropsAndClassesList = - { - classes: { - input: 'border-1', - }, - } + const globalConfiguration: WithVariantPropsAndClassesList = { + classes: { + input: 'border-1', + }, + }; const defaultConfiguration = { classes: { @@ -706,15 +704,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - } + }; expect( parseVariantWithClassesList( {}, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration - ) + defaultConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -722,20 +720,20 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }) - }) + }); + }); it('it merges the props with the the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { input: 'border-1', label: ({ add }) => { - add('bg-green-500') + add('bg-green-500'); }, }, - } + }; const defaultConfiguration = { classes: { @@ -744,15 +742,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - } + }; expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], {}, - defaultConfiguration - ) + defaultConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -760,28 +758,28 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500 bg-green-500', input: 'border-1', }, - }) - }) + }); + }); it('it merges the global configuration, the props, and the default configuration', () => { - type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input' + type ClassesKeys = 'wrapper' | 'inputWrapper' | 'label' | 'input'; const props: WithVariantPropsAndClassesList = { classes: { wrapper: [ ({ clear }) => { - clear() + clear(); }, 'flex items-center space-x-2', ], }, - } + }; const globalConfiguration = { classes: { input: 'border-1', }, - } + }; const defaultConfiguration = { classes: { @@ -790,15 +788,15 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: '', }, - } + }; expect( parseVariantWithClassesList( props, ['wrapper', 'inputWrapper', 'label', 'input'], globalConfiguration, - defaultConfiguration - ) + defaultConfiguration, + ), ).toEqual({ classesList: { wrapper: 'flex items-center space-x-2', @@ -806,6 +804,6 @@ describe('parse variants with classes list function', () => { label: 'uppercase text-gray-500', input: 'border-1', }, - }) - }) -}) + }); + }); +}); diff --git a/src/__tests__/pick.test.ts b/src/__tests__/pick.test.ts index a1609c2..3b4222a 100644 --- a/src/__tests__/pick.test.ts +++ b/src/__tests__/pick.test.ts @@ -1,4 +1,4 @@ -import pick from '../helpers/pick' +import pick from '../helpers/pick'; describe('pick', () => { it('filter the truthy attributes of an object', () => { @@ -8,13 +8,13 @@ describe('pick', () => { gender: '', other: undefined, onemore: false, - } + }; expect(pick(obj)).toEqual({ name: 'Alfonso', age: 33, - }) - }) + }); + }); it('filter the attributes of an object by a condition', () => { const obj = { @@ -23,13 +23,13 @@ describe('pick', () => { gender: '', other: undefined, onemore: false, - } + }; expect(pick(obj, (value) => ['number', 'undefined'].includes(typeof value))).toEqual({ age: 33, other: undefined, - }) - }) + }); + }); it('filter the attributes of an object by a condition with the key name', () => { const obj = { @@ -38,11 +38,11 @@ describe('pick', () => { gender: '', other: undefined, onemore: false, - } + }; expect(pick(obj, (_value, key) => ['age', 'other'].includes(key))).toEqual({ age: 33, other: undefined, - }) - }) -}) + }); + }); +}); diff --git a/src/__tests__/promisify.test.ts b/src/__tests__/promisify.test.ts index 536601e..3b5ad3a 100644 --- a/src/__tests__/promisify.test.ts +++ b/src/__tests__/promisify.test.ts @@ -1,27 +1,27 @@ -import promisify from '../helpers/promisify' +import promisify from '../helpers/promisify'; describe('promisify', () => { it('converts a random value into a promise', async () => { - const value = 'result' + const value = 'result'; - const promise = promisify(value) + const promise = promisify(value); - expect(promise).toBeInstanceOf(Promise) + expect(promise).toBeInstanceOf(Promise); - const result = await promise + const result = await promise; - expect(result).toBe(value) - }) + expect(result).toBe(value); + }); it('keeps promises as it is', async () => { - const value = new Promise((resolve) => resolve('result')) + const value = new Promise((resolve) => resolve('result')); - const promise = promisify(value) + const promise = promisify(value); - expect(promise).toBeInstanceOf(Promise) + expect(promise).toBeInstanceOf(Promise); - const result = await promise + const result = await promise; - expect(result).toBe('result') - }) -}) + expect(result).toBe('result'); + }); +}); diff --git a/src/__tests__/promisifyFunctionResult.test.ts b/src/__tests__/promisifyFunctionResult.test.ts index 0692cd4..fdb81b7 100644 --- a/src/__tests__/promisifyFunctionResult.test.ts +++ b/src/__tests__/promisifyFunctionResult.test.ts @@ -1,80 +1,79 @@ -import promisifyFunctionResult from '../helpers/promisifyFunctionResult' +import promisifyFunctionResult from '../helpers/promisifyFunctionResult'; describe('promisifyFunctionResult', () => { it('converts the result of a function into a promise', async () => { - const fn = () => 'result' + const fn = () => 'result'; - const promisified = promisifyFunctionResult(fn) + const promisified = promisifyFunctionResult(fn); - expect(promisified).toBeInstanceOf(Promise) + expect(promisified).toBeInstanceOf(Promise); - const result = await promisified + const result = await promisified; - expect(result).toBe('result') - }) + expect(result).toBe('result'); + }); it('keeps promises as it is', async () => { - const fn = () => new Promise((resolve) => resolve('result')) + const fn = () => new Promise((resolve) => resolve('result')); - const promisified = promisifyFunctionResult(fn) + const promisified = promisifyFunctionResult(fn); - expect(promisified).toBeInstanceOf(Promise) + expect(promisified).toBeInstanceOf(Promise); - const result = await promisified + const result = await promisified; - expect(result).toBe('result') - }) + expect(result).toBe('result'); + }); it('pass the parameters to the function', async () => { const fn = (status: string): string => { if (status === 'success') { - return 'success' + return 'success'; } - return 'error' - } + return 'error'; + }; - const promisified = promisifyFunctionResult(fn, 'success') + const promisified = promisifyFunctionResult(fn, 'success'); - expect(promisified).toBeInstanceOf(Promise) + expect(promisified).toBeInstanceOf(Promise); - const result = await promisified + const result = await promisified; - expect(result).toBe('success') + expect(result).toBe('success'); - const promisified2 = promisifyFunctionResult(fn, 'other') + const promisified2 = promisifyFunctionResult(fn, 'other'); - expect(promisified2).toBeInstanceOf(Promise) + expect(promisified2).toBeInstanceOf(Promise); - const result2 = await promisified2 + const result2 = await promisified2; - expect(result2).toBe('error') - }) + expect(result2).toBe('error'); + }); it('pass the parameters to the promise', async () => { - const fn = (status: string): Promise => - new Promise((resolve) => { - if (status === 'success') { - resolve('success') - } + const fn = (status: string): Promise => new Promise((resolve) => { + if (status === 'success') { + resolve('success'); + } - resolve('error') - }) + resolve('error'); + }); - const promisified = promisifyFunctionResult(fn, 'success') + const promisified = promisifyFunctionResult(fn, 'success'); - expect(promisified).toBeInstanceOf(Promise) + expect(promisified).toBeInstanceOf(Promise); - const result = await promisified + const result = await promisified; - expect(result).toBe('success') + expect(result).toBe('success'); - const promisified2 = promisifyFunctionResult(fn, 'other') + const promisified2 = promisifyFunctionResult(fn, 'other'); - expect(promisified2).toBeInstanceOf(Promise) + expect(promisified2).toBeInstanceOf(Promise); - const result2 = await promisified2 + const result2 = await promisified2; - expect(result2).toBe('error') - }) -}) + expect(result2).toBe('error'); + }); +}); diff --git a/src/__tests__/substractFromArray.test.ts b/src/__tests__/substractFromArray.test.ts index 2e1148d..375369a 100644 --- a/src/__tests__/substractFromArray.test.ts +++ b/src/__tests__/substractFromArray.test.ts @@ -1,24 +1,24 @@ -import substractFromArray from '../helpers/substractFromArray' +import substractFromArray from '../helpers/substractFromArray'; describe('substractFromArray', () => { it('keeps the same array if item doesnt exist', () => { - const arr = [1, 2, 3] - expect(substractFromArray(arr, 4)).toEqual([1, 2, 3]) - }) + const arr = [1, 2, 3]; + expect(substractFromArray(arr, 4)).toEqual([1, 2, 3]); + }); it('removes the item if already exists', () => { - const arr = [1, 2, 3] - expect(substractFromArray(arr, 1)).toEqual([2, 3]) + const arr = [1, 2, 3]; + expect(substractFromArray(arr, 1)).toEqual([2, 3]); // Should not affect the original array - expect(arr).toEqual(arr) - }) + expect(arr).toEqual(arr); + }); it('returns an empty array if is not array', () => { - expect(substractFromArray(null, 'whatever')).toEqual([]) - }) + expect(substractFromArray(null, 'whatever')).toEqual([]); + }); it('removes an existing item for objects', () => { - const arr = [{ a: 1 }, { b: '2' }, { three: '3' }] - expect(substractFromArray(arr, { b: '2' })).toEqual([{ a: 1 }, { three: '3' }]) - }) -}) + const arr = [{ a: 1 }, { b: '2' }, { three: '3' }]; + expect(substractFromArray(arr, { b: '2' })).toEqual([{ a: 1 }, { three: '3' }]); + }); +}); diff --git a/src/__tests__/throttle.test.ts b/src/__tests__/throttle.test.ts index 9630209..5d51bc6 100644 --- a/src/__tests__/throttle.test.ts +++ b/src/__tests__/throttle.test.ts @@ -1,51 +1,51 @@ -import throttle from '../helpers/throttle' +import throttle from '../helpers/throttle'; describe('throttle', () => { it('runs the method after 200 ms by default', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - jest.useFakeTimers() + jest.useFakeTimers(); - const throttledFn = throttle(mockFn) + const throttledFn = throttle(mockFn); - throttledFn() + throttledFn(); - expect(mockFn).toHaveBeenCalledTimes(1) + expect(mockFn).toHaveBeenCalledTimes(1); - jest.advanceTimersByTime(199) + jest.advanceTimersByTime(199); - throttledFn() + throttledFn(); - expect(mockFn).toHaveBeenCalledTimes(1) + expect(mockFn).toHaveBeenCalledTimes(1); - jest.advanceTimersByTime(1) + jest.advanceTimersByTime(1); - throttledFn() + throttledFn(); - expect(mockFn).toHaveBeenCalledTimes(2) - }) + expect(mockFn).toHaveBeenCalledTimes(2); + }); it('runs the method inmediatly once', () => { - const mockFn = jest.fn() + const mockFn = jest.fn(); - jest.useFakeTimers() + jest.useFakeTimers(); - const throttledFn = throttle(mockFn, 300) + const throttledFn = throttle(mockFn, 300); - throttledFn() + throttledFn(); - expect(mockFn).toHaveBeenCalledTimes(1) + expect(mockFn).toHaveBeenCalledTimes(1); - jest.advanceTimersByTime(299) + jest.advanceTimersByTime(299); - throttledFn() + throttledFn(); - expect(mockFn).toHaveBeenCalledTimes(1) + expect(mockFn).toHaveBeenCalledTimes(1); - jest.advanceTimersByTime(1) + jest.advanceTimersByTime(1); - throttledFn() + throttledFn(); - expect(mockFn).toHaveBeenCalledTimes(2) - }) -}) + expect(mockFn).toHaveBeenCalledTimes(2); + }); +}); diff --git a/src/config/TAlertConfig.ts b/src/config/TAlertConfig.ts index d509f7a..db16056 100644 --- a/src/config/TAlertConfig.ts +++ b/src/config/TAlertConfig.ts @@ -1,4 +1,4 @@ -import { enterAndLeave } from './transitions' +import { enterAndLeave } from './transitions'; const TAlertConfig = { classes: { @@ -14,10 +14,10 @@ const TAlertConfig = { closeIcon: 'w-4 h-4', ...enterAndLeave, }, -} +}; -export const TAlertClassesKeys = Object.keys(TAlertConfig.classes) +export const TAlertClassesKeys = Object.keys(TAlertConfig.classes); -export type TAlertClassesValidKeys = keyof typeof TAlertConfig.classes +export type TAlertClassesValidKeys = keyof typeof TAlertConfig.classes; -export default TAlertConfig +export default TAlertConfig; diff --git a/src/config/TButtonConfig.ts b/src/config/TButtonConfig.ts index 657bd74..95ab2fd 100644 --- a/src/config/TButtonConfig.ts +++ b/src/config/TButtonConfig.ts @@ -1,6 +1,6 @@ const TButtonConfig = { classes: 'block px-4 py-2 text-white transition duration-100 ease-in-out bg-blue-500 border border-transparent rounded shadow-sm hover:bg-blue-600 focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -} +}; -export default TButtonConfig +export default TButtonConfig; diff --git a/src/config/TCardConfig.ts b/src/config/TCardConfig.ts index 0a66fea..278ce97 100644 --- a/src/config/TCardConfig.ts +++ b/src/config/TCardConfig.ts @@ -9,10 +9,10 @@ export const TCardConfig = { // @tw footer: 'p-3 border-t border-gray-100 rounded-b', }, -} +}; -export const TCardClassesKeys = Object.keys(TCardConfig.classes) +export const TCardClassesKeys = Object.keys(TCardConfig.classes); -export type TCardClassesValidKeys = keyof typeof TCardConfig.classes +export type TCardClassesValidKeys = keyof typeof TCardConfig.classes; -export default TCardConfig +export default TCardConfig; diff --git a/src/config/TCheckboxConfig.ts b/src/config/TCheckboxConfig.ts index 5838c2a..da9b92d 100644 --- a/src/config/TCheckboxConfig.ts +++ b/src/config/TCheckboxConfig.ts @@ -1,6 +1,6 @@ const TCheckboxConfig = { classes: 'text-blue-500 transition duration-100 ease-in-out border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 focus:ring-offset-0 disabled:opacity-50 disabled:cursor-not-allowed', -} +}; -export default TCheckboxConfig +export default TCheckboxConfig; diff --git a/src/config/TDatepickerConfig.ts b/src/config/TDatepickerConfig.ts index 1c2b666..609aae8 100644 --- a/src/config/TDatepickerConfig.ts +++ b/src/config/TDatepickerConfig.ts @@ -175,10 +175,10 @@ const TDatepickerConfig = { 'flex items-center justify-center w-6 h-6 text-xs text-gray-500 rounded-sm', // ...enterAndLeave, }, -} +}; -export const TDatepickerClassesKeys = Object.keys(TDatepickerConfig.classes) +export const TDatepickerClassesKeys = Object.keys(TDatepickerConfig.classes); -export type TDatepickerClassesValidKeys = keyof typeof TDatepickerConfig.classes +export type TDatepickerClassesValidKeys = keyof typeof TDatepickerConfig.classes; -export default TDatepickerConfig +export default TDatepickerConfig; diff --git a/src/config/TDialogConfig.ts b/src/config/TDialogConfig.ts index 3f6619d..50306d0 100644 --- a/src/config/TDialogConfig.ts +++ b/src/config/TDialogConfig.ts @@ -1,13 +1,13 @@ -import { PromiseRejectFn, Data } from '../types/Misc' -import TInputConfig from './TInputConfig' +import { PromiseRejectFn, Data } from '../types/Misc'; +import TInputConfig from './TInputConfig'; // eslint-disable-next-line import/no-named-as-default -import TModalConfig from './TModalConfig' +import TModalConfig from './TModalConfig'; const { overlay: fixedOverlay, wrapper: fixedWrapper, modal: fixedDialog, -} = TModalConfig.fixedClasses +} = TModalConfig.fixedClasses; const { overlay, @@ -27,7 +27,7 @@ const { leaveActiveClass, leaveFromClass, leaveToClass, -} = TModalConfig.classes +} = TModalConfig.classes; const TDialogConfig = { fixedClasses: { @@ -98,7 +98,7 @@ const TDialogConfig = { overlayLeaveFromClass, overlayLeaveToClass, }, -} +}; export enum DialogType { Alert = 'alert', @@ -134,38 +134,38 @@ export type DialogResponse = { input?: any // eslint-disable-next-line @typescript-eslint/no-explicit-any response?: any -} +}; -export type DialogShowFn = (name: string) => Promise +export type DialogShowFn = (name: string) => Promise; export type DialogProgramaticallyShowFn = ( titleOrDialogOptions: Options | string, text?: string, icon?: string -) => Promise +) => Promise; -export type DialogHideFn = (name: string) => void +export type DialogHideFn = (name: string) => void; export type DialogBeforeHideParams = { cancel: PromiseRejectFn response?: DialogResponse -} +}; export type DialogBeforeShowParams = { cancel: PromiseRejectFn // eslint-disable-next-line @typescript-eslint/no-explicit-any params?: any -} +}; // eslint-disable-next-line @typescript-eslint/no-explicit-any -export type DialogInputValidatorFn = (value: any) => string | Promise | null | undefined +export type DialogInputValidatorFn = (value: any) => string | Promise | null | undefined; // @TODO: see if was can get use a more specific typing // eslint-disable-next-line @typescript-eslint/no-explicit-any -export type DialogPreconfirmFn = (input: any) => Promise | any +export type DialogPreconfirmFn = (input: any) => Promise | any; -export const TDialogClassesKeys = Object.keys(TDialogConfig.classes) +export const TDialogClassesKeys = Object.keys(TDialogConfig.classes); -export type TDialogClassesValidKeys = keyof typeof TDialogConfig.classes +export type TDialogClassesValidKeys = keyof typeof TDialogConfig.classes; -export default TDialogConfig +export default TDialogConfig; diff --git a/src/config/TDropdownConfig.ts b/src/config/TDropdownConfig.ts index 4c43098..6df1faa 100644 --- a/src/config/TDropdownConfig.ts +++ b/src/config/TDropdownConfig.ts @@ -1,5 +1,5 @@ -import TButtonConfig from './TButtonConfig' -import { enterAndLeave } from './transitions' +import TButtonConfig from './TButtonConfig'; +import { enterAndLeave } from './transitions'; const TDropdownConfig = { classes: { @@ -8,11 +8,11 @@ const TDropdownConfig = { dropdown: 'w-56 bg-white rounded shadow', ...enterAndLeave, }, -} +}; -export const TDropdownClassesKeys = Object.keys(TDropdownConfig.classes) +export const TDropdownClassesKeys = Object.keys(TDropdownConfig.classes); -export type TDropdownClassesValidKeys = keyof typeof TDropdownConfig.classes +export type TDropdownClassesValidKeys = keyof typeof TDropdownConfig.classes; export const TDropdownPopperDefaultOptions = { placement: 'bottom', @@ -26,6 +26,6 @@ export const TDropdownPopperDefaultOptions = { ], strategy: 'absolute', onFirstUpdate: undefined, -} +}; -export default TDropdownConfig +export default TDropdownConfig; diff --git a/src/config/TInputConfig.ts b/src/config/TInputConfig.ts index 2626f8c..e1f4403 100644 --- a/src/config/TInputConfig.ts +++ b/src/config/TInputConfig.ts @@ -1,6 +1,6 @@ const TInputConfig = { classes: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -} +}; -export default TInputConfig +export default TInputConfig; diff --git a/src/config/TInputGroupConfig.ts b/src/config/TInputGroupConfig.ts index 06cd5e1..5bf944a 100644 --- a/src/config/TInputGroupConfig.ts +++ b/src/config/TInputGroupConfig.ts @@ -11,10 +11,10 @@ const TInputGroupConfig = { // @tw description: 'text-sm text-gray-400', }, -} +}; -export const TInputGroupClassesKeys = Object.keys(TInputGroupConfig.classes) +export const TInputGroupClassesKeys = Object.keys(TInputGroupConfig.classes); -export type TInputGroupClassesValidKeys = keyof typeof TInputGroupConfig.classes +export type TInputGroupClassesValidKeys = keyof typeof TInputGroupConfig.classes; -export default TInputGroupConfig +export default TInputGroupConfig; diff --git a/src/config/TModalConfig.ts b/src/config/TModalConfig.ts index 82354c2..72c4d54 100644 --- a/src/config/TModalConfig.ts +++ b/src/config/TModalConfig.ts @@ -50,7 +50,7 @@ export const TModalConfig = { // @tw leaveToClass: 'transform scale-95 opacity-0', }, -} +}; export enum ModalHideReason { Outside = 'outside', @@ -61,12 +61,12 @@ export enum ModalHideReason { Other = 'other', } -export type ModalShowFn = (name: string, params?: Record) => void +export type ModalShowFn = (name: string, params?: Record) => void; -export type ModalHideFn = (name: string) => void +export type ModalHideFn = (name: string) => void; -export const TModalClassesKeys = Object.keys(TModalConfig.classes) +export const TModalClassesKeys = Object.keys(TModalConfig.classes); -export type TModalClassesValidKeys = keyof typeof TModalConfig.classes +export type TModalClassesValidKeys = keyof typeof TModalConfig.classes; -export default TModalConfig +export default TModalConfig; diff --git a/src/config/TRadioConfig.ts b/src/config/TRadioConfig.ts index a12c19c..d65b155 100644 --- a/src/config/TRadioConfig.ts +++ b/src/config/TRadioConfig.ts @@ -1,6 +1,6 @@ const TRadioConfig = { classes: 'text-blue-500 transition duration-100 ease-in-out border-gray-300 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 focus:ring-offset-0 disabled:opacity-50 disabled:cursor-not-allowed', -} +}; -export default TRadioConfig +export default TRadioConfig; diff --git a/src/config/TRichSelectConfig.ts b/src/config/TRichSelectConfig.ts index b38795f..1958854 100644 --- a/src/config/TRichSelectConfig.ts +++ b/src/config/TRichSelectConfig.ts @@ -1,4 +1,4 @@ -import { enterAndLeave } from './transitions' +import { enterAndLeave } from './transitions'; const TRichSelectConfig = { classes: { @@ -102,10 +102,10 @@ const TRichSelectConfig = { ...enterAndLeave, }, -} +}; -export const TRichSelectClassesKeys = Object.keys(TRichSelectConfig.classes) +export const TRichSelectClassesKeys = Object.keys(TRichSelectConfig.classes); -export type TRichSelectClassesValidKeys = keyof typeof TRichSelectConfig.classes +export type TRichSelectClassesValidKeys = keyof typeof TRichSelectConfig.classes; -export default TRichSelectConfig +export default TRichSelectConfig; diff --git a/src/config/TSelectConfig.ts b/src/config/TSelectConfig.ts index 3f20a3f..caf65c7 100644 --- a/src/config/TSelectConfig.ts +++ b/src/config/TSelectConfig.ts @@ -1,6 +1,6 @@ const TSelectConfig = { classes: 'block w-full pl-3 pr-10 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -} +}; -export default TSelectConfig +export default TSelectConfig; diff --git a/src/config/TTagConfig.ts b/src/config/TTagConfig.ts index c05137c..f04f272 100644 --- a/src/config/TTagConfig.ts +++ b/src/config/TTagConfig.ts @@ -1,6 +1,6 @@ const TTagConfig = { // @tw classes: '', -} +}; -export default TTagConfig +export default TTagConfig; diff --git a/src/config/TTextareaConfig.ts b/src/config/TTextareaConfig.ts index 1ddd10a..0700d73 100644 --- a/src/config/TTextareaConfig.ts +++ b/src/config/TTextareaConfig.ts @@ -1,6 +1,6 @@ const TTextareaConfig = { classes: 'block w-full px-3 py-2 text-black placeholder-gray-400 transition duration-100 ease-in-out bg-white border border-gray-300 rounded shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed', -} +}; -export default TTextareaConfig +export default TTextareaConfig; diff --git a/src/config/TToggleConfig.ts b/src/config/TToggleConfig.ts index 03b8f8f..1a15a34 100644 --- a/src/config/TToggleConfig.ts +++ b/src/config/TToggleConfig.ts @@ -49,10 +49,10 @@ const TToggleConfig = { // @tw uncheckedPlaceholder: '', }, -} +}; -export const TToggleClassesKeys = Object.keys(TToggleConfig.classes) +export const TToggleClassesKeys = Object.keys(TToggleConfig.classes); -export type TToggleClassesValidKeys = keyof typeof TToggleConfig.classes +export type TToggleClassesValidKeys = keyof typeof TToggleConfig.classes; -export default TToggleConfig +export default TToggleConfig; diff --git a/src/config/TWrappedCheckboxConfig.ts b/src/config/TWrappedCheckboxConfig.ts index 565850b..ed4b2a7 100644 --- a/src/config/TWrappedCheckboxConfig.ts +++ b/src/config/TWrappedCheckboxConfig.ts @@ -1,5 +1,5 @@ -import { CSSClass } from '../types' -import TCheckboxConfig from './TCheckboxConfig' +import { CSSClass } from '../types'; +import TCheckboxConfig from './TCheckboxConfig'; export const TWrappedCheckboxClassesKeys = [ 'wrapper', @@ -9,7 +9,7 @@ export const TWrappedCheckboxClassesKeys = [ 'input', 'label', 'labelChecked', -] +]; export type TWrappedCheckboxClassesValidKeys = | 'wrapper' @@ -18,7 +18,7 @@ export type TWrappedCheckboxClassesValidKeys = | 'inputWrapperChecked' | 'input' | 'label' - | 'labelChecked' + | 'labelChecked'; export const TWrappedCheckboxConfig: { classes: { @@ -31,6 +31,6 @@ export const TWrappedCheckboxConfig: { label: '', input: TCheckboxConfig.classes, }, -} +}; -export default TWrappedCheckboxConfig +export default TWrappedCheckboxConfig; diff --git a/src/config/TWrappedRadioConfig.ts b/src/config/TWrappedRadioConfig.ts index cd6acaa..169cdd7 100644 --- a/src/config/TWrappedRadioConfig.ts +++ b/src/config/TWrappedRadioConfig.ts @@ -1,6 +1,6 @@ -import { CSSClass } from '../types/CSSClass' +import { CSSClass } from '../types/CSSClass'; -import TRadioConfig from './TRadioConfig' +import TRadioConfig from './TRadioConfig'; export const TWrappedRadioClassesKeys = [ 'wrapper', @@ -10,7 +10,7 @@ export const TWrappedRadioClassesKeys = [ 'input', 'label', 'labelChecked', -] +]; export type TWrappedRadioClassesValidKeys = | 'wrapper' @@ -19,7 +19,7 @@ export type TWrappedRadioClassesValidKeys = | 'inputWrapperChecked' | 'input' | 'label' - | 'labelChecked' + | 'labelChecked'; export const TWrappedRadioConfig: { classes: { @@ -32,6 +32,6 @@ export const TWrappedRadioConfig: { label: '', input: TRadioConfig.classes, }, -} +}; -export default TWrappedRadioConfig +export default TWrappedRadioConfig; diff --git a/src/config/index.ts b/src/config/index.ts index 5003fd2..292d010 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,11 +1,11 @@ -export { default as TInputConfig } from './TInputConfig' -export { default as TTextareaConfig } from './TTextareaConfig' -export { default as TButtonConfig } from './TButtonConfig' -export { default as TSelectConfig } from './TSelectConfig' -export { default as TCheckboxConfig } from './TCheckboxConfig' -export { default as TRadioConfig } from './TRadioConfig' -export { default as TTagConfig } from './TTagConfig' -export { default as TCardConfig, TCardClassesKeys, TCardClassesValidKeys } from './TCardConfig' +export { default as TInputConfig } from './TInputConfig'; +export { default as TTextareaConfig } from './TTextareaConfig'; +export { default as TButtonConfig } from './TButtonConfig'; +export { default as TSelectConfig } from './TSelectConfig'; +export { default as TCheckboxConfig } from './TCheckboxConfig'; +export { default as TRadioConfig } from './TRadioConfig'; +export { default as TTagConfig } from './TTagConfig'; +export { default as TCardConfig, TCardClassesKeys, TCardClassesValidKeys } from './TCardConfig'; export { default as TModalConfig, TModalClassesKeys, @@ -13,7 +13,7 @@ export { ModalShowFn, ModalHideFn, ModalHideReason, -} from './TModalConfig' +} from './TModalConfig'; export { default as TDialogConfig, TDialogClassesKeys, @@ -29,41 +29,41 @@ export { DialogIcon, DialogPreconfirmFn, DialogInputValidatorFn, -} from './TDialogConfig' -export { default as TAlertConfig, TAlertClassesKeys, TAlertClassesValidKeys } from './TAlertConfig' +} from './TDialogConfig'; +export { default as TAlertConfig, TAlertClassesKeys, TAlertClassesValidKeys } from './TAlertConfig'; export { default as TInputGroupConfig, TInputGroupClassesKeys, TInputGroupClassesValidKeys, -} from './TInputGroupConfig' +} from './TInputGroupConfig'; export { default as TDropdownConfig, TDropdownPopperDefaultOptions, TDropdownClassesKeys, TDropdownClassesValidKeys, -} from './TDropdownConfig' +} from './TDropdownConfig'; export { default as TRichSelectConfig, TRichSelectClassesKeys, TRichSelectClassesValidKeys, -} from './TRichSelectConfig' +} from './TRichSelectConfig'; export { default as TDatepickerConfig, TDatepickerClassesKeys, TDatepickerClassesValidKeys, -} from './TDatepickerConfig' +} from './TDatepickerConfig'; export { default as TToggleConfig, TToggleClassesKeys, TToggleClassesValidKeys, -} from './TToggleConfig' +} from './TToggleConfig'; export { default as TWrappedRadioConfig, TWrappedRadioClassesKeys, TWrappedRadioClassesValidKeys, -} from './TWrappedRadioConfig' +} from './TWrappedRadioConfig'; export { default as TWrappedCheckboxConfig, TWrappedCheckboxClassesKeys, TWrappedCheckboxClassesValidKeys, -} from './TWrappedCheckboxConfig' +} from './TWrappedCheckboxConfig'; diff --git a/src/config/transitions.ts b/src/config/transitions.ts index 54e40a9..ba57ce1 100644 --- a/src/config/transitions.ts +++ b/src/config/transitions.ts @@ -12,4 +12,4 @@ export const enterAndLeave = { leaveFromClass: 'transform scale-100 opacity-100', // @tw leaveToClass: 'transform scale-95 opacity-0', -} +}; diff --git a/src/dates/addDays.ts b/src/dates/addDays.ts index 5597ceb..dbc9cf9 100644 --- a/src/dates/addDays.ts +++ b/src/dates/addDays.ts @@ -1,9 +1,9 @@ -import clone from '../helpers/clone' +import clone from '../helpers/clone'; const addDays = (date: Date, amount = 1): Date => { - const result = clone(date) - result.setDate(result.getDate() + amount) - return result -} + const result = clone(date); + result.setDate(result.getDate() + amount); + return result; +}; -export default addDays +export default addDays; diff --git a/src/dates/addMonths.ts b/src/dates/addMonths.ts index 4daf5a8..571194c 100644 --- a/src/dates/addMonths.ts +++ b/src/dates/addMonths.ts @@ -1,18 +1,18 @@ -import clone from '../helpers/clone' -import getLastDayOfPrevMonth from './getLastDayOfPrevMonth' +import clone from '../helpers/clone'; +import getLastDayOfPrevMonth from './getLastDayOfPrevMonth'; const addMonths = (date: Date, amount = 1): Date => { - let newDate = clone(date) - newDate.setMonth(date.getMonth() + amount) + let newDate = clone(date); + newDate.setMonth(date.getMonth() + amount); // Means the current day has less days so the extra month is // in the following month if (newDate.getDate() !== date.getDate()) { // Assign the last day of previous month - newDate = getLastDayOfPrevMonth(newDate) + newDate = getLastDayOfPrevMonth(newDate); } - return newDate -} + return newDate; +}; -export default addMonths +export default addMonths; diff --git a/src/dates/addYears.ts b/src/dates/addYears.ts index ce7642d..9537e85 100644 --- a/src/dates/addYears.ts +++ b/src/dates/addYears.ts @@ -1,19 +1,19 @@ -import clone from '../helpers/clone' -import getLastDayOfPrevMonth from './getLastDayOfPrevMonth' +import clone from '../helpers/clone'; +import getLastDayOfPrevMonth from './getLastDayOfPrevMonth'; const addYears = (date: Date, amount = 1): Date => { - let newDate = clone(date) + let newDate = clone(date); - newDate.setFullYear(date.getFullYear() + amount) + newDate.setFullYear(date.getFullYear() + amount); // Means the new date is is a different month, this happens when the // next month has less days than the current month. (29th feb vs 28th feb) if (newDate.getDate() !== date.getDate()) { // Assign the last day of previous month - newDate = getLastDayOfPrevMonth(newDate) + newDate = getLastDayOfPrevMonth(newDate); } - return newDate -} + return newDate; +}; -export default addYears +export default addYears; diff --git a/src/dates/buildDateFormatter.ts b/src/dates/buildDateFormatter.ts index 2cb0736..1f495fd 100644 --- a/src/dates/buildDateFormatter.ts +++ b/src/dates/buildDateFormatter.ts @@ -1,14 +1,12 @@ -import formatDate from './formatDate' -import { DateLocale, DateFormatter } from '../types/Dates' +import formatDate from './formatDate'; +import { DateLocale, DateFormatter } from '../types/Dates'; -const buildDateFormatter = - (locale: DateLocale, customDateFormatter?: DateFormatter): DateFormatter => - (date: Date | null | undefined, format = 'Y-m-d H:i:S') => { - if (customDateFormatter) { - return customDateFormatter(date, format, locale) - } - - return formatDate(date, format, locale) +const buildDateFormatter = (locale: DateLocale, customDateFormatter?: DateFormatter): DateFormatter => (date: Date | null | undefined, format = 'Y-m-d H:i:S') => { + if (customDateFormatter) { + return customDateFormatter(date, format, locale); } -export default buildDateFormatter + return formatDate(date, format, locale); +}; + +export default buildDateFormatter; diff --git a/src/dates/buildDateParser.ts b/src/dates/buildDateParser.ts index a8171bc..9e75260 100644 --- a/src/dates/buildDateParser.ts +++ b/src/dates/buildDateParser.ts @@ -1,14 +1,12 @@ -import parseDate from './parseDate' -import { DateLocale, DateValue, DateParser } from '../types/Dates' +import parseDate from './parseDate'; +import { DateLocale, DateValue, DateParser } from '../types/Dates'; -const buildDateParser = - (locale: DateLocale, customDateParser?: DateParser): DateParser => - (date: DateValue | null | undefined, format = 'Y-m-d H:i:S', timeless?: boolean) => { - if (customDateParser) { - return customDateParser(date, format, timeless, locale) - } - - return parseDate(date, format, timeless, locale) +const buildDateParser = (locale: DateLocale, customDateParser?: DateParser): DateParser => (date: DateValue | null | undefined, format = 'Y-m-d H:i:S', timeless?: boolean) => { + if (customDateParser) { + return customDateParser(date, format, timeless, locale); } -export default buildDateParser + return parseDate(date, format, timeless, locale); +}; + +export default buildDateParser; diff --git a/src/dates/dateIsPartOfTheRange.ts b/src/dates/dateIsPartOfTheRange.ts index d795a02..65d4421 100644 --- a/src/dates/dateIsPartOfTheRange.ts +++ b/src/dates/dateIsPartOfTheRange.ts @@ -1,31 +1,31 @@ -import { DateParser, DateValue } from '../types/Dates' -import parseDate from './parseDate' +import { DateParser, DateValue } from '../types/Dates'; +import parseDate from './parseDate'; const dateIsPartOfTheRange = ( date: Date, min: DateValue | undefined, max: DateValue | undefined, dateParser: DateParser = parseDate, - dateFormat = 'Y-m-d H:i:S' + dateFormat = 'Y-m-d H:i:S', ): boolean => { - const minDate = min === undefined ? undefined : dateParser(min, dateFormat) - const maxDate = max === undefined ? undefined : dateParser(max, dateFormat) + const minDate = min === undefined ? undefined : dateParser(min, dateFormat); + const maxDate = max === undefined ? undefined : dateParser(max, dateFormat); - const time = date.getTime() + const time = date.getTime(); if (minDate && maxDate) { - return time >= minDate.getTime() && time <= maxDate.getTime() + return time >= minDate.getTime() && time <= maxDate.getTime(); } if (minDate) { - return time >= minDate.getTime() + return time >= minDate.getTime(); } if (maxDate) { - return time <= maxDate.getTime() + return time <= maxDate.getTime(); } - return true -} + return true; +}; -export default dateIsPartOfTheRange +export default dateIsPartOfTheRange; diff --git a/src/dates/dayIsPartOfTheConditions.ts b/src/dates/dayIsPartOfTheConditions.ts index dc65600..012840f 100644 --- a/src/dates/dayIsPartOfTheConditions.ts +++ b/src/dates/dayIsPartOfTheConditions.ts @@ -1,35 +1,35 @@ -import isSameDay from './isSameDay' +import isSameDay from './isSameDay'; -import { DateParser, DateConditions } from '../types/Dates' +import { DateParser, DateConditions } from '../types/Dates'; const dayIsPartOfTheConditions = ( date: Date | null | undefined, condition: DateConditions | undefined, dateParser: DateParser, - dateFormat?: string + dateFormat?: string, ): boolean => { if (!date) { - return false + return false; } if (typeof condition === 'function') { - return condition(date) + return condition(date); } if (typeof condition === 'string' || condition instanceof String) { - const disabledDate = dateParser(condition as string, dateFormat) - return isSameDay(disabledDate, date) + const disabledDate = dateParser(condition as string, dateFormat); + return isSameDay(disabledDate, date); } if (condition instanceof Date) { - return isSameDay(condition, date) + return isSameDay(condition, date); } if (Array.isArray(condition)) { - return condition.some((c) => dayIsPartOfTheConditions(date, c, dateParser, dateFormat)) + return condition.some((c) => dayIsPartOfTheConditions(date, c, dateParser, dateFormat)); } - return false -} + return false; +}; -export default dayIsPartOfTheConditions +export default dayIsPartOfTheConditions; diff --git a/src/dates/formatDate.ts b/src/dates/formatDate.ts index 460d72d..1f56b5d 100644 --- a/src/dates/formatDate.ts +++ b/src/dates/formatDate.ts @@ -1,13 +1,12 @@ -import { DateLocale, TokenFormattingFunctions, DateToken } from '../types/Dates' +import { DateLocale, TokenFormattingFunctions, DateToken } from '../types/Dates'; -import { English } from './l10n/default' +import { English } from './l10n/default'; -const boolToInt = (bool: boolean): 1 | 0 => (bool === true ? 1 : 0) +const boolToInt = (bool: boolean): 1 | 0 => (bool === true ? 1 : 0); -const pad = (number: string | number, length = 2): string => `000${number}`.slice(length * -1) +const pad = (number: string | number, length = 2): string => `000${number}`.slice(length * -1); -const monthToString = (monthNumber: number, shorthand: boolean, locale: DateLocale): string => - locale.months[shorthand ? 'shorthand' : 'longhand'][monthNumber] +const monthToString = (monthNumber: number, shorthand: boolean, locale: DateLocale): string => locale.months[shorthand ? 'shorthand' : 'longhand'][monthNumber]; export const tokenFormatingFunctions: TokenFormattingFunctions = { // get the date in UTC @@ -15,17 +14,17 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // weekday name, short, e.g. Thu D(date: Date, locale: DateLocale) { - return locale.weekdays.shorthand[tokenFormatingFunctions.w(date, locale) as number] + return locale.weekdays.shorthand[tokenFormatingFunctions.w(date, locale) as number]; }, // full month name e.g. January F(date: Date, locale: DateLocale) { - return monthToString((tokenFormatingFunctions.n(date, locale) as number) - 1, false, locale) + return monthToString((tokenFormatingFunctions.n(date, locale) as number) - 1, false, locale); }, // padded hour 1-12 G(date: Date, locale: DateLocale) { - return pad(tokenFormatingFunctions.h(date, locale)) + return pad(tokenFormatingFunctions.h(date, locale)); }, // hours with leading zero e.g. 03 @@ -33,7 +32,7 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // day (1-30) with ordinal suffix e.g. 1st, 2nd J(date: Date, locale: DateLocale) { - return date.getDate() + locale.ordinal(date.getDate()) + return date.getDate() + locale.ordinal(date.getDate()); }, // AM/PM @@ -41,7 +40,7 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // shorthand month e.g. Jan, Sep, Oct, etc M(date: Date, locale: DateLocale) { - return monthToString(date.getMonth(), true, locale) + return monthToString(date.getMonth(), true, locale); }, // seconds 00-59 @@ -52,22 +51,22 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { W(givenDate: Date) { // return options.getWeek(date); - const date = new Date(givenDate.getTime()) - date.setHours(0, 0, 0, 0) + const date = new Date(givenDate.getTime()); + date.setHours(0, 0, 0, 0); // Thursday in current week decides the year. - date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7)) + date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7)); // January 4 is always in week 1. - const week1 = new Date(date.getFullYear(), 0, 4) + const week1 = new Date(date.getFullYear(), 0, 4); // Adjust to Thursday in week 1 and count number of weeks from date to week1. return ( - 1 + - Math.round( - ((date.getTime() - week1.getTime()) / 86400000 - 3 + ((week1.getDay() + 6) % 7)) / 7 + 1 + + Math.round( + ((date.getTime() - week1.getTime()) / 86400000 - 3 + ((week1.getDay() + 6) % 7)) / 7, ) - ) + ); }, // full year e.g. 2016, padded (0001-9999) @@ -87,7 +86,7 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // weekday name, full, e.g. Thursday l(date: Date, locale: DateLocale) { - return locale.weekdays.longhand[date.getDay()] + return locale.weekdays.longhand[date.getDay()]; }, // padded month number (01-12) @@ -104,31 +103,31 @@ export const tokenFormatingFunctions: TokenFormattingFunctions = { // last two digits of year e.g. 16 for 2016 y: (date: Date) => String(date.getFullYear()).substring(2), -} +}; const formatDate = ( date: Date | null | undefined, format: string, - customLocale?: DateLocale + customLocale?: DateLocale, ): string => { if (!date) { - return '' + return ''; } - const locale = customLocale || English + const locale = customLocale || English; return format .split('') .map((char, i, arr) => { if (tokenFormatingFunctions[char as DateToken] && arr[i - 1] !== '\\') { - return tokenFormatingFunctions[char as DateToken](date, locale) + return tokenFormatingFunctions[char as DateToken](date, locale); } if (char !== '\\') { - return char + return char; } - return '' + return ''; }) - .join('') -} + .join(''); +}; -export default formatDate +export default formatDate; diff --git a/src/dates/getDateInDayNumber.ts b/src/dates/getDateInDayNumber.ts index d6cc79c..b3191af 100644 --- a/src/dates/getDateInDayNumber.ts +++ b/src/dates/getDateInDayNumber.ts @@ -1,4 +1,3 @@ -const getDateInDayNumber = (date: Date, dayNumber: number): Date => - new Date(date.getFullYear(), date.getMonth(), dayNumber) +const getDateInDayNumber = (date: Date, dayNumber: number): Date => new Date(date.getFullYear(), date.getMonth(), dayNumber); -export default getDateInDayNumber +export default getDateInDayNumber; diff --git a/src/dates/getFirstDayOfMonth.ts b/src/dates/getFirstDayOfMonth.ts index 7033d2a..34be39e 100644 --- a/src/dates/getFirstDayOfMonth.ts +++ b/src/dates/getFirstDayOfMonth.ts @@ -1,4 +1,3 @@ -const getFirstDayOfMonth = (fromDate: Date): Date => - new Date(fromDate.getFullYear(), fromDate.getMonth(), 1) +const getFirstDayOfMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth(), 1); -export default getFirstDayOfMonth +export default getFirstDayOfMonth; diff --git a/src/dates/getFirstDayOfNextMonth.ts b/src/dates/getFirstDayOfNextMonth.ts index e1f9033..b03c59a 100644 --- a/src/dates/getFirstDayOfNextMonth.ts +++ b/src/dates/getFirstDayOfNextMonth.ts @@ -1,4 +1,3 @@ -const getFirstDayOfNextMonth = (fromDate: Date): Date => - new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 1) +const getFirstDayOfNextMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 1); -export default getFirstDayOfNextMonth +export default getFirstDayOfNextMonth; diff --git a/src/dates/getFirstDayOfPrevMonth.ts b/src/dates/getFirstDayOfPrevMonth.ts index a594a2c..59a6a21 100644 --- a/src/dates/getFirstDayOfPrevMonth.ts +++ b/src/dates/getFirstDayOfPrevMonth.ts @@ -1,4 +1,3 @@ -const getFirstDayOfPrevMonth = (fromDate: Date): Date => - new Date(fromDate.getFullYear(), fromDate.getMonth() - 1, 1) +const getFirstDayOfPrevMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth() - 1, 1); -export default getFirstDayOfPrevMonth +export default getFirstDayOfPrevMonth; diff --git a/src/dates/getLastDayOfMonth.ts b/src/dates/getLastDayOfMonth.ts index e2261d3..ca65470 100644 --- a/src/dates/getLastDayOfMonth.ts +++ b/src/dates/getLastDayOfMonth.ts @@ -1,4 +1,3 @@ -const getLastDayOfMonth = (fromDate: Date): Date => - new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0) +const getLastDayOfMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth() + 1, 0); -export default getLastDayOfMonth +export default getLastDayOfMonth; diff --git a/src/dates/getLastDayOfPrevMonth.ts b/src/dates/getLastDayOfPrevMonth.ts index db47d5c..df64b03 100644 --- a/src/dates/getLastDayOfPrevMonth.ts +++ b/src/dates/getLastDayOfPrevMonth.ts @@ -1,4 +1,3 @@ -const getLastDayOfPrevMonth = (fromDate: Date): Date => - new Date(fromDate.getFullYear(), fromDate.getMonth(), 0) +const getLastDayOfPrevMonth = (fromDate: Date): Date => new Date(fromDate.getFullYear(), fromDate.getMonth(), 0); -export default getLastDayOfPrevMonth +export default getLastDayOfPrevMonth; diff --git a/src/dates/index.ts b/src/dates/index.ts index b36a9bf..70e7666 100644 --- a/src/dates/index.ts +++ b/src/dates/index.ts @@ -1,14 +1,14 @@ -export { English as dateEnglishLocale } from './l10n/default' -export { default as visibleDaysInMonthView } from './visibleDaysInMonthView' -export { default as isSameMonth } from './isSameMonth' -export { default as isSameDay } from './isSameDay' -export { default as isToday } from './isToday' -export { default as addDays } from './addDays' -export { default as addMonths } from './addMonths' -export { default as addYears } from './addYears' -export { default as dateIsPartOfTheRange } from './dateIsPartOfTheRange' -export { default as dayIsPartOfTheConditions } from './dayIsPartOfTheConditions' -export { default as parseDate } from './parseDate' -export { default as formatDate } from './formatDate' -export { default as buildDateParser } from './buildDateParser' -export { default as buildDateFormatter } from './buildDateFormatter' +export { English as dateEnglishLocale } from './l10n/default'; +export { default as visibleDaysInMonthView } from './visibleDaysInMonthView'; +export { default as isSameMonth } from './isSameMonth'; +export { default as isSameDay } from './isSameDay'; +export { default as isToday } from './isToday'; +export { default as addDays } from './addDays'; +export { default as addMonths } from './addMonths'; +export { default as addYears } from './addYears'; +export { default as dateIsPartOfTheRange } from './dateIsPartOfTheRange'; +export { default as dayIsPartOfTheConditions } from './dayIsPartOfTheConditions'; +export { default as parseDate } from './parseDate'; +export { default as formatDate } from './formatDate'; +export { default as buildDateParser } from './buildDateParser'; +export { default as buildDateFormatter } from './buildDateFormatter'; diff --git a/src/dates/isSameDay.ts b/src/dates/isSameDay.ts index b00d5e0..0ca6594 100644 --- a/src/dates/isSameDay.ts +++ b/src/dates/isSameDay.ts @@ -1,13 +1,13 @@ const isSameDay = (date1?: Date, date2?: Date): boolean => { if (!date1 || !date2) { - return false + return false; } return ( - date1.getDate() === date2.getDate() && - date1.getMonth() === date2.getMonth() && - date1.getFullYear() === date2.getFullYear() - ) -} + date1.getDate() === date2.getDate() + && date1.getMonth() === date2.getMonth() + && date1.getFullYear() === date2.getFullYear() + ); +}; -export default isSameDay +export default isSameDay; diff --git a/src/dates/isSameMonth.ts b/src/dates/isSameMonth.ts index f8bf410..de506d9 100644 --- a/src/dates/isSameMonth.ts +++ b/src/dates/isSameMonth.ts @@ -1,9 +1,9 @@ const isSameMonth = (date1?: Date, date2?: Date): boolean => { if (!date1 || !date2) { - return false + return false; } - return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() -} + return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth(); +}; -export default isSameMonth +export default isSameMonth; diff --git a/src/dates/isToday.ts b/src/dates/isToday.ts index c62448a..0394464 100644 --- a/src/dates/isToday.ts +++ b/src/dates/isToday.ts @@ -1,5 +1,5 @@ -import isSameDay from './isSameDay' +import isSameDay from './isSameDay'; -const isToday = (date: Date): boolean => isSameDay(date, new Date()) +const isToday = (date: Date): boolean => isSameDay(date, new Date()); -export default isToday +export default isToday; diff --git a/src/dates/l10n/ar.ts b/src/dates/l10n/ar.ts index 17a9866..37e0333 100644 --- a/src/dates/l10n/ar.ts +++ b/src/dates/l10n/ar.ts @@ -1,5 +1,5 @@ /* Arabic locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Arabic: CustomDateLocale = { weekdays: { @@ -26,6 +26,6 @@ export const Arabic: CustomDateLocale = { }, rangeSeparator: ' - ', -} +}; -export default Arabic +export default Arabic; diff --git a/src/dates/l10n/at.ts b/src/dates/l10n/at.ts index 389ce50..d26dfea 100644 --- a/src/dates/l10n/at.ts +++ b/src/dates/l10n/at.ts @@ -1,5 +1,5 @@ /* Austria locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Austria: CustomDateLocale = { weekdays: { @@ -28,6 +28,6 @@ export const Austria: CustomDateLocale = { firstDayOfWeek: 1, weekAbbreviation: 'KW', rangeSeparator: ' bis ', -} +}; -export default Austria +export default Austria; diff --git a/src/dates/l10n/az.ts b/src/dates/l10n/az.ts index d5ea0d9..5a2bb5b 100644 --- a/src/dates/l10n/az.ts +++ b/src/dates/l10n/az.ts @@ -1,5 +1,5 @@ /* Azerbaijan locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Azerbaijan: CustomDateLocale = { weekdays: { @@ -38,6 +38,6 @@ export const Azerbaijan: CustomDateLocale = { weekAbbreviation: 'Hf', amPM: ['GƏ', 'GS'], time24hr: true, -} +}; -export default Azerbaijan +export default Azerbaijan; diff --git a/src/dates/l10n/be.ts b/src/dates/l10n/be.ts index e51519f..7c042c1 100644 --- a/src/dates/l10n/be.ts +++ b/src/dates/l10n/be.ts @@ -1,5 +1,5 @@ /* Belarusian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Belarusian: CustomDateLocale = { weekdays: { @@ -25,13 +25,13 @@ export const Belarusian: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, rangeSeparator: ' — ', weekAbbreviation: 'Тыд.', amPM: ['ДП', 'ПП'], yearAriaLabel: 'Год', time24hr: true, -} +}; -export default Belarusian +export default Belarusian; diff --git a/src/dates/l10n/bg.ts b/src/dates/l10n/bg.ts index d18cd60..e8a836e 100644 --- a/src/dates/l10n/bg.ts +++ b/src/dates/l10n/bg.ts @@ -1,5 +1,5 @@ /* Bulgarian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Bulgarian: CustomDateLocale = { weekdays: { @@ -39,6 +39,6 @@ export const Bulgarian: CustomDateLocale = { }, time24hr: true, firstDayOfWeek: 1, -} +}; -export default Bulgarian +export default Bulgarian; diff --git a/src/dates/l10n/bn.ts b/src/dates/l10n/bn.ts index d8268b7..1e4af06 100644 --- a/src/dates/l10n/bn.ts +++ b/src/dates/l10n/bn.ts @@ -1,5 +1,5 @@ /* Bangla locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Bangla: CustomDateLocale = { weekdays: { @@ -37,6 +37,6 @@ export const Bangla: CustomDateLocale = { 'ডিসেম্বর', ], }, -} +}; -export default Bangla +export default Bangla; diff --git a/src/dates/l10n/bs.ts b/src/dates/l10n/bs.ts index 3e869bb..a3b7664 100644 --- a/src/dates/l10n/bs.ts +++ b/src/dates/l10n/bs.ts @@ -1,5 +1,5 @@ /* Bosnian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Bosnian: CustomDateLocale = { firstDayOfWeek: 1, @@ -27,6 +27,6 @@ export const Bosnian: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Bosnian +export default Bosnian; diff --git a/src/dates/l10n/cat.ts b/src/dates/l10n/cat.ts index 2c1b98b..c414359 100644 --- a/src/dates/l10n/cat.ts +++ b/src/dates/l10n/cat.ts @@ -1,5 +1,5 @@ /* Catalan locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Catalan: CustomDateLocale = { weekdays: { @@ -39,24 +39,24 @@ export const Catalan: CustomDateLocale = { }, ordinal: (nth) => { - const s = nth % 100 - if (s > 3 && s < 21) return 'è' + const s = nth % 100; + if (s > 3 && s < 21) return 'è'; switch (s % 10) { case 1: - return 'r' + return 'r'; case 2: - return 'n' + return 'n'; case 3: - return 'r' + return 'r'; case 4: - return 't' + return 't'; default: - return 'è' + return 'è'; } }, firstDayOfWeek: 1, time24hr: true, -} +}; -export default Catalan +export default Catalan; diff --git a/src/dates/l10n/cs.ts b/src/dates/l10n/cs.ts index 9c9603e..d8c5bb8 100644 --- a/src/dates/l10n/cs.ts +++ b/src/dates/l10n/cs.ts @@ -1,5 +1,5 @@ /* Czech locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Czech: CustomDateLocale = { weekdays: { @@ -25,13 +25,13 @@ export const Czech: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '.' + return '.'; }, rangeSeparator: ' do ', weekAbbreviation: 'Týd.', amPM: ['dop.', 'odp.'], yearAriaLabel: 'Rok', time24hr: true, -} +}; -export default Czech +export default Czech; diff --git a/src/dates/l10n/cy.ts b/src/dates/l10n/cy.ts index a29c266..eb1eed8 100644 --- a/src/dates/l10n/cy.ts +++ b/src/dates/l10n/cy.ts @@ -1,5 +1,5 @@ /* Welsh locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Welsh: CustomDateLocale = { weekdays: { @@ -49,28 +49,28 @@ export const Welsh: CustomDateLocale = { firstDayOfWeek: 1, ordinal: (nth) => { - if (nth === 1) return 'af' + if (nth === 1) return 'af'; - if (nth === 2) return 'ail' + if (nth === 2) return 'ail'; - if (nth === 3 || nth === 4) return 'ydd' + if (nth === 3 || nth === 4) return 'ydd'; - if (nth === 5 || nth === 6) return 'ed' + if (nth === 5 || nth === 6) return 'ed'; if ((nth >= 7 && nth <= 10) || nth === 12 || nth === 15 || nth === 18 || nth === 20) { - return 'fed' + return 'fed'; } if (nth === 11 || nth === 13 || nth === 14 || nth === 16 || nth === 17 || nth === 19) { - return 'eg' + return 'eg'; } - if (nth >= 21 && nth <= 39) return 'ain' + if (nth >= 21 && nth <= 39) return 'ain'; // Inconclusive. - return '' + return ''; }, time24hr: true, -} +}; -export default Welsh +export default Welsh; diff --git a/src/dates/l10n/da.ts b/src/dates/l10n/da.ts index 00f1257..c51d2e3 100644 --- a/src/dates/l10n/da.ts +++ b/src/dates/l10n/da.ts @@ -1,5 +1,5 @@ /* Danish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Danish: CustomDateLocale = { weekdays: { @@ -31,6 +31,6 @@ export const Danish: CustomDateLocale = { rangeSeparator: ' til ', weekAbbreviation: 'uge', time24hr: true, -} +}; -export default Danish +export default Danish; diff --git a/src/dates/l10n/de.ts b/src/dates/l10n/de.ts index 82047a6..8834f0e 100644 --- a/src/dates/l10n/de.ts +++ b/src/dates/l10n/de.ts @@ -1,5 +1,5 @@ /* German locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const German: CustomDateLocale = { weekdays: { @@ -29,6 +29,6 @@ export const German: CustomDateLocale = { weekAbbreviation: 'KW', rangeSeparator: ' bis ', time24hr: true, -} +}; -export default German +export default German; diff --git a/src/dates/l10n/default.ts b/src/dates/l10n/default.ts index f93376c..09351c2 100644 --- a/src/dates/l10n/default.ts +++ b/src/dates/l10n/default.ts @@ -1,4 +1,4 @@ -import { DateLocale } from '../../types/Dates' +import { DateLocale } from '../../types/Dates'; export const English: DateLocale = { weekdays: { @@ -25,16 +25,16 @@ export const English: DateLocale = { daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], firstDayOfWeek: 0, ordinal: (nth: number) => { - const s = nth % 100 + const s = nth % 100; switch (s % 10) { case 1: - return 'st' + return 'st'; case 2: - return 'nd' + return 'nd'; case 3: - return 'rd' + return 'rd'; default: - return 'th' + return 'th'; } }, rangeSeparator: ' to ', @@ -47,6 +47,6 @@ export const English: DateLocale = { time24hr: false, timeLabel: 'Time', okLabel: 'Ok', -} +}; -export default English +export default English; diff --git a/src/dates/l10n/eo.ts b/src/dates/l10n/eo.ts index e4fb557..0757666 100644 --- a/src/dates/l10n/eo.ts +++ b/src/dates/l10n/eo.ts @@ -1,5 +1,5 @@ /* Esperanto locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Esperanto: CustomDateLocale = { firstDayOfWeek: 1, @@ -32,6 +32,6 @@ export const Esperanto: CustomDateLocale = { ordinal: () => '-a', time24hr: true, -} +}; -export default Esperanto +export default Esperanto; diff --git a/src/dates/l10n/es.ts b/src/dates/l10n/es.ts index 8fdf479..0658497 100644 --- a/src/dates/l10n/es.ts +++ b/src/dates/l10n/es.ts @@ -1,5 +1,5 @@ /* Spanish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Spanish: CustomDateLocale = { weekdays: { @@ -32,6 +32,6 @@ export const Spanish: CustomDateLocale = { time24hr: true, timeLabel: 'Hora', okLabel: 'Ok', -} +}; -export default Spanish +export default Spanish; diff --git a/src/dates/l10n/et.ts b/src/dates/l10n/et.ts index a54a8b1..be0cc12 100644 --- a/src/dates/l10n/et.ts +++ b/src/dates/l10n/et.ts @@ -1,5 +1,5 @@ /* Estonian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Estonian: CustomDateLocale = { weekdays: { @@ -41,12 +41,12 @@ export const Estonian: CustomDateLocale = { firstDayOfWeek: 1, ordinal() { - return '.' + return '.'; }, weekAbbreviation: 'Näd', rangeSeparator: ' kuni ', time24hr: true, -} +}; -export default Estonian +export default Estonian; diff --git a/src/dates/l10n/fa.ts b/src/dates/l10n/fa.ts index f48649e..db628a6 100644 --- a/src/dates/l10n/fa.ts +++ b/src/dates/l10n/fa.ts @@ -1,5 +1,5 @@ /* Farsi (Persian) locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Persian: CustomDateLocale = { weekdays: { @@ -39,6 +39,6 @@ export const Persian: CustomDateLocale = { }, firstDayOfWeek: 6, ordinal: () => '', -} +}; -export default Persian +export default Persian; diff --git a/src/dates/l10n/fi.ts b/src/dates/l10n/fi.ts index e7d5bac..adc21c4 100644 --- a/src/dates/l10n/fi.ts +++ b/src/dates/l10n/fi.ts @@ -1,5 +1,5 @@ /* Finnish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Finnish: CustomDateLocale = { firstDayOfWeek: 1, @@ -50,6 +50,6 @@ export const Finnish: CustomDateLocale = { ordinal: () => '.', time24hr: true, -} +}; -export default Finnish +export default Finnish; diff --git a/src/dates/l10n/fo.ts b/src/dates/l10n/fo.ts index 41cf443..aa4ec64 100644 --- a/src/dates/l10n/fo.ts +++ b/src/dates/l10n/fo.ts @@ -1,5 +1,5 @@ /* Faroese locale for flatpickr */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Faroese: CustomDateLocale = { weekdays: { @@ -40,6 +40,6 @@ export const Faroese: CustomDateLocale = { weekAbbreviation: 'vika', yearAriaLabel: 'Ár', time24hr: true, -} +}; -export default Faroese +export default Faroese; diff --git a/src/dates/l10n/fr.ts b/src/dates/l10n/fr.ts index 2f60111..cf33c21 100644 --- a/src/dates/l10n/fr.ts +++ b/src/dates/l10n/fr.ts @@ -1,5 +1,5 @@ /* French locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const French: CustomDateLocale = { firstDayOfWeek: 1, @@ -41,13 +41,13 @@ export const French: CustomDateLocale = { }, ordinal: (nth) => { - if (nth > 1) return '' + if (nth > 1) return ''; - return 'er' + return 'er'; }, rangeSeparator: ' au ', weekAbbreviation: 'Sem', time24hr: true, -} +}; -export default French +export default French; diff --git a/src/dates/l10n/ga.ts b/src/dates/l10n/ga.ts index 42cdba8..fa1afe5 100644 --- a/src/dates/l10n/ga.ts +++ b/src/dates/l10n/ga.ts @@ -1,5 +1,5 @@ /* Gaelic Irish locale for flatpickr */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Irish: CustomDateLocale = { firstDayOfWeek: 1, @@ -35,6 +35,6 @@ export const Irish: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Irish +export default Irish; diff --git a/src/dates/l10n/gr.ts b/src/dates/l10n/gr.ts index 5782938..5fb30cc 100644 --- a/src/dates/l10n/gr.ts +++ b/src/dates/l10n/gr.ts @@ -1,5 +1,5 @@ /* Greek locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Greek: CustomDateLocale = { weekdays: { @@ -28,13 +28,13 @@ export const Greek: CustomDateLocale = { firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, weekAbbreviation: 'Εβδ', rangeSeparator: ' έως ', amPM: ['ΠΜ', 'ΜΜ'], -} +}; -export default Greek +export default Greek; diff --git a/src/dates/l10n/he.ts b/src/dates/l10n/he.ts index 4285a03..a688f68 100644 --- a/src/dates/l10n/he.ts +++ b/src/dates/l10n/he.ts @@ -1,5 +1,5 @@ /* Hebrew locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Hebrew: CustomDateLocale = { weekdays: { @@ -39,6 +39,6 @@ export const Hebrew: CustomDateLocale = { }, rangeSeparator: ' אל ', time24hr: true, -} +}; -export default Hebrew +export default Hebrew; diff --git a/src/dates/l10n/hi.ts b/src/dates/l10n/hi.ts index 20e68f8..55e17c0 100644 --- a/src/dates/l10n/hi.ts +++ b/src/dates/l10n/hi.ts @@ -1,5 +1,5 @@ /* Hindi locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Hindi: CustomDateLocale = { weekdays: { @@ -37,6 +37,6 @@ export const Hindi: CustomDateLocale = { 'दिसम्बर', ], }, -} +}; -export default Hindi +export default Hindi; diff --git a/src/dates/l10n/hr.ts b/src/dates/l10n/hr.ts index 761ed14..d5d7a83 100644 --- a/src/dates/l10n/hr.ts +++ b/src/dates/l10n/hr.ts @@ -1,5 +1,5 @@ /* Croatian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Croatian: CustomDateLocale = { firstDayOfWeek: 1, @@ -40,6 +40,6 @@ export const Croatian: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Croatian +export default Croatian; diff --git a/src/dates/l10n/hu.ts b/src/dates/l10n/hu.ts index 0eb28f1..114d390 100644 --- a/src/dates/l10n/hu.ts +++ b/src/dates/l10n/hu.ts @@ -1,5 +1,5 @@ /* Hungarian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Hungarian: CustomDateLocale = { firstDayOfWeek: 1, @@ -41,12 +41,12 @@ export const Hungarian: CustomDateLocale = { }, ordinal() { - return '.' + return '.'; }, weekAbbreviation: 'Hét', rangeSeparator: ' - ', time24hr: true, -} +}; -export default Hungarian +export default Hungarian; diff --git a/src/dates/l10n/id.ts b/src/dates/l10n/id.ts index 907b095..116e203 100644 --- a/src/dates/l10n/id.ts +++ b/src/dates/l10n/id.ts @@ -1,5 +1,5 @@ /* Indonesian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Indonesian: CustomDateLocale = { weekdays: { @@ -30,6 +30,6 @@ export const Indonesian: CustomDateLocale = { ordinal: () => '', time24hr: true, rangeSeparator: ' - ', -} +}; -export default Indonesian +export default Indonesian; diff --git a/src/dates/l10n/index.ts b/src/dates/l10n/index.ts index d9225ca..3aadf28 100644 --- a/src/dates/l10n/index.ts +++ b/src/dates/l10n/index.ts @@ -1,66 +1,66 @@ /* eslint-disable camelcase */ -import { DateLocaleName, CustomDateLocale } from '../../types/Dates' +import { DateLocaleName, CustomDateLocale } from '../../types/Dates'; -import { Arabic as ar } from './ar' -import { Austria as at } from './at' -import { Azerbaijan as az } from './az' -import { Belarusian as be } from './be' -import { Bosnian as bs } from './bs' -import { Bulgarian as bg } from './bg' -import { Bangla as bn } from './bn' -import { Catalan as cat } from './cat' -import { Czech as cs } from './cs' -import { Welsh as cy } from './cy' -import { Danish as da } from './da' -import { German as de } from './de' -import { English as en } from './default' -import { Esperanto as eo } from './eo' -import { Spanish as es } from './es' -import { Estonian as et } from './et' -import { Persian as fa } from './fa' -import { Finnish as fi } from './fi' -import { Faroese as fo } from './fo' -import { French as fr } from './fr' -import { Greek as gr } from './gr' -import { Hebrew as he } from './he' -import { Hindi as hi } from './hi' -import { Croatian as hr } from './hr' -import { Hungarian as hu } from './hu' -import { Indonesian as id } from './id' -import { Icelandic as is } from './is' -import { Italian as it } from './it' -import { Japanese as ja } from './ja' -import { Georgian as ka } from './ka' -import { Korean as ko } from './ko' -import { Khmer as km } from './km' -import { Kazakh as kz } from './kz' -import { Lithuanian as lt } from './lt' -import { Latvian as lv } from './lv' -import { Macedonian as mk } from './mk' -import { Mongolian as mn } from './mn' -import { Malaysian as ms } from './ms' -import { Burmese as my } from './my' -import { Dutch as nl } from './nl' -import { Norwegian as no } from './no' -import { Punjabi as pa } from './pa' -import { Polish as pl } from './pl' -import { Portuguese as pt } from './pt' -import { Romanian as ro } from './ro' -import { Russian as ru } from './ru' -import { Sinhala as si } from './si' -import { Slovak as sk } from './sk' -import { Slovenian as sl } from './sl' -import { Albanian as sq } from './sq' -import { Serbian as sr } from './sr' -import { Swedish as sv } from './sv' -import { Thai as th } from './th' -import { Turkish as tr } from './tr' -import { Ukrainian as uk } from './uk' -import { Uzbek as uz } from './uz' -import { UzbekLatin as uzLatn } from './uz_latn' -import { Vietnamese as vn } from './vn' -import { Mandarin as zh } from './zh' -import { MandarinTraditional as zh_tw } from './zh-tw' +import { Arabic as ar } from './ar'; +import { Austria as at } from './at'; +import { Azerbaijan as az } from './az'; +import { Belarusian as be } from './be'; +import { Bosnian as bs } from './bs'; +import { Bulgarian as bg } from './bg'; +import { Bangla as bn } from './bn'; +import { Catalan as cat } from './cat'; +import { Czech as cs } from './cs'; +import { Welsh as cy } from './cy'; +import { Danish as da } from './da'; +import { German as de } from './de'; +import { English as en } from './default'; +import { Esperanto as eo } from './eo'; +import { Spanish as es } from './es'; +import { Estonian as et } from './et'; +import { Persian as fa } from './fa'; +import { Finnish as fi } from './fi'; +import { Faroese as fo } from './fo'; +import { French as fr } from './fr'; +import { Greek as gr } from './gr'; +import { Hebrew as he } from './he'; +import { Hindi as hi } from './hi'; +import { Croatian as hr } from './hr'; +import { Hungarian as hu } from './hu'; +import { Indonesian as id } from './id'; +import { Icelandic as is } from './is'; +import { Italian as it } from './it'; +import { Japanese as ja } from './ja'; +import { Georgian as ka } from './ka'; +import { Korean as ko } from './ko'; +import { Khmer as km } from './km'; +import { Kazakh as kz } from './kz'; +import { Lithuanian as lt } from './lt'; +import { Latvian as lv } from './lv'; +import { Macedonian as mk } from './mk'; +import { Mongolian as mn } from './mn'; +import { Malaysian as ms } from './ms'; +import { Burmese as my } from './my'; +import { Dutch as nl } from './nl'; +import { Norwegian as no } from './no'; +import { Punjabi as pa } from './pa'; +import { Polish as pl } from './pl'; +import { Portuguese as pt } from './pt'; +import { Romanian as ro } from './ro'; +import { Russian as ru } from './ru'; +import { Sinhala as si } from './si'; +import { Slovak as sk } from './sk'; +import { Slovenian as sl } from './sl'; +import { Albanian as sq } from './sq'; +import { Serbian as sr } from './sr'; +import { Swedish as sv } from './sv'; +import { Thai as th } from './th'; +import { Turkish as tr } from './tr'; +import { Ukrainian as uk } from './uk'; +import { Uzbek as uz } from './uz'; +import { UzbekLatin as uzLatn } from './uz_latn'; +import { Vietnamese as vn } from './vn'; +import { Mandarin as zh } from './zh'; +import { MandarinTraditional as zh_tw } from './zh-tw'; const l10n: Record = { ar, @@ -125,6 +125,6 @@ const l10n: Record = { zh_tw, uz, uz_latn: uzLatn, -} +}; -export default l10n +export default l10n; diff --git a/src/dates/l10n/is.ts b/src/dates/l10n/is.ts index 6ab5de7..d86d5af 100644 --- a/src/dates/l10n/is.ts +++ b/src/dates/l10n/is.ts @@ -1,5 +1,5 @@ /* Icelandic locale for flatpickr */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Icelandic: CustomDateLocale = { weekdays: { @@ -40,6 +40,6 @@ export const Icelandic: CustomDateLocale = { weekAbbreviation: 'vika', yearAriaLabel: 'Ár', time24hr: true, -} +}; -export default Icelandic +export default Icelandic; diff --git a/src/dates/l10n/it.ts b/src/dates/l10n/it.ts index 188e446..5ac1fce 100644 --- a/src/dates/l10n/it.ts +++ b/src/dates/l10n/it.ts @@ -1,5 +1,5 @@ /* Italian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Italian: CustomDateLocale = { weekdays: { @@ -29,6 +29,6 @@ export const Italian: CustomDateLocale = { rangeSeparator: ' al ', weekAbbreviation: 'Se', time24hr: true, -} +}; -export default Italian +export default Italian; diff --git a/src/dates/l10n/ja.ts b/src/dates/l10n/ja.ts index 94f302f..427b9aa 100644 --- a/src/dates/l10n/ja.ts +++ b/src/dates/l10n/ja.ts @@ -1,5 +1,5 @@ /* Japanese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Japanese: CustomDateLocale = { weekdays: { @@ -40,6 +40,6 @@ export const Japanese: CustomDateLocale = { time24hr: true, rangeSeparator: ' から ', firstDayOfWeek: 1, -} +}; -export default Japanese +export default Japanese; diff --git a/src/dates/l10n/ka.ts b/src/dates/l10n/ka.ts index ab52067..52f9ea7 100644 --- a/src/dates/l10n/ka.ts +++ b/src/dates/l10n/ka.ts @@ -1,5 +1,5 @@ /* Georgian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Georgian: CustomDateLocale = { weekdays: { @@ -25,13 +25,13 @@ export const Georgian: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, rangeSeparator: ' — ', weekAbbreviation: 'კვ.', amPM: ['AM', 'PM'], yearAriaLabel: 'წელი', time24hr: true, -} +}; -export default Georgian +export default Georgian; diff --git a/src/dates/l10n/km.ts b/src/dates/l10n/km.ts index ffe5571..1090c8b 100644 --- a/src/dates/l10n/km.ts +++ b/src/dates/l10n/km.ts @@ -1,5 +1,5 @@ /* Khmer locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Khmer: CustomDateLocale = { weekdays: { @@ -42,6 +42,6 @@ export const Khmer: CustomDateLocale = { weekAbbreviation: 'សប្តាហ៍', yearAriaLabel: 'ឆ្នាំ', time24hr: true, -} +}; -export default Khmer +export default Khmer; diff --git a/src/dates/l10n/ko.ts b/src/dates/l10n/ko.ts index 31802b6..5e059ad 100644 --- a/src/dates/l10n/ko.ts +++ b/src/dates/l10n/ko.ts @@ -1,5 +1,5 @@ /* Republic of Korea locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Korean: CustomDateLocale = { weekdays: { @@ -41,6 +41,6 @@ export const Korean: CustomDateLocale = { ordinal: () => '일', rangeSeparator: ' ~ ', -} +}; -export default Korean +export default Korean; diff --git a/src/dates/l10n/kz.ts b/src/dates/l10n/kz.ts index e28d6e1..9d5d583 100644 --- a/src/dates/l10n/kz.ts +++ b/src/dates/l10n/kz.ts @@ -1,5 +1,5 @@ /* Kazakh locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Kazakh: CustomDateLocale = { weekdays: { @@ -25,12 +25,12 @@ export const Kazakh: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, rangeSeparator: ' — ', weekAbbreviation: 'Апта', amPM: ['ТД', 'ТК'], yearAriaLabel: 'Жыл', -} +}; -export default Kazakh +export default Kazakh; diff --git a/src/dates/l10n/lt.ts b/src/dates/l10n/lt.ts index 48f7676..dbdef4e 100644 --- a/src/dates/l10n/lt.ts +++ b/src/dates/l10n/lt.ts @@ -1,5 +1,5 @@ /* Lithuanian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Lithuanian: CustomDateLocale = { weekdays: { @@ -36,11 +36,11 @@ export const Lithuanian: CustomDateLocale = { firstDayOfWeek: 1, ordinal() { - return '-a' + return '-a'; }, rangeSeparator: ' iki ', weekAbbreviation: 'Sav', time24hr: true, -} +}; -export default Lithuanian +export default Lithuanian; diff --git a/src/dates/l10n/lv.ts b/src/dates/l10n/lv.ts index ebf43b0..8cc1d8a 100644 --- a/src/dates/l10n/lv.ts +++ b/src/dates/l10n/lv.ts @@ -1,5 +1,5 @@ /* Latvian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Latvian: CustomDateLocale = { firstDayOfWeek: 1, @@ -37,6 +37,6 @@ export const Latvian: CustomDateLocale = { rangeSeparator: ' līdz ', time24hr: true, -} +}; -export default Latvian +export default Latvian; diff --git a/src/dates/l10n/mk.ts b/src/dates/l10n/mk.ts index ea0af61..4ac06d3 100644 --- a/src/dates/l10n/mk.ts +++ b/src/dates/l10n/mk.ts @@ -1,5 +1,5 @@ /* Macedonian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Macedonian: CustomDateLocale = { weekdays: { @@ -29,6 +29,6 @@ export const Macedonian: CustomDateLocale = { weekAbbreviation: 'Нед.', rangeSeparator: ' до ', time24hr: true, -} +}; -export default Macedonian +export default Macedonian; diff --git a/src/dates/l10n/mn.ts b/src/dates/l10n/mn.ts index bfbfbdc..aae503f 100644 --- a/src/dates/l10n/mn.ts +++ b/src/dates/l10n/mn.ts @@ -1,5 +1,5 @@ /* Mongolian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Mongolian: CustomDateLocale = { firstDayOfWeek: 1, @@ -40,6 +40,6 @@ export const Mongolian: CustomDateLocale = { }, rangeSeparator: '-с ', time24hr: true, -} +}; -export default Mongolian +export default Mongolian; diff --git a/src/dates/l10n/ms.ts b/src/dates/l10n/ms.ts index c4ef692..dcca0b3 100644 --- a/src/dates/l10n/ms.ts +++ b/src/dates/l10n/ms.ts @@ -1,5 +1,5 @@ /* Malaysian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Malaysian: CustomDateLocale = { weekdays: { @@ -28,6 +28,6 @@ export const Malaysian: CustomDateLocale = { firstDayOfWeek: 1, ordinal: () => '', -} +}; -export default Malaysian +export default Malaysian; diff --git a/src/dates/l10n/my.ts b/src/dates/l10n/my.ts index 9c6d537..e415abe 100644 --- a/src/dates/l10n/my.ts +++ b/src/dates/l10n/my.ts @@ -1,5 +1,5 @@ /* Burmese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Burmese: CustomDateLocale = { weekdays: { @@ -42,6 +42,6 @@ export const Burmese: CustomDateLocale = { ordinal: () => '', time24hr: true, -} +}; -export default Burmese +export default Burmese; diff --git a/src/dates/l10n/nl.ts b/src/dates/l10n/nl.ts index f28494c..d4cf86e 100644 --- a/src/dates/l10n/nl.ts +++ b/src/dates/l10n/nl.ts @@ -1,5 +1,5 @@ /* Dutch locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Dutch: CustomDateLocale = { weekdays: { @@ -44,10 +44,10 @@ export const Dutch: CustomDateLocale = { time24hr: true, ordinal: (nth) => { - if (nth === 1 || nth === 8 || nth >= 20) return 'ste' + if (nth === 1 || nth === 8 || nth >= 20) return 'ste'; - return 'de' + return 'de'; }, -} +}; -export default Dutch +export default Dutch; diff --git a/src/dates/l10n/no.ts b/src/dates/l10n/no.ts index 636f735..2d1b71d 100644 --- a/src/dates/l10n/no.ts +++ b/src/dates/l10n/no.ts @@ -1,5 +1,5 @@ /* Norwegian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Norwegian: CustomDateLocale = { weekdays: { @@ -31,6 +31,6 @@ export const Norwegian: CustomDateLocale = { time24hr: true, ordinal: () => '.', -} +}; -export default Norwegian +export default Norwegian; diff --git a/src/dates/l10n/pa.ts b/src/dates/l10n/pa.ts index 0d70014..93ee6d7 100644 --- a/src/dates/l10n/pa.ts +++ b/src/dates/l10n/pa.ts @@ -1,5 +1,5 @@ /* Punjabi locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Punjabi: CustomDateLocale = { weekdays: { @@ -25,6 +25,6 @@ export const Punjabi: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Punjabi +export default Punjabi; diff --git a/src/dates/l10n/pl.ts b/src/dates/l10n/pl.ts index 15c4bad..b396eff 100644 --- a/src/dates/l10n/pl.ts +++ b/src/dates/l10n/pl.ts @@ -1,5 +1,5 @@ /* Polish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Polish: CustomDateLocale = { weekdays: { @@ -30,6 +30,6 @@ export const Polish: CustomDateLocale = { time24hr: true, ordinal: () => '.', -} +}; -export default Polish +export default Polish; diff --git a/src/dates/l10n/pt.ts b/src/dates/l10n/pt.ts index 0e302b3..9253aeb 100644 --- a/src/dates/l10n/pt.ts +++ b/src/dates/l10n/pt.ts @@ -1,5 +1,5 @@ /* Portuguese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Portuguese: CustomDateLocale = { weekdays: { @@ -35,6 +35,6 @@ export const Portuguese: CustomDateLocale = { rangeSeparator: ' até ', time24hr: true, -} +}; -export default Portuguese +export default Portuguese; diff --git a/src/dates/l10n/ro.ts b/src/dates/l10n/ro.ts index 57881fa..1d57c32 100644 --- a/src/dates/l10n/ro.ts +++ b/src/dates/l10n/ro.ts @@ -1,5 +1,5 @@ /* Romanian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Romanian: CustomDateLocale = { weekdays: { @@ -29,6 +29,6 @@ export const Romanian: CustomDateLocale = { time24hr: true, ordinal: () => '', -} +}; -export default Romanian +export default Romanian; diff --git a/src/dates/l10n/ru.ts b/src/dates/l10n/ru.ts index 079df50..0941c9c 100644 --- a/src/dates/l10n/ru.ts +++ b/src/dates/l10n/ru.ts @@ -1,5 +1,5 @@ /* Russian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Russian: CustomDateLocale = { weekdays: { @@ -38,13 +38,13 @@ export const Russian: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, rangeSeparator: ' — ', weekAbbreviation: 'Нед.', amPM: ['ДП', 'ПП'], yearAriaLabel: 'Год', time24hr: true, -} +}; -export default Russian +export default Russian; diff --git a/src/dates/l10n/si.ts b/src/dates/l10n/si.ts index 2aa6aea..b09581b 100644 --- a/src/dates/l10n/si.ts +++ b/src/dates/l10n/si.ts @@ -1,5 +1,5 @@ /* Sinhala locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Sinhala: CustomDateLocale = { weekdays: { @@ -38,6 +38,6 @@ export const Sinhala: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Sinhala +export default Sinhala; diff --git a/src/dates/l10n/sk.ts b/src/dates/l10n/sk.ts index 564915a..9fec73d 100644 --- a/src/dates/l10n/sk.ts +++ b/src/dates/l10n/sk.ts @@ -1,5 +1,5 @@ /* Slovak locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Slovak: CustomDateLocale = { weekdays: { @@ -29,8 +29,8 @@ export const Slovak: CustomDateLocale = { rangeSeparator: ' do ', time24hr: true, ordinal() { - return '.' + return '.'; }, -} +}; -export default Slovak +export default Slovak; diff --git a/src/dates/l10n/sl.ts b/src/dates/l10n/sl.ts index 4167ce8..125753d 100644 --- a/src/dates/l10n/sl.ts +++ b/src/dates/l10n/sl.ts @@ -1,5 +1,5 @@ /* Slovenian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Slovenian: CustomDateLocale = { weekdays: { @@ -29,8 +29,8 @@ export const Slovenian: CustomDateLocale = { rangeSeparator: ' do ', time24hr: true, ordinal() { - return '.' + return '.'; }, -} +}; -export default Slovenian +export default Slovenian; diff --git a/src/dates/l10n/sq.ts b/src/dates/l10n/sq.ts index 260875b..9cdbfcc 100644 --- a/src/dates/l10n/sq.ts +++ b/src/dates/l10n/sq.ts @@ -1,5 +1,5 @@ /* Albanian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Albanian: CustomDateLocale = { weekdays: { @@ -25,6 +25,6 @@ export const Albanian: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Albanian +export default Albanian; diff --git a/src/dates/l10n/sr-cyr.ts b/src/dates/l10n/sr-cyr.ts index c87bea7..05a0d12 100644 --- a/src/dates/l10n/sr-cyr.ts +++ b/src/dates/l10n/sr-cyr.ts @@ -1,5 +1,5 @@ /* Serbian Cyrillic locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const SerbianCyrillic: CustomDateLocale = { weekdays: { @@ -28,6 +28,6 @@ export const SerbianCyrillic: CustomDateLocale = { firstDayOfWeek: 1, weekAbbreviation: 'Нед.', rangeSeparator: ' до ', -} +}; -export default SerbianCyrillic +export default SerbianCyrillic; diff --git a/src/dates/l10n/sr.ts b/src/dates/l10n/sr.ts index 1af23e7..8147beb 100644 --- a/src/dates/l10n/sr.ts +++ b/src/dates/l10n/sr.ts @@ -1,5 +1,5 @@ /* Serbian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Serbian: CustomDateLocale = { weekdays: { @@ -29,6 +29,6 @@ export const Serbian: CustomDateLocale = { weekAbbreviation: 'Ned.', rangeSeparator: ' do ', time24hr: true, -} +}; -export default Serbian +export default Serbian; diff --git a/src/dates/l10n/sv.ts b/src/dates/l10n/sv.ts index 5ad1b3b..bebff5c 100644 --- a/src/dates/l10n/sv.ts +++ b/src/dates/l10n/sv.ts @@ -1,5 +1,5 @@ /* Swedish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Swedish: CustomDateLocale = { firstDayOfWeek: 1, @@ -30,6 +30,6 @@ export const Swedish: CustomDateLocale = { time24hr: true, ordinal: () => '.', -} +}; -export default Swedish +export default Swedish; diff --git a/src/dates/l10n/th.ts b/src/dates/l10n/th.ts index 54f7383..ab1fe0e 100644 --- a/src/dates/l10n/th.ts +++ b/src/dates/l10n/th.ts @@ -1,5 +1,5 @@ /* Thai locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Thai: CustomDateLocale = { weekdays: { @@ -43,6 +43,6 @@ export const Thai: CustomDateLocale = { time24hr: true, ordinal: () => '', -} +}; -export default Thai +export default Thai; diff --git a/src/dates/l10n/tr.ts b/src/dates/l10n/tr.ts index 831fa46..47e9af9 100644 --- a/src/dates/l10n/tr.ts +++ b/src/dates/l10n/tr.ts @@ -1,5 +1,5 @@ /* Turkish locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Turkish: CustomDateLocale = { weekdays: { @@ -30,6 +30,6 @@ export const Turkish: CustomDateLocale = { weekAbbreviation: 'Hf', amPM: ['ÖÖ', 'ÖS'], time24hr: true, -} +}; -export default Turkish +export default Turkish; diff --git a/src/dates/l10n/uk.ts b/src/dates/l10n/uk.ts index bda1883..6629ac9 100644 --- a/src/dates/l10n/uk.ts +++ b/src/dates/l10n/uk.ts @@ -1,5 +1,5 @@ /* Ukrainian locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Ukrainian: CustomDateLocale = { firstDayOfWeek: 1, @@ -27,6 +27,6 @@ export const Ukrainian: CustomDateLocale = { ], }, time24hr: true, -} +}; -export default Ukrainian +export default Ukrainian; diff --git a/src/dates/l10n/uz.ts b/src/dates/l10n/uz.ts index af8393c..f997ccd 100644 --- a/src/dates/l10n/uz.ts +++ b/src/dates/l10n/uz.ts @@ -1,5 +1,5 @@ /* Uzbek locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Uzbek: CustomDateLocale = { weekdays: { @@ -25,13 +25,13 @@ export const Uzbek: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, rangeSeparator: ' — ', weekAbbreviation: 'Ҳафта', amPM: ['AM', 'PM'], yearAriaLabel: 'Йил', time24hr: true, -} +}; -export default Uzbek +export default Uzbek; diff --git a/src/dates/l10n/uz_latn.ts b/src/dates/l10n/uz_latn.ts index e7b8c66..96188f9 100644 --- a/src/dates/l10n/uz_latn.ts +++ b/src/dates/l10n/uz_latn.ts @@ -1,5 +1,5 @@ /* Uzbek locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const UzbekLatin: CustomDateLocale = { weekdays: { @@ -38,13 +38,13 @@ export const UzbekLatin: CustomDateLocale = { }, firstDayOfWeek: 1, ordinal() { - return '' + return ''; }, rangeSeparator: ' — ', weekAbbreviation: 'Hafta', amPM: ['AM', 'PM'], yearAriaLabel: 'Yil', time24hr: true, -} +}; -export default UzbekLatin +export default UzbekLatin; diff --git a/src/dates/l10n/vn.ts b/src/dates/l10n/vn.ts index f455cdb..5605366 100644 --- a/src/dates/l10n/vn.ts +++ b/src/dates/l10n/vn.ts @@ -1,5 +1,5 @@ /* Vietnamese locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Vietnamese: CustomDateLocale = { weekdays: { @@ -40,6 +40,6 @@ export const Vietnamese: CustomDateLocale = { firstDayOfWeek: 1, rangeSeparator: ' đến ', -} +}; -export default Vietnamese +export default Vietnamese; diff --git a/src/dates/l10n/zh-tw.ts b/src/dates/l10n/zh-tw.ts index 3153fa2..3f2b644 100644 --- a/src/dates/l10n/zh-tw.ts +++ b/src/dates/l10n/zh-tw.ts @@ -1,5 +1,5 @@ /* Mandarin locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const MandarinTraditional: CustomDateLocale = { weekdays: { @@ -38,6 +38,6 @@ export const MandarinTraditional: CustomDateLocale = { }, rangeSeparator: ' 至 ', weekAbbreviation: '週', -} +}; -export default MandarinTraditional +export default MandarinTraditional; diff --git a/src/dates/l10n/zh.ts b/src/dates/l10n/zh.ts index 31c5b5f..d5a6acf 100644 --- a/src/dates/l10n/zh.ts +++ b/src/dates/l10n/zh.ts @@ -1,5 +1,5 @@ /* Mandarin locals for vue-tailwind */ -import { CustomDateLocale } from '../../types/Dates' +import { CustomDateLocale } from '../../types/Dates'; export const Mandarin: CustomDateLocale = { weekdays: { @@ -40,6 +40,6 @@ export const Mandarin: CustomDateLocale = { rangeSeparator: ' 至 ', weekAbbreviation: '周', -} +}; -export default Mandarin +export default Mandarin; diff --git a/src/dates/parseDate.ts b/src/dates/parseDate.ts index d8cba19..9eba041 100644 --- a/src/dates/parseDate.ts +++ b/src/dates/parseDate.ts @@ -1,4 +1,4 @@ -import clone from '../helpers/clone' +import clone from '../helpers/clone'; import { DateValue, @@ -7,79 +7,79 @@ import { TokenParsingFunctions, TokenParsingFunction, DateToken, -} from '../types/Dates' +} from '../types/Dates'; -import { English } from './l10n/default' +import { English } from './l10n/default'; -const boolToInt = (bool: boolean): 1 | 0 => (bool === true ? 1 : 0) +const boolToInt = (bool: boolean): 1 | 0 => (bool === true ? 1 : 0); -const doNothing = (): undefined => undefined +const doNothing = (): undefined => undefined; const tokenParsingFunctions: TokenParsingFunctions = { D: doNothing, F(dateObj: Date, monthName: string, locale: DateLocale) { - dateObj.setMonth(locale.months.longhand.indexOf(monthName)) + dateObj.setMonth(locale.months.longhand.indexOf(monthName)); }, G: (dateObj: Date, hour: string) => { - dateObj.setHours(parseFloat(hour)) + dateObj.setHours(parseFloat(hour)); }, H: (dateObj: Date, hour: string) => { - dateObj.setHours(parseFloat(hour)) + dateObj.setHours(parseFloat(hour)); }, J: (dateObj: Date, day: string) => { - dateObj.setDate(parseFloat(day)) + dateObj.setDate(parseFloat(day)); }, K: (dateObj: Date, amPM: string, locale: DateLocale) => { dateObj.setHours( - (dateObj.getHours() % 12) + 12 * boolToInt(new RegExp(locale.amPM[1], 'i').test(amPM)) - ) + (dateObj.getHours() % 12) + 12 * boolToInt(new RegExp(locale.amPM[1], 'i').test(amPM)), + ); }, M(dateObj: Date, shortMonth: string, locale: DateLocale) { - dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth)) + dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth)); }, S: (dateObj: Date, seconds: string) => { - dateObj.setSeconds(parseFloat(seconds)) + dateObj.setSeconds(parseFloat(seconds)); }, U: (_: Date, unixSeconds: string) => new Date(parseFloat(unixSeconds) * 1000), W(dateObj: Date, weekNum: string, locale: DateLocale) { - const weekNumber = parseInt(weekNum, 10) - const date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0) - date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek) + const weekNumber = parseInt(weekNum, 10); + const date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0); + date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek); - return date + return date; }, Y: (dateObj: Date, year: string) => { - dateObj.setFullYear(parseFloat(year)) + dateObj.setFullYear(parseFloat(year)); }, Z: (_: Date, ISODate: string) => new Date(ISODate), d: (dateObj: Date, day: string) => { - dateObj.setDate(parseFloat(day)) + dateObj.setDate(parseFloat(day)); }, h: (dateObj: Date, hour: string) => { - dateObj.setHours(parseFloat(hour)) + dateObj.setHours(parseFloat(hour)); }, i: (dateObj: Date, minutes: string) => { - dateObj.setMinutes(parseFloat(minutes)) + dateObj.setMinutes(parseFloat(minutes)); }, j: (dateObj: Date, day: string) => { - dateObj.setDate(parseFloat(day)) + dateObj.setDate(parseFloat(day)); }, l: doNothing, m: (dateObj: Date, month: string) => { - dateObj.setMonth(parseFloat(month) - 1) + dateObj.setMonth(parseFloat(month) - 1); }, n: (dateObj: Date, month: string) => { - dateObj.setMonth(parseFloat(month) - 1) + dateObj.setMonth(parseFloat(month) - 1); }, s: (dateObj: Date, seconds: string) => { - dateObj.setSeconds(parseFloat(seconds)) + dateObj.setSeconds(parseFloat(seconds)); }, w: doNothing, y: (dateObj: Date, year: string) => { - dateObj.setFullYear(2000 + parseFloat(year)) + dateObj.setFullYear(2000 + parseFloat(year)); }, -} +}; const tokenRegex: TokenRegex = { // A textual representation of a day (regex matches any word) @@ -113,129 +113,129 @@ const tokenRegex: TokenRegex = { s: '(\\d\\d|\\d)', w: '(\\d\\d|\\d)', y: '(\\d{2})', -} +}; -const isTimestamp = (date: string | number): boolean => typeof date === 'number' +const isTimestamp = (date: string | number): boolean => typeof date === 'number'; -const isGMTString = (date: string): boolean => date.toLowerCase().endsWith('gmt') +const isGMTString = (date: string): boolean => date.toLowerCase().endsWith('gmt'); -const isIsoString = (date: string): boolean => date.toLowerCase().endsWith('z') +const isIsoString = (date: string): boolean => date.toLowerCase().endsWith('z'); -const getIsBackSlash = (char: string | undefined): boolean => char === '\\' +const getIsBackSlash = (char: string | undefined): boolean => char === '\\'; const getTokenParsingOperationsFromFormat = ( date: string, format: string, - locale: DateLocale + locale: DateLocale, ): { fn: TokenParsingFunction; match: string }[] => { // The regex used for the `K` token is different for English and other languages - const localeTokenRegex = { ...tokenRegex } + const localeTokenRegex = { ...tokenRegex }; // Generates something like `(AM|PM|am|pm)` localeTokenRegex.K = `(${locale.amPM[0]}|${ locale.amPM[1] - }|${locale.amPM[0].toLowerCase()}|${locale.amPM[1].toLowerCase()})` + }|${locale.amPM[0].toLowerCase()}|${locale.amPM[1].toLowerCase()})`; - const operations: { fn: TokenParsingFunction; match: string }[] = [] + const operations: { fn: TokenParsingFunction; match: string }[] = []; - let regexString = '' - let matchIndex = 0 + let regexString = ''; + let matchIndex = 0; format.split('').forEach((token: string | DateToken, tokenIndex: number) => { - const isBackSlash = getIsBackSlash(token) - const isEscaped = getIsBackSlash(format[tokenIndex - 1]) || isBackSlash - const regex: string | undefined = localeTokenRegex[token as DateToken] + const isBackSlash = getIsBackSlash(token); + const isEscaped = getIsBackSlash(format[tokenIndex - 1]) || isBackSlash; + const regex: string | undefined = localeTokenRegex[token as DateToken]; if (!isEscaped && regex) { - regexString += regex + regexString += regex; - const match = new RegExp(regexString).exec(date) + const match = new RegExp(regexString).exec(date); if (match !== null) { - matchIndex += 1 + matchIndex += 1; if (token === 'Y') { // Should run the operation for years first operations.unshift({ fn: tokenParsingFunctions[token], match: match[matchIndex], - }) + }); } else { operations.push({ fn: tokenParsingFunctions[token], match: match[matchIndex], - }) + }); } } } else if (!isBackSlash) { // Meaning any character - regexString += '.' + regexString += '.'; } - }) + }); - return operations -} + return operations; +}; const getToday = (): Date => { - const today = new Date() - today.setHours(0, 0, 0, 0) - return today -} + const today = new Date(); + today.setHours(0, 0, 0, 0); + return today; +}; const parseDate = ( date: DateValue | undefined | null, fromFormat = 'Y-m-d H:i:S', timeless?: boolean, - customLocale?: DateLocale + customLocale?: DateLocale, ): Date | undefined => { if (date !== 0 && !date) { - return undefined + return undefined; } if (date === 'today') { - return getToday() + return getToday(); } - const locale = customLocale || English + const locale = customLocale || English; - let parsedDate: Date | undefined - const originalDate = date + let parsedDate: Date | undefined; + const originalDate = date; if (date instanceof Date) { - parsedDate = clone(date) + parsedDate = clone(date); } else if (isTimestamp(date)) { // New date from timestamp - parsedDate = new Date(date) + parsedDate = new Date(date); } else if (typeof date === 'string') { if (isGMTString(date) || isIsoString(date)) { - parsedDate = new Date(date) + parsedDate = new Date(date); } else { - const operations = getTokenParsingOperationsFromFormat(date, fromFormat, locale) + const operations = getTokenParsingOperationsFromFormat(date, fromFormat, locale); if (operations.length === 0) { - parsedDate = undefined + parsedDate = undefined; } else { - parsedDate = new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) + parsedDate = new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0); operations.forEach((operation) => { - const { fn, match } = operation - parsedDate = fn(parsedDate as Date, String(match), locale) || parsedDate - }) + const { fn, match } = operation; + parsedDate = fn(parsedDate as Date, String(match), locale) || parsedDate; + }); } } } else { - throw new Error(`Invalid date provided: ${originalDate}`) + throw new Error(`Invalid date provided: ${originalDate}`); } // eslint-disable-next-line no-restricted-globals if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) { - throw new Error(`Invalid date provided: ${originalDate}`) + throw new Error(`Invalid date provided: ${originalDate}`); } if (timeless === true) { - parsedDate.setHours(0, 0, 0, 0) + parsedDate.setHours(0, 0, 0, 0); } - return parsedDate -} + return parsedDate; +}; -export default parseDate +export default parseDate; diff --git a/src/dates/visibleDaysInMonthView.ts b/src/dates/visibleDaysInMonthView.ts index e32f876..05261ec 100644 --- a/src/dates/visibleDaysInMonthView.ts +++ b/src/dates/visibleDaysInMonthView.ts @@ -1,65 +1,60 @@ -import { WeekDay } from '../types/Dates' +import { WeekDay } from '../types/Dates'; -import getDateInDayNumber from './getDateInDayNumber' -import getFirstDayOfMonth from './getFirstDayOfMonth' -import getFirstDayOfNextMonth from './getFirstDayOfNextMonth' -import getFirstDayOfPrevMonth from './getFirstDayOfPrevMonth' -import getLastDayOfMonth from './getLastDayOfMonth' -import getLastDayOfPrevMonth from './getLastDayOfPrevMonth' +import getDateInDayNumber from './getDateInDayNumber'; +import getFirstDayOfMonth from './getFirstDayOfMonth'; +import getFirstDayOfNextMonth from './getFirstDayOfNextMonth'; +import getFirstDayOfPrevMonth from './getFirstDayOfPrevMonth'; +import getLastDayOfMonth from './getLastDayOfMonth'; +import getLastDayOfPrevMonth from './getLastDayOfPrevMonth'; const getNextMonthDays = ( firstDayOfNextMonth: Date, monthDays: Date[], - prevMonthDays: Date[] + prevMonthDays: Date[], ): Date[] => { - const nextMonthTotalDays = 7 - ((monthDays.length + prevMonthDays.length) % 7) + const nextMonthTotalDays = 7 - ((monthDays.length + prevMonthDays.length) % 7); if (nextMonthTotalDays === 7) { - return [] + return []; } - return Array.from({ length: nextMonthTotalDays }, (_x, i) => i + 1).map((day) => - getDateInDayNumber(firstDayOfNextMonth, day) - ) -} + return Array.from({ length: nextMonthTotalDays }, (_x, i) => i + 1).map((day) => getDateInDayNumber(firstDayOfNextMonth, day)); +}; -const getMonthDays = (month: Date, lastDayOfMonth: Date): Date[] => - Array.from({ length: lastDayOfMonth.getDate() }, (_x, i) => i + 1).map((day) => - getDateInDayNumber(month, day) - ) +const getMonthDays = (month: Date, lastDayOfMonth: Date): Date[] => Array.from({ length: lastDayOfMonth.getDate() }, (_x, i) => i + 1).map((day) => getDateInDayNumber(month, day)); const getPreviousMonthDays = ( month: Date, firstDayOfPrevMonth: Date, lastDayOfPrevMonth: Date, - weekstart: WeekDay + weekstart: WeekDay, ): Date[] => { - let prevMonthTotalDays = getFirstDayOfMonth(month).getDay() - weekstart + let prevMonthTotalDays = getFirstDayOfMonth(month).getDay() - weekstart; if (prevMonthTotalDays < 0) { - prevMonthTotalDays = 7 + prevMonthTotalDays + prevMonthTotalDays = 7 + prevMonthTotalDays; } return Array.from({ length: prevMonthTotalDays }, (_x, i) => lastDayOfPrevMonth.getDate() - i) .reverse() - .map((day) => getDateInDayNumber(firstDayOfPrevMonth, day)) -} + .map((day) => getDateInDayNumber(firstDayOfPrevMonth, day)); +}; const visibleDaysInMonthView = (month: Date, weekstart: WeekDay = WeekDay.Sunday): Date[] => { - const firstDayOfPrevMonth = getFirstDayOfPrevMonth(month) - const lastDayOfPrevMonth = getLastDayOfPrevMonth(month) - const lastDayOfMonth = getLastDayOfMonth(month) - const firstDayOfNextMonth = getFirstDayOfNextMonth(month) + const firstDayOfPrevMonth = getFirstDayOfPrevMonth(month); + const lastDayOfPrevMonth = getLastDayOfPrevMonth(month); + const lastDayOfMonth = getLastDayOfMonth(month); + const firstDayOfNextMonth = getFirstDayOfNextMonth(month); const prevMonthDays = getPreviousMonthDays( month, firstDayOfPrevMonth, lastDayOfPrevMonth, - weekstart - ) - const monthDays = getMonthDays(month, lastDayOfMonth) - const nextMonthDays = getNextMonthDays(firstDayOfNextMonth, monthDays, prevMonthDays) + weekstart, + ); + const monthDays = getMonthDays(month, lastDayOfMonth); + const nextMonthDays = getNextMonthDays(firstDayOfNextMonth, monthDays, prevMonthDays); - return prevMonthDays.concat(monthDays, nextMonthDays) -} + return prevMonthDays.concat(monthDays, nextMonthDays); +}; -export default visibleDaysInMonthView +export default visibleDaysInMonthView; diff --git a/src/filterOptions.ts b/src/filterOptions.ts index 688bc6b..f4965d8 100644 --- a/src/filterOptions.ts +++ b/src/filterOptions.ts @@ -1,8 +1,8 @@ -import { NormalizedOption, NormalizedOptions } from './types' +import { NormalizedOption, NormalizedOptions } from './types'; const filterOptions = (options: NormalizedOptions, query: string): NormalizedOptions => { if (query === '') { - return options + return options; } return options @@ -13,22 +13,22 @@ const filterOptions = (options: NormalizedOptions, query: string): NormalizedOpt ...{ children: filterOptions(option.children, query), }, - } - return newOption + }; + return newOption; } - return option + return option; }) .filter((option: NormalizedOption): boolean => { const foundText = String(option.text) .toUpperCase() .trim() - .includes(query.toUpperCase().trim()) + .includes(query.toUpperCase().trim()); - const hasChildren = option.children && option.children.length > 0 + const hasChildren = option.children && option.children.length > 0; - return hasChildren || foundText - }) -} + return hasChildren || foundText; + }); +}; -export default filterOptions +export default filterOptions; diff --git a/src/flattenOptions.ts b/src/flattenOptions.ts index bb65e6e..959b5a7 100644 --- a/src/flattenOptions.ts +++ b/src/flattenOptions.ts @@ -1,12 +1,11 @@ -import { NormalizedOption, NormalizedOptions } from './types' +import { NormalizedOption, NormalizedOptions } from './types'; -const flattenOptions = (options: NormalizedOptions): NormalizedOptions => - options.flatMap((option: NormalizedOption) => { - if (option.children) { - return flattenOptions(option.children) - } +const flattenOptions = (options: NormalizedOptions): NormalizedOptions => options.flatMap((option: NormalizedOption) => { + if (option.children) { + return flattenOptions(option.children); + } - return option - }) + return option; +}); -export default flattenOptions +export default flattenOptions; diff --git a/src/helpers/addToArray.ts b/src/helpers/addToArray.ts index 2695e78..0869b27 100644 --- a/src/helpers/addToArray.ts +++ b/src/helpers/addToArray.ts @@ -3,10 +3,10 @@ const addToArray =

>(arr: any, value: any): P => { if (!Array.isArray(arr)) { - return [value] as P + return [value] as P; } - return [...arr, value] as P -} + return [...arr, value] as P; +}; -export default addToArray +export default addToArray; diff --git a/src/helpers/clone.ts b/src/helpers/clone.ts index 886abc3..21f93ad 100644 --- a/src/helpers/clone.ts +++ b/src/helpers/clone.ts @@ -1,10 +1,10 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any const clone =

(obj: P): P => { if (obj instanceof Date) { - return new Date(obj.valueOf()) as P + return new Date(obj.valueOf()) as P; } - return JSON.parse(JSON.stringify(obj)) -} + return JSON.parse(JSON.stringify(obj)); +}; -export default clone +export default clone; diff --git a/src/helpers/debounce.ts b/src/helpers/debounce.ts index fa1ea8c..33c5121 100644 --- a/src/helpers/debounce.ts +++ b/src/helpers/debounce.ts @@ -1,33 +1,33 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -type DebounceFn = (...args: any[]) => void +type DebounceFn = (...args: any[]) => void; export type DebouncedFn = { cancel: () => void -} & DebounceFn +} & DebounceFn; const debounce = (func: (...args: any[]) => void, wait = 200): DebouncedFn => { - let timeout: ReturnType | undefined + let timeout: ReturnType | undefined; const cancel: () => void = () => { if (timeout) { - clearTimeout(timeout) + clearTimeout(timeout); } - } + }; const debounceFn: DebounceFn = (...args: any[]) => { - cancel() + cancel(); timeout = setTimeout(() => { - timeout = undefined - func(args) - }, wait) + timeout = undefined; + func(args); + }, wait); if (!wait) { - func(args) + func(args); } - } + }; - return Object.assign(debounceFn, { cancel }) -} + return Object.assign(debounceFn, { cancel }); +}; -export default debounce +export default debounce; diff --git a/src/helpers/elementIsTargetOrTargetChild.ts b/src/helpers/elementIsTargetOrTargetChild.ts index cc79f16..469d1c7 100644 --- a/src/helpers/elementIsTargetOrTargetChild.ts +++ b/src/helpers/elementIsTargetOrTargetChild.ts @@ -1,12 +1,12 @@ const elementIsTargetOrTargetChild = ( target: EventTarget | null, - wrapper: HTMLElement + wrapper: HTMLElement, ): boolean => { if (!(target instanceof Element)) { - return false + return false; } - return wrapper.contains(target) -} + return wrapper.contains(target); +}; -export default elementIsTargetOrTargetChild +export default elementIsTargetOrTargetChild; diff --git a/src/helpers/get.ts b/src/helpers/get.ts index 2da14f1..9127a4c 100644 --- a/src/helpers/get.ts +++ b/src/helpers/get.ts @@ -2,7 +2,7 @@ const get = ( object: T, path: string | number | symbol, - defaultValue?: unknown + defaultValue?: unknown, ): K | undefined => { const result = String(path) .replace(/\[/g, '.') @@ -10,13 +10,13 @@ const get = ( .split('.') .reduce((objectSoFar: T | any, step: string) => { if (typeof objectSoFar === 'object' || Array.isArray(objectSoFar)) { - return objectSoFar[step] + return objectSoFar[step]; } - return undefined - }, object) + return undefined; + }, object); - return result === undefined ? defaultValue : result -} + return result === undefined ? defaultValue : result; +}; -export default get +export default get; diff --git a/src/helpers/getFocusableElements.ts b/src/helpers/getFocusableElements.ts index ca1cf10..11a6073 100644 --- a/src/helpers/getFocusableElements.ts +++ b/src/helpers/getFocusableElements.ts @@ -1,8 +1,7 @@ -const getFocusableElements = (element: HTMLElement): Array => - Array.from( - element.querySelectorAll( - 'a, button, input, textarea, select, details, [contenteditable], [tabindex]:not([tabindex="-1"])' - ) - ).filter((el) => !el.hasAttribute('disabled')) as Array +const getFocusableElements = (element: HTMLElement): Array => Array.from( + element.querySelectorAll( + 'a, button, input, textarea, select, details, [contenteditable], [tabindex]:not([tabindex="-1"])', + ), +).filter((el) => !el.hasAttribute('disabled')) as Array; -export default getFocusableElements +export default getFocusableElements; diff --git a/src/helpers/hasProperty.ts b/src/helpers/hasProperty.ts index 314fd05..2cc00f8 100644 --- a/src/helpers/hasProperty.ts +++ b/src/helpers/hasProperty.ts @@ -1,8 +1,7 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any const hasProperty = ( obj: X | undefined, - prop: Y -): obj is X & Record => - obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, prop) + prop: Y, +): obj is X & Record => obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, prop); -export default hasProperty +export default hasProperty; diff --git a/src/helpers/index.ts b/src/helpers/index.ts index cdc7361..917ee96 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -1,17 +1,17 @@ -export { default as get } from './get' -export { default as pick } from './pick' -export { default as isPrimitive } from './isPrimitive' -export { default as isEqual } from './isEqual' -export { default as clone } from './clone' -export { default as debounce, DebouncedFn } from './debounce' -export { default as throttle } from './throttle' -export { default as addToArray } from './addToArray' -export { default as substractFromArray } from './substractFromArray' -export { default as elementIsTargetOrTargetChild } from './elementIsTargetOrTargetChild' -export { default as getFocusableElements } from './getFocusableElements' -export { default as isTouchOnlyDevice } from './isTouchOnlyDevice' -export { default as normalizeMeasure } from './normalizeMeasure' -export { default as normalizedOptionIsDisabled } from './normalizedOptionIsDisabled' -export { default as hasProperty } from './hasProperty' -export { default as promisify } from './promisify' -export { default as promisifyFunctionResult } from './promisifyFunctionResult' +export { default as get } from './get'; +export { default as pick } from './pick'; +export { default as isPrimitive } from './isPrimitive'; +export { default as isEqual } from './isEqual'; +export { default as clone } from './clone'; +export { default as debounce, DebouncedFn } from './debounce'; +export { default as throttle } from './throttle'; +export { default as addToArray } from './addToArray'; +export { default as substractFromArray } from './substractFromArray'; +export { default as elementIsTargetOrTargetChild } from './elementIsTargetOrTargetChild'; +export { default as getFocusableElements } from './getFocusableElements'; +export { default as isTouchOnlyDevice } from './isTouchOnlyDevice'; +export { default as normalizeMeasure } from './normalizeMeasure'; +export { default as normalizedOptionIsDisabled } from './normalizedOptionIsDisabled'; +export { default as hasProperty } from './hasProperty'; +export { default as promisify } from './promisify'; +export { default as promisifyFunctionResult } from './promisifyFunctionResult'; diff --git a/src/helpers/isEqual.ts b/src/helpers/isEqual.ts index a48083d..38d0418 100644 --- a/src/helpers/isEqual.ts +++ b/src/helpers/isEqual.ts @@ -1,3 +1,3 @@ -const isEqual = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b) +const isEqual = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b); -export default isEqual +export default isEqual; diff --git a/src/helpers/isObject.ts b/src/helpers/isObject.ts index 1b59736..75ff499 100644 --- a/src/helpers/isObject.ts +++ b/src/helpers/isObject.ts @@ -1,17 +1,17 @@ const isObject = , U>(value: T | U): value is T => { if (!value) { - return false + return false; } if (typeof value !== 'object') { - return false + return false; } if (Array.isArray(value)) { - return false + return false; } - return true -} + return true; +}; -export default isObject +export default isObject; diff --git a/src/helpers/isPrimitive.ts b/src/helpers/isPrimitive.ts index f45a234..5aff5fb 100644 --- a/src/helpers/isPrimitive.ts +++ b/src/helpers/isPrimitive.ts @@ -1,9 +1,9 @@ const isPrimitive = (value: unknown): boolean => { if (value === null) { - return true + return true; } - return !['array', 'function', 'object'].includes(typeof value) -} + return !['array', 'function', 'object'].includes(typeof value); +}; -export default isPrimitive +export default isPrimitive; diff --git a/src/helpers/isTouchOnlyDevice.ts b/src/helpers/isTouchOnlyDevice.ts index 4fdecb1..8355dbb 100644 --- a/src/helpers/isTouchOnlyDevice.ts +++ b/src/helpers/isTouchOnlyDevice.ts @@ -1,14 +1,14 @@ const isTouchOnlyDevice = (w?: Window): boolean => { if (w === undefined) { if (window === undefined) { - return false + return false; } // eslint-disable-next-line no-param-reassign - w = window + w = window; } - return !!(w.matchMedia && w.matchMedia('(any-hover: none)').matches) -} + return !!(w.matchMedia && w.matchMedia('(any-hover: none)').matches); +}; -export default isTouchOnlyDevice +export default isTouchOnlyDevice; diff --git a/src/helpers/normalizeMeasure.ts b/src/helpers/normalizeMeasure.ts index a93ffdf..5c67d9d 100644 --- a/src/helpers/normalizeMeasure.ts +++ b/src/helpers/normalizeMeasure.ts @@ -1,19 +1,19 @@ -import { Measure } from '../types' +import { Measure } from '../types'; const normalizeMeasure = (measure?: Measure | null | undefined): string | undefined => { if (measure === null || measure === undefined) { - return undefined + return undefined; } if (typeof measure === 'number') { - return `${measure}px` + return `${measure}px`; } if (String(Number(measure)) === measure) { - return `${Number(measure)}px` + return `${Number(measure)}px`; } - return measure -} + return measure; +}; -export default normalizeMeasure +export default normalizeMeasure; diff --git a/src/helpers/normalizedOptionIsDisabled.ts b/src/helpers/normalizedOptionIsDisabled.ts index f47a172..6be741e 100644 --- a/src/helpers/normalizedOptionIsDisabled.ts +++ b/src/helpers/normalizedOptionIsDisabled.ts @@ -1,6 +1,5 @@ -import { NormalizedOption } from '../types' +import { NormalizedOption } from '../types'; -const normalizedOptionIsDisabled = (option: NormalizedOption): boolean => - option.disabled === true || option.disabled === 'disabled' +const normalizedOptionIsDisabled = (option: NormalizedOption): boolean => option.disabled === true || option.disabled === 'disabled'; -export default normalizedOptionIsDisabled +export default normalizedOptionIsDisabled; diff --git a/src/helpers/pick.ts b/src/helpers/pick.ts index 8d79506..6a4e3e2 100644 --- a/src/helpers/pick.ts +++ b/src/helpers/pick.ts @@ -1,15 +1,15 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ const pick = ( object: T, - condition: (value: T[K], key: K) => boolean = (value) => !!value + condition: (value: T[K], key: K) => boolean = (value) => !!value, ): T => { - const newObject = { ...object } + const newObject = { ...object }; Object.keys(object) .filter((key) => !condition(newObject[key as K], key as K)) - .forEach((key) => delete newObject[key as K]) + .forEach((key) => delete newObject[key as K]); - return newObject -} + return newObject; +}; -export default pick +export default pick; diff --git a/src/helpers/promisify.ts b/src/helpers/promisify.ts index 4834c0b..eb12c3c 100644 --- a/src/helpers/promisify.ts +++ b/src/helpers/promisify.ts @@ -1,9 +1,9 @@ const promisify =

(value: Promise

| P): Promise

=> { if (value instanceof Promise) { - return value + return value; } - return Promise.resolve(value) -} + return Promise.resolve(value); +}; -export default promisify +export default promisify; diff --git a/src/helpers/promisifyFunctionResult.ts b/src/helpers/promisifyFunctionResult.ts index d882cc6..8e01cc6 100644 --- a/src/helpers/promisifyFunctionResult.ts +++ b/src/helpers/promisifyFunctionResult.ts @@ -1,13 +1,13 @@ -import promisify from './promisify' +import promisify from './promisify'; /* eslint-disable @typescript-eslint/no-explicit-any */ const promisifyFunctionResult =

( fn: (...args: P) => K | Promise, ...args: P ): Promise => { - const result = fn(...args) + const result = fn(...args); - return promisify(result) -} + return promisify(result); +}; -export default promisifyFunctionResult +export default promisifyFunctionResult; diff --git a/src/helpers/substractFromArray.ts b/src/helpers/substractFromArray.ts index 17e1b72..e1663d6 100644 --- a/src/helpers/substractFromArray.ts +++ b/src/helpers/substractFromArray.ts @@ -1,23 +1,23 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import isEqual from './isEqual' +import isEqual from './isEqual'; const substractFromArray =

(arr: any, value: any): P => { if (!Array.isArray(arr)) { - return [] as any + return [] as any; } - const index = arr.findIndex((valueInOriginal) => isEqual(valueInOriginal, value)) + const index = arr.findIndex((valueInOriginal) => isEqual(valueInOriginal, value)); if (index === -1) { - return arr as P + return arr as P; } - const newArray = [...arr] + const newArray = [...arr]; - newArray.splice(index, 1) + newArray.splice(index, 1); - return newArray as P -} + return newArray as P; +}; -export default substractFromArray +export default substractFromArray; diff --git a/src/helpers/throttle.ts b/src/helpers/throttle.ts index 3585b49..8301d7f 100644 --- a/src/helpers/throttle.ts +++ b/src/helpers/throttle.ts @@ -1,16 +1,16 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ const throttle = (func: (...args: any[]) => void, wait = 200): ((...args: any[]) => void) => { - let isCalled = false + let isCalled = false; return (...args: any[]) => { if (!isCalled) { - func(...args) - isCalled = true + func(...args); + isCalled = true; setTimeout(() => { - isCalled = false - }, wait) + isCalled = false; + }, wait); } - } -} + }; +}; -export default throttle +export default throttle; diff --git a/src/index.ts b/src/index.ts index fc4a7f9..e0bca20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ -export { default as mergeClasses } from './mergeClasses' -export { default as parseVariant } from './parseVariant' -export { default as parseVariantWithClassesList } from './parseVariantWithClassesList' -export { default as normalizeOptions } from './normalizeOptions' -export { default as flattenOptions } from './flattenOptions' -export { default as filterOptions } from './filterOptions' -export * from './config' -export * from './helpers' -export * from './dates' -export * from './types' +export { default as mergeClasses } from './mergeClasses'; +export { default as parseVariant } from './parseVariant'; +export { default as parseVariantWithClassesList } from './parseVariantWithClassesList'; +export { default as normalizeOptions } from './normalizeOptions'; +export { default as flattenOptions } from './flattenOptions'; +export { default as filterOptions } from './filterOptions'; +export * from './config'; +export * from './helpers'; +export * from './dates'; +export * from './types'; diff --git a/src/mergeClasses.ts b/src/mergeClasses.ts index 243af06..afa0add 100644 --- a/src/mergeClasses.ts +++ b/src/mergeClasses.ts @@ -1,54 +1,58 @@ -import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass' +import { CSSClasses, CSSClassKeyValuePair } from './types/CSSClass'; -export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => - Object.keys(classesObject).filter((className: string) => !!classesObject[className]) +export const selectClasses = (classesObject: CSSClassKeyValuePair): CSSClasses => Object.keys(classesObject).filter((className: string) => !!classesObject[className]); const mergeClasses = (...classes: CSSClasses): string => { - const mergedClasses = new Set() + const mergedClasses = new Set(); // We use a local function to iterate over the classes so we can pass the // currently mergeed classes to functional definitions const merge = (...nestedClasses: CSSClasses) => { nestedClasses.forEach((className) => { if (!className) { - return + return; } if (typeof className === 'boolean') { - return + return; } - if (typeof className === 'string' || typeof className === 'undefined') { - mergedClasses.add(`${className || ''}`.replace(/ +/g, ' ').trim()) - return + if (typeof className === 'string') { + const classNames = className.replace(/ +/g, ' ').trim().split(' '); + if (classNames.length > 1) { + merge(...classNames); + } else { + mergedClasses.add(classNames[0]); + } + return; } if (Array.isArray(className)) { - merge(...className) - return + merge(...className); + return; } if (typeof className === 'function') { className({ clear() { - mergedClasses.clear() + mergedClasses.clear(); }, - add(cssClass: string) { - merge(...cssClass.split(' ')) + add(...cssClass: string[]) { + merge(...cssClass); }, remove(cssClass: string) { - mergedClasses.delete(cssClass) + mergedClasses.delete(cssClass); }, - }) - return + }); + return; } - merge(...selectClasses(className)) - }) - } - merge(...classes) + merge(...selectClasses(className)); + }); + }; + merge(...classes); - return Array.from(mergedClasses).join(' ') -} + return Array.from(mergedClasses).join(' '); +}; -export default mergeClasses +export default mergeClasses; diff --git a/src/normalizeOptions.ts b/src/normalizeOptions.ts index 5189947..787c60c 100644 --- a/src/normalizeOptions.ts +++ b/src/normalizeOptions.ts @@ -1,4 +1,4 @@ -import get from './helpers/get' +import get from './helpers/get'; import { InputOptions, @@ -8,96 +8,96 @@ import { InputOptionValue, InputOptionText, InputOptionObject, -} from './types' +} from './types'; const guessOptionValue = (option: InputOptionObject, valueAttribute?: string): InputOptionValue => { if (valueAttribute) { - const value = get(option, valueAttribute) + const value = get(option, valueAttribute); if (value === null) { - return null + return null; } if (typeof value === 'undefined') { - return undefined + return undefined; } if (typeof value === 'number' || typeof value === 'string') { - return value + return value; } - return String(value) + return String(value); } - return option.value -} + return option.value; +}; const guessOptionText = (option: InputOptionObject, textAttribute?: string): InputOptionText => { if (textAttribute) { - const text = get(option, textAttribute) + const text = get(option, textAttribute); if (typeof text === 'undefined' || text === null) { - return '' + return ''; } if (typeof text === 'number' || typeof text === 'string') { - return text + return text; } - return String(text) + return String(text); } - return option.text -} + return option.text; +}; const normalizeOption = ( option: InputOption, textAttribute?: string, - valueAttribute?: string + valueAttribute?: string, ): NormalizedOption => { if (typeof option === 'string' || typeof option === 'number') { return { value: option, text: option, raw: option, - } + }; } const normalizedOption: NormalizedOption = { value: guessOptionValue(option, valueAttribute), text: guessOptionText(option, textAttribute), raw: option, - } + }; if (option.disabled) { - normalizedOption.disabled = true + normalizedOption.disabled = true; } if (option.children) { // eslint-disable-next-line @typescript-eslint/no-use-before-define - normalizedOption.children = normalizeOptions(option.children, textAttribute, valueAttribute) + normalizedOption.children = normalizeOptions(option.children, textAttribute, valueAttribute); } - return normalizedOption -} + return normalizedOption; +}; const normalizeOptions = ( options?: InputOptions, textAttribute?: string, - valueAttribute?: string + valueAttribute?: string, ): NormalizedOptions => { if (Array.isArray(options)) { - return options.map((option) => normalizeOption(option, textAttribute, valueAttribute)) + return options.map((option) => normalizeOption(option, textAttribute, valueAttribute)); } if (typeof options === 'object') { return Object.keys(options).map((optionKey) => ({ value: optionKey, text: options[optionKey], - })) + })); } - return [] -} + return []; +}; -export default normalizeOptions +export default normalizeOptions; diff --git a/src/parseVariant.ts b/src/parseVariant.ts index d6519d5..a939faf 100644 --- a/src/parseVariant.ts +++ b/src/parseVariant.ts @@ -1,44 +1,46 @@ -import { ObjectWithClassName, Variants, WithVariantProps } from './types/Variants' -import mergeClasses from './mergeClasses' +import { ObjectWithClassName, Variants, WithVariantProps } from './types/Variants'; +import mergeClasses from './mergeClasses'; const getCustomPropsFromVariant =

( variants?: Variants

, - variant?: string + variant?: string, ): WithVariantProps

| undefined => { if (variant !== undefined && variants) { - return variants[variant] + return variants[variant]; } - return undefined -} + return undefined; +}; const parseVariant =

( props: WithVariantProps

, globalConfiguration?: WithVariantProps

, - defaultConfiguration?: WithVariantProps

+ defaultConfiguration?: WithVariantProps

, ): P => { const { variants, variant, ...mainProps } = { ...defaultConfiguration, ...globalConfiguration, ...props, - } + }; - const customProps = getCustomPropsFromVariant(variants, variant) + const customProps = getCustomPropsFromVariant(variants, variant); const mergedProps = { ...mainProps, ...customProps, - } + }; - const { classes, fixedClasses, class: className, ...componentProps } = mergedProps + const { + classes, fixedClasses, class: className, ...componentProps + } = mergedProps; - const mergedClasses: string = mergeClasses(className, classes, fixedClasses) + const mergedClasses: string = mergeClasses(className, classes, fixedClasses); if (mergedClasses) { - ;(componentProps as P).class = mergedClasses + (componentProps as P).class = mergedClasses; } - return componentProps as P -} + return componentProps as P; +}; -export default parseVariant +export default parseVariant; diff --git a/src/parseVariantWithClassesList.ts b/src/parseVariantWithClassesList.ts index 7f38034..f69dd16 100644 --- a/src/parseVariantWithClassesList.ts +++ b/src/parseVariantWithClassesList.ts @@ -3,158 +3,158 @@ import { VariantsWithClassesList, WithVariantPropsAndClassesList, WithVariantProps, -} from './types/Variants' -import pick from './helpers/pick' +} from './types/Variants'; +import pick from './helpers/pick'; -import mergeClasses from './mergeClasses' -import { CSSClassesList, CSSRawClassesList } from './types' -import hasProperty from './helpers/hasProperty' -import isObject from './helpers/isObject' +import mergeClasses from './mergeClasses'; +import { CSSClassesList, CSSRawClassesList } from './types'; +import hasProperty from './helpers/hasProperty'; +import isObject from './helpers/isObject'; const getCustomPropsFromVariant =

( variants?: VariantsWithClassesList, - variant?: string + variant?: string, ): WithVariantPropsAndClassesList | undefined => { if (variant !== undefined && variants) { - return variants[variant] + return variants[variant]; } - return undefined -} + return undefined; +}; const getShouldClearClasses =

( props: WithVariantPropsAndClassesList, key: string, - variant: string | undefined + variant: string | undefined, ): boolean => { if (variant === undefined) { - return hasProperty(props, key) && (props[key] === undefined || props[key] === null) + return hasProperty(props, key) && (props[key] === undefined || props[key] === null); } if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

+ const propsVariant = props.variants[variant] as WithVariantProps

; return ( - hasProperty(propsVariant, key) && - (propsVariant[key] === undefined || propsVariant[key] === null) - ) + hasProperty(propsVariant, key) + && (propsVariant[key] === undefined || propsVariant[key] === null) + ); } - return false -} + return false; +}; const parseVariantWithClassesList =

( props: WithVariantPropsAndClassesList, classesListKeys: Readonly>, globalConfiguration?: WithVariantPropsAndClassesList, - defaultConfiguration?: WithVariantPropsAndClassesList + defaultConfiguration?: WithVariantPropsAndClassesList, ): P => { const { variants, variant, ...mainProps } = { ...defaultConfiguration, ...globalConfiguration, ...props, - } + }; - const classes: Partial> = {} - const fixedClasses: Partial> = {} + const classes: Partial> = {}; + const fixedClasses: Partial> = {}; - const clearClasses = getShouldClearClasses(props, 'classes', variant) + const clearClasses = getShouldClearClasses(props, 'classes', variant); - const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant) + const clearFixedClasses = getShouldClearClasses(props, 'fixedClasses', variant); if (clearClasses) { classesListKeys.forEach((classItemKey) => { - classes[classItemKey] = undefined - }) + classes[classItemKey] = undefined; + }); } else { classesListKeys.forEach((classItemKey) => { // Get classes from global configuration or alternatively from library configuration if ( - globalConfiguration && - isObject(globalConfiguration.classes) && - classItemKey in globalConfiguration.classes + globalConfiguration + && isObject(globalConfiguration.classes) + && classItemKey in globalConfiguration.classes ) { - classes[classItemKey] = globalConfiguration.classes[classItemKey] + classes[classItemKey] = globalConfiguration.classes[classItemKey]; } else if ( - defaultConfiguration && - isObject(defaultConfiguration.classes) && - classItemKey in defaultConfiguration.classes + defaultConfiguration + && isObject(defaultConfiguration.classes) + && classItemKey in defaultConfiguration.classes ) { - classes[classItemKey] = defaultConfiguration.classes[classItemKey] + classes[classItemKey] = defaultConfiguration.classes[classItemKey]; } // Get classes from props and merge them with the previous ones if (isObject(props.classes) && classItemKey in props.classes) { if (typeof props.classes[classItemKey] !== 'undefined') { - classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]] + classes[classItemKey] = [classes[classItemKey], props.classes[classItemKey]]; } else { - classes[classItemKey] = undefined + classes[classItemKey] = undefined; } } if (variant) { if (props.variants !== undefined && props.variants[variant] !== undefined) { - const propsVariant = props.variants[variant] as WithVariantProps

+ const propsVariant = props.variants[variant] as WithVariantProps

; if (isObject(propsVariant.classes) && classItemKey in propsVariant.classes) { - classes[classItemKey] = propsVariant.classes[classItemKey] + classes[classItemKey] = propsVariant.classes[classItemKey]; } } else if ( - globalConfiguration && - isObject(globalConfiguration.variants) && - variant in globalConfiguration.variants + globalConfiguration + && isObject(globalConfiguration.variants) + && variant in globalConfiguration.variants ) { const globalConfigurationVariant = globalConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - globalConfigurationVariant.classes && - isObject(globalConfigurationVariant.classes) && - classItemKey in globalConfigurationVariant.classes + globalConfigurationVariant.classes + && isObject(globalConfigurationVariant.classes) + && classItemKey in globalConfigurationVariant.classes ) { - classes[classItemKey] = globalConfigurationVariant.classes[classItemKey] + classes[classItemKey] = globalConfigurationVariant.classes[classItemKey]; } } else if ( - defaultConfiguration !== undefined && - defaultConfiguration.variants !== undefined && - defaultConfiguration.variants[variant] !== undefined + defaultConfiguration !== undefined + && defaultConfiguration.variants !== undefined + && defaultConfiguration.variants[variant] !== undefined ) { const defaultConfigurationVariant = defaultConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - defaultConfigurationVariant.classes && - isObject(defaultConfigurationVariant.classes) && - classItemKey in defaultConfigurationVariant.classes + defaultConfigurationVariant.classes + && isObject(defaultConfigurationVariant.classes) + && classItemKey in defaultConfigurationVariant.classes ) { - classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey] + classes[classItemKey] = defaultConfigurationVariant.classes[classItemKey]; } } } - }) + }); } if (clearFixedClasses) { classesListKeys.forEach((classItemKey) => { - fixedClasses[classItemKey] = undefined - }) + fixedClasses[classItemKey] = undefined; + }); } else { classesListKeys.forEach((classItemKey) => { // Get classes from global configuration or alternatively from library configuration if ( - globalConfiguration && - isObject(globalConfiguration.fixedClasses) && - classItemKey in globalConfiguration.fixedClasses + globalConfiguration + && isObject(globalConfiguration.fixedClasses) + && classItemKey in globalConfiguration.fixedClasses ) { - fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey] + fixedClasses[classItemKey] = globalConfiguration.fixedClasses[classItemKey]; } else if ( - defaultConfiguration && - isObject(defaultConfiguration.fixedClasses) && - classItemKey in defaultConfiguration.fixedClasses + defaultConfiguration + && isObject(defaultConfiguration.fixedClasses) + && classItemKey in defaultConfiguration.fixedClasses ) { - fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey] + fixedClasses[classItemKey] = defaultConfiguration.fixedClasses[classItemKey]; } // Get classes from props and merge them with the previous ones @@ -163,84 +163,84 @@ const parseVariantWithClassesList =

+ const propsVariant = props.variants[variant] as WithVariantProps

; if (isObject(propsVariant.fixedClasses) && classItemKey in propsVariant.fixedClasses) { - fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey] + fixedClasses[classItemKey] = propsVariant.fixedClasses[classItemKey]; } } else if ( - globalConfiguration !== undefined && - globalConfiguration.variants !== undefined && - globalConfiguration.variants[variant] !== undefined + globalConfiguration !== undefined + && globalConfiguration.variants !== undefined + && globalConfiguration.variants[variant] !== undefined ) { const globalConfigurationVariant = globalConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - isObject(globalConfigurationVariant.fixedClasses) && - classItemKey in globalConfigurationVariant.fixedClasses + isObject(globalConfigurationVariant.fixedClasses) + && classItemKey in globalConfigurationVariant.fixedClasses ) { - fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey] + fixedClasses[classItemKey] = globalConfigurationVariant.fixedClasses[classItemKey]; } } else if ( - defaultConfiguration !== undefined && - defaultConfiguration.variants !== undefined && - defaultConfiguration.variants[variant] !== undefined + defaultConfiguration !== undefined + && defaultConfiguration.variants !== undefined + && defaultConfiguration.variants[variant] !== undefined ) { const defaultConfigurationVariant = defaultConfiguration.variants[ variant - ] as WithVariantProps

+ ] as WithVariantProps

; if ( - isObject(defaultConfigurationVariant.fixedClasses) && - classItemKey in defaultConfigurationVariant.fixedClasses + isObject(defaultConfigurationVariant.fixedClasses) + && classItemKey in defaultConfigurationVariant.fixedClasses ) { - fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey] + fixedClasses[classItemKey] = defaultConfigurationVariant.fixedClasses[classItemKey]; } } } - }) + }); } - const customProps = getCustomPropsFromVariant(variants, variant) + const customProps = getCustomPropsFromVariant(variants, variant); const mergedProps = { ...mainProps, ...customProps, - } + }; - delete mergedProps.fixedClasses + delete mergedProps.fixedClasses; - delete mergedProps.classes + delete mergedProps.classes; - const mergedClasses: CSSClassesList = {} + const mergedClasses: CSSClassesList = {}; classesListKeys.forEach((classItemKey) => { - const classesForTheCurrentKey = classes[classItemKey] - const fixedClassesForTheCurrentKey = fixedClasses[classItemKey] + const classesForTheCurrentKey = classes[classItemKey]; + const fixedClassesForTheCurrentKey = fixedClasses[classItemKey]; mergedClasses[classItemKey as string] = mergeClasses( classesForTheCurrentKey, - fixedClassesForTheCurrentKey - ) - }) + fixedClassesForTheCurrentKey, + ); + }); - const result = pick(mergedClasses) + const result = pick(mergedClasses); if (Object.keys(result).length > 0) { - ;(mergedProps as P).classesList = result + (mergedProps as P).classesList = result; } - return mergedProps as P -} + return mergedProps as P; +}; -export default parseVariantWithClassesList +export default parseVariantWithClassesList; diff --git a/src/types/CSSClass.ts b/src/types/CSSClass.ts index fc76c8c..418811f 100644 --- a/src/types/CSSClass.ts +++ b/src/types/CSSClass.ts @@ -1,8 +1,8 @@ export type CSSClassKeyValuePair = { [key: string]: CSSClass -} +}; -export type CSSClasses = CSSClass[] +export type CSSClasses = CSSClass[]; export type CSSClass = | CSSClassKeyValuePair @@ -12,15 +12,15 @@ export type CSSClass = | null | boolean | ((modifiers: { - clear: () => void - add: (cssClass: string) => void - remove: (cssClass: string) => void - }) => void) + clear: () => void + add: (cssClass: string) => void + remove: (cssClass: string) => void + }) => void); export type CSSRawClassesList = { [key in ClassesKeys]?: CSSClass -} +}; export type CSSClassesList = { [key in ClassesKeys]?: CSSClass -} +}; diff --git a/src/types/Dates.ts b/src/types/Dates.ts index 7e24e23..712e334 100644 --- a/src/types/Dates.ts +++ b/src/types/Dates.ts @@ -11,7 +11,7 @@ export enum WeekDay { Saturday = 6, } -export type DateValue = Date | string | number +export type DateValue = Date | string | number; export type DateLocale = { weekdays: { @@ -31,7 +31,7 @@ export type DateLocale = { string, string, string, - string + string, ] longhand: [ string, @@ -45,7 +45,7 @@ export type DateLocale = { string, string, string, - string + string, ] } daysInMonth: [ @@ -60,7 +60,7 @@ export type DateLocale = { number, number, number, - number + number, ] firstDayOfWeek: number ordinal: (nth: number) => string @@ -74,7 +74,7 @@ export type DateLocale = { time24hr: boolean timeLabel: string okLabel: string -} +}; export type CustomDateLocale = { ordinal?: DateLocale['ordinal'] @@ -106,7 +106,7 @@ export type CustomDateLocale = { string, string, string, - string + string, ] longhand: [ string, @@ -120,10 +120,10 @@ export type CustomDateLocale = { string, string, string, - string + string, ] } -} +}; export type DateLocaleName = | 'ar' @@ -187,11 +187,11 @@ export type DateLocaleName = | 'zh' | 'uz' | 'uz_latn' - | 'zh_tw' + | 'zh_tw'; export type DateLocales = { [key in DateLocaleName]: DateLocale -} +}; export type DateToken = | 'D' @@ -215,36 +215,36 @@ export type DateToken = | 'n' | 's' | 'w' - | 'y' + | 'y'; export type TokenParsingFunction = ( date: Date, data: string, locale: DateLocale -) => Date | void | undefined +) => Date | void | undefined; -export type TokenParsingFunctions = Record +export type TokenParsingFunctions = Record; -export type TokenRegex = { [k in DateToken]: string } +export type TokenRegex = { [k in DateToken]: string }; export type TokenFormattingFunctions = Record< - DateToken, - (date: Date, locale: DateLocale) => string | number -> +DateToken, +(date: Date, locale: DateLocale) => string | number +>; export type DateParser = ( date: DateValue | null | undefined, givenFormat?: string, timeless?: boolean, customLocale?: DateLocale -) => Date | undefined +) => Date | undefined; export type DateFormatter = ( date: Date | null | undefined, format?: string, overrideLocale?: DateLocale -) => string +) => string; -export type DateCondition = DateValue | ((date: Date) => boolean) +export type DateCondition = DateValue | ((date: Date) => boolean); -export type DateConditions = DateCondition | DateCondition[] +export type DateConditions = DateCondition | DateCondition[]; diff --git a/src/types/InputOptions.ts b/src/types/InputOptions.ts index bc870e9..e74f099 100644 --- a/src/types/InputOptions.ts +++ b/src/types/InputOptions.ts @@ -1,8 +1,8 @@ -export type NormalizedOptions = Array +export type NormalizedOptions = Array; -export type InputOptionValue = string | number | undefined | null +export type InputOptionValue = string | number | undefined | null; -export type InputOptionText = string | number | undefined +export type InputOptionText = string | number | undefined; export type NormalizedOption = { value: InputOptionValue @@ -11,9 +11,9 @@ export type NormalizedOption = { raw?: any children?: NormalizedOptions disabled?: boolean | 'disabled' -} +}; -export type InputOptions = Array | { [key: string]: InputOptionText } +export type InputOptions = Array | { [key: string]: InputOptionText }; export type InputOptionObject = { value?: InputOptionValue @@ -22,6 +22,6 @@ export type InputOptionObject = { children?: InputOptions // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any -} +}; -export type InputOption = InputOptionObject | string | number +export type InputOption = InputOptionObject | string | number; diff --git a/src/types/Misc.ts b/src/types/Misc.ts index a3d68a1..f4c2a14 100644 --- a/src/types/Misc.ts +++ b/src/types/Misc.ts @@ -1,6 +1,6 @@ -type Measure = string | number -type Data = Record +type Measure = string | number; +type Data = Record; // eslint-disable-next-line @typescript-eslint/no-explicit-any -type PromiseRejectFn = (reason?: any) => void +type PromiseRejectFn = (reason?: any) => void; -export { Measure, Data, PromiseRejectFn } +export { Measure, Data, PromiseRejectFn }; diff --git a/src/types/Modify.ts b/src/types/Modify.ts index e97fc8e..c009594 100644 --- a/src/types/Modify.ts +++ b/src/types/Modify.ts @@ -1 +1 @@ -export type Modify = Omit & R +export type Modify = Omit & R; diff --git a/src/types/Variants.ts b/src/types/Variants.ts index 7a8e4fb..3440294 100644 --- a/src/types/Variants.ts +++ b/src/types/Variants.ts @@ -1,4 +1,4 @@ -import { CSSClass, CSSClassesList } from './CSSClass' +import { CSSClass, CSSClassesList } from './CSSClass'; export type WithVariantProps

= { classes?: CSSClass @@ -6,7 +6,7 @@ export type WithVariantProps

= { variants?: Variants

variant?: string class?: string -} & P +} & P; export interface Variants

{ [key: string]: WithVariantProps

| undefined @@ -14,15 +14,15 @@ export interface Variants

{ export type ObjectWithClassName = { class?: string -} +}; export type ObjectWithClassesList = ObjectWithClassName & { classesList?: CSSClassesList -} +}; export type WithVariantPropsAndClassesList = WithVariantProps

& { classesList?: CSSClassesList -} +}; export interface VariantsWithClassesList { [key: string]: WithVariantPropsAndClassesList | undefined } diff --git a/src/types/index.ts b/src/types/index.ts index 6fe22d4..72fec1b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,6 @@ -export * from './CSSClass' -export * from './Variants' -export * from './InputOptions' -export * from './Modify' -export * from './Misc' -export * from './Dates' +export * from './CSSClass'; +export * from './Variants'; +export * from './InputOptions'; +export * from './Modify'; +export * from './Misc'; +export * from './Dates'; From 407d65c1adb255d545975709f7ff5617e0958dd6 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Thu, 9 Dec 2021 14:46:57 +0100 Subject: [PATCH 5/5] fix: allow passing multiple classes --- src/types/CSSClass.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/CSSClass.ts b/src/types/CSSClass.ts index 418811f..df744f8 100644 --- a/src/types/CSSClass.ts +++ b/src/types/CSSClass.ts @@ -13,7 +13,7 @@ export type CSSClass = | boolean | ((modifiers: { clear: () => void - add: (cssClass: string) => void + add: (...cssClass: string[]) => void remove: (cssClass: string) => void }) => void);