Basic JavaScript utility collection for browser-based applications.
Documentation & interactive tutorials:
[https://www.pim.sk/@pim-sk/utils/](https://www.pim.sk/@pim-sk/utils/)npm install @pim.sk/utilsEvery module is a standalone ES module — import only what you need.
With a bundler, package exports resolve the file automatically (no extension needed):
import { sleep, to } from '@pim.sk/utils/wait'
import sortAssoc from '@pim.sk/utils/sortAssoc'
import { isNull } from '@pim.sk/utils/is'No install needed. An importmap maps the @pim.sk/utils/ prefix to a directory — either local or CDN. The full filename including extension is required in the browser.
<script type="importmap">
{
"imports": {
"@pim.sk/utils/": "https://cdn.jsdelivr.net/npm/@pim.sk/utils@1.1.2/src/"
}
}
</script>
<script type="module">
import { sleep, to } from '@pim.sk/utils/wait.mjs'
import sortAssoc from '@pim.sk/utils/sortAssoc.mjs'
import '@pim.sk/utils/array-extend.mjs' // side-effect only — no exports
</script>Pin the version (
@1.1.2) in production to avoid breaking changes.
Use.min.mjs/.min.jsbuilds for production.
The same importmap pattern works for a local directory:
"@pim.sk/utils/": "/library/js/"Both resolve identically — only the source differs.
| Module | Description |
|---|---|
| get | Fetch wrapper with async/await support. Configurable method, output type (json, text, object) and data payload. |
| wait | sleep(ms) — async pause. to(fn|selector) — polls until a condition, CSS selector or variable becomes truthy. |
| Module | Description |
|---|---|
| parse | Recursively converts string values in objects/arrays to native JS types. Safe number detection preserves phone numbers and leading-zero codes. |
| is | Type-checking predicates: isString, isNumber, isBoolean, isNull, isUndefined, isNil, isArray, isObject, isJson, isDate, isDOM, isFunction, isClass. |
| boolean | Converts loose truthy strings ("1", "yes", "true", "on") to a native boolean. |
| recursiveCompare | Deep diff of two objects or arrays. Returns change records { k, f, t } — path, from-value, to-value. |
| Module | Description |
|---|---|
| sortAssoc | Sorts an array of objects by one or more fields. Supports String, Number, Date, Boolean, asc/desc and multi-field sorting. |
| array-extend ⚡ | Side-effect only — no exports. Extends Array.prototype with: .sum, .avg, .min, .max, .unique, .put, .sortBy and more. Import without destructuring: import '@pim.sk/utils/array-extend.mjs' |
| fulltext-filter | Client-side full-text search over an array of objects. Returns results ranked by match score. |
| Module | Description |
|---|---|
| strings | accentMap (diacritics→ASCII), emptyMap (slugify), compareMatch (% word overlap), telColapse/telExpand (phone formatting), basename, dirname, extname, cleanPath, strip_tags, shortString, random. |
| numbers | cislo (locale-aware string→number), formatBytes, cenaNa5Centov (price rounding), ratio (percentage of total). |
| Module | Description |
|---|---|
| dom | toDOM(html) — converts an HTML string to a live DOM Node. |
| copy-code | Clipboard helper for code snippets. Auto-init via data-copy-code attribute (hover button), or manual init with selector/element input. |
| filter-menu | Live search/filter for navigation <li> lists. Auto-init via data-filter-menu attribute; or manual call with { input, selector?, items?, debounceWait? }. |
| position | Element layout: viewport coords (top, left), page coords (topp, leftp), dimensions and computed padding. |
| inViewport | Detects when elements enter/leave the viewport. Configurable threshold, once mode, callbacks, destroy(). |
| inViewportAnim | Triggers Animate.css animations on viewport entry. Per-element data-ivpa-* overrides, lifecycle callbacks, destroy(). |
| Module | Description |
|---|---|
| jsonStorage | localStorage wrapper with automatic JSON serialisation. setItem supports merge mode. |
| jsonStorageSes | Same API as jsonStorage, backed by sessionStorage — cleared on tab close. |
| Module | Description |
|---|---|
| line | Global __LINE__ getter — returns current source file name and line number at the call site. |
| debounce | Delays function execution until a quiet period has passed. |
| class-url | Parses and manipulates the current page URL — path segments, query params, hash. |
| date-time | Date formatting and manipulation helpers with Slovak locale defaults. |
| Module | Description |
|---|---|
| slots-el | Converts Vue 3 slot VNodes to an HTML string (.html) or DOM Node array (.node). Requires Vue 3 peer dependency. |
Vue 3 is an optional peer dependency, required only by slots-el:
npm install vue@^3MIT © pim.sk