UNPKG

@scriptables/manifest

Version:

Utilities to generate, parse, and update manifest headers in Scriptable scripts.

42 lines (40 loc) 1.94 kB
type CamelToKebab<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? `-${Lowercase<T>}` : T}${CamelToKebab<U>}` : S; type CamelToSnake<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? `_${Lowercase<T>}` : T}${CamelToSnake<U>}` : S; type KeysToCaseVariants<T> = { [K in keyof T as K extends string ? K | CamelToKebab<K> | CamelToSnake<K> : K]: T[K]; }; type ScriptableShareSheetInputs = Array<'file-url' | 'url' | 'image' | 'plain-text'>; /** * Base manifest type with camelCase keys */ interface ScriptableManifest { name?: string; alwaysRunInApp?: boolean; shareSheetInputs?: ScriptableShareSheetInputs; iconColor?: string; iconGlyph?: string; } /** * Extended manifest type supporting all naming conventions */ type CompatibleScriptableManifest = KeysToCaseVariants<ScriptableManifest>; /** * All valid key names for the Scriptable manifest (camel format) */ declare const SCRIPTABLE_MANIFEST_KEYS: readonly ["name", "alwaysRunInApp", "shareSheetInputs", "iconColor", "iconGlyph"]; /** * All valid key names for the Scriptable manifest (for banner formatting) */ declare const SCRIPTABLE_BANNER_KEYS: readonly ["always-run-in-app", "share-sheet-inputs", "icon-color", "icon-glyph"]; type ScriptableManifestKey = (typeof SCRIPTABLE_MANIFEST_KEYS)[number]; type ScriptableBannerKey = (typeof SCRIPTABLE_BANNER_KEYS)[number]; /** * Banner format, keeping the hyphen format in order to conform to the Scriptable specification */ interface ScriptableBannerManifest { 'always-run-in-app'?: boolean | string; 'share-sheet-inputs'?: string; 'icon-color'?: string; 'icon-glyph'?: string; } export { type CompatibleScriptableManifest, SCRIPTABLE_BANNER_KEYS, SCRIPTABLE_MANIFEST_KEYS, type ScriptableBannerKey, type ScriptableBannerManifest, type ScriptableManifest, type ScriptableManifestKey, type ScriptableShareSheetInputs };