@vettvangur/vanilla
v0.0.62
Published
Vettvangur | Vanilla JS Utility Library
Maintainers
Keywords
Readme
@vettvangur/vanilla
Tree-shakeable utility library used across Vettvangur projects. Functions are grouped by concern and re-exported under sub-paths so consumers only pull in what they need.
Install
pnpm add @vettvangur/vanillaImports
import { fetcher, dictionary } from '@vettvangur/vanilla'
import { clickOutside, preloadTimeout } from '@vettvangur/vanilla/dom'
import { capitalize, getCulture } from '@vettvangur/vanilla/string'
import { fetcher, flatten, regexr } from '@vettvangur/vanilla/data'
import { loadEnvFiles, getUmbracoData } from '@vettvangur/vanilla/server'| Sub-path | Surface |
| --- | --- |
| @vettvangur/vanilla | Everything (use sub-paths to keep bundles small). |
| @vettvangur/vanilla/dom | clickOutside, preloadTimeout — both SSR-safe and return disposers. |
| @vettvangur/vanilla/string | capitalize, dictionary, getCulture, getTranslation, isEmpty. |
| @vettvangur/vanilla/data | fetcher, flatten, regexr. |
| @vettvangur/vanilla/server | Node-only: loadEnvFiles, getUmbracoData. |
Selected APIs
fetcher({ url, options?, throwOnError = false })— minimalfetchwrapper. Returns{ data, error }by default; passthrowOnError: trueto make it throw instead. Noconsole.error— failures are quiet so build pipelines can decide.dictionary(key, data, culture = 'is-IS')— translation lookup. Uses aWeakMapindex to make repeat lookups against the samedataarray O(1).getCulture(path)— extracts a BCP-47-ish culture prefix from a URL path:/is/...→'is',/en-US/...→'en-us'.flatten(obj)— flattens nested objects to dash-joined keys ({ a: { b: 'x' } } → { 'a-b': 'x' }). ThrowsTypeErroron non-object non-null input.clickOutside(callback)— listens for clicks outside.co-triggerelements and the Escape key. Returns a disposer that removes both listeners.preloadTimeout()— togglesloaded/preload--hiddenbody classes on a 100/400ms cadence. Returns a disposer that clears both timers.loadEnvFiles(showMessage = true)— server-only loader that hydratesprocess.envfrom.env/.env.localetc.getUmbracoData({ route, fetchType, options, fetchOptions })— fetch from Umbraco's Content Delivery API, withloadEnvFilesinvoked automatically.
SSR / disposers
DOM helpers (clickOutside, preloadTimeout) early-return a no-op disposer when document is undefined, so they're safe to import from server bundles. Always capture and call the returned disposer on unmount or route change.
const dispose = clickOutside(() => closeMenu())
// later:
dispose()