Common.Utils

Classes for your scripts

Ovu skriptu ne treba izravno instalirati. To je biblioteka za druge skripte koje se uključuju u meta direktivu // @require https://update.greasyfork.org/scripts/389765/1785927/CommonUtils.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Autor
Anton Shevchuk
Verzija
0.1.0
Stvoreno
04.09.2019.
Ažurirano
29.03.2026.
Size
3,7 KB
Licenza
MIT

Common Utils

Shared utility classes for WME (Waze Map Editor) userscripts.

Require Script

// @require https://greasyfork.org/scripts/389765-common-utils/code/CommonUtils.js?version=XXX

See last available version on the GreasyFork homepage

Development

npm install
npm run build       # one-off build → dist/Utils.user.js
npm run watch       # rebuild on changes

Source is written in TypeScript under src/, built with Rollup into dist/Utils.user.js.

src/
├── meta.ts          # userscript header
├── container.ts     # Container class
├── simple-cache.ts  # SimpleCache extends Container
├── settings.ts      # Settings extends Container
├── tools.ts         # Tools static class
└── index.ts         # exposes all classes to global scope

API

Container

A nested key-value store with path-based access:

let container = new Container()

// set nested values
container.set(['options', 'theme'], 'dark')
container.set(['options', 'lang'], 'uk')

// get nested values
container.get('options', 'theme')  // 'dark'
container.get('options')           // { theme: 'dark', lang: 'uk' }
container.get()                    // entire container

// check existence
container.has('options', 'theme')  // true
container.has('options', 'color')  // false

SimpleCache

Simplified Container with flat key-value interface:

let cache = new SimpleCache()

cache.set('key', result)
cache.has('key')          // true
cache.get('key')          // result

Settings

Container backed by localStorage. Loads on construction, merges stored values over defaults:

// load settings (merges localStorage data over defaults)
let settings = new Settings('my-script', {
  enabled: true,
  radius: 200
})

// read
settings.get('enabled')    // true
settings.get('radius')     // 200

// update
settings.set(['radius'], 500)

// save to localStorage (call before page unload)
settings.save()

With jQuery:

$(window).on('beforeunload', () => settings.save())

Tools

Static utility methods:

// deep merge objects (preserves nested structure)
let result = Tools.mergeDeep({}, defaults, overrides)

// check if value is a plain object
Tools.isObject({})     // true
Tools.isObject([])     // false
Tools.isObject(null)   // false

Links

Author homepage: https://anton.shevchuk.name/
Script homepage: https://github.com/AntonShevchuk/common.utils
GreasyFork: https://greasyfork.org/uk/scripts/389765-common-utils