@weresk/core
v0.3.1
Published
**@weresk/core** Common utilities and types for the rest of @weresk libraries
Downloads
12
Readme
@weresk/core Common utilities and types for the rest of @weresk libraries
Exports
Types
- Props
DefaultStyleProps: ContainsclassNameandstylepropertiesDefaultProps: ExtendsDefaultStylePropsand addsidDefaultPropsWithChildren: ExtendsDefaultPropsand addschildrenDefaultPageParams: ContainsslugandpathpropertiesDefaultPageProps: Containsparams: DefaultPageParamsDefaultLayoutProps: ExtendsDefaultPagePropsand addschildren
- Sanity
SpanBlockListItemLinkColorFileObjectImageObjectTableRowTableValue
Utils
- Arrays
pickRandom<T>(array?: T[]): T | undefined: Returns a random element from an arrayshuffle<T>(array: T[]): T[]: Shuffles an array
- Objects
isObject(item?: any): boolean: Checks if a variable is an object and not an arraymapKeys<K extends string, T>(keys: K[], fn: (arg: K) => T): Record<K, T>: Creates an object from an array of keys, using map functionmergeDeep(target: object, ...sources: object[]): object: Deeply merges multiple objectsobjectMap(obj: object, fn: (k: string, v: any, i: number) => any): object: Maps an objectpurgeEmptyStrings<T extends object>(obj: T): Partial<T>: Converts empty strings in the object values toundefined
- Styles
colorToRGB(color: Color): string: Converts Sanity Color object toR G BstringlockBodyScroll(lock = true): Locks and unlocks scroll for HTML body element
- Text
caseTransform(input: string | undefined, transform: "capitalize" | "uppercase" | "lowercase" | "title"): string: Transforms a string casecapitalize(input: string | undefined): string: Capitalizes a stringtitle(input: string | undefined): string: Transfrorms a string case to a title caseformatKeywords(input: string): string: In a string converts line breaks into commas and cleans up multiple and trailing spaceslongestWord(input: string): string: Returns a longest word in a stringneatTextBreaks(input?: string, length?: 1 | 2 | 3): string: Inserts a non-breakable space after a short words in a string, replaces dashes with non-breakable hyphemsneatChildrenBreaks(children?: React.ReactNode, length?: 1 | 2 | 3): React.ReactNode: Applies neatTextBreaks to all strings inside a React elementnumeric(input: number | string | undefined): number: Returns a number part of a string, works as well with numbers and undefined valuestransliterate(input?: string): string: Transliterates cyrillic glyphs in a string
- Typed
getTitleByValue(value?: string, items?: {value: string, title: string}[]): string: Finds atitlevalue for a correspondingvaluein an array of objects with those keysisIn<FilterType extends string>(filter: FilterType[] | boolean | undefined, value: string | undefined): Checks if a string is an array with typed string literal valuestoLiteralString<LiteralType extends string>(values: readonly LiteralType[], value: string | undefined): LiteralType | undefined: Converts string to literal type if it is within values
- Sanity
getImageUrlBuilder(source: SanityImageSource): ImageUrlBuilder: Returns a Sanity Image Url Builder object from Sanity Image SourcegetImageUrl = (source?: SanityImageSource, width?: number, height?: number): string: Returns an URL from Sanity Image SourcepreviewPortableText(input: (Block | object)[] | undefined): string | undefined: Returns a first text element inside a Sanity PortableText object
