Common.Utils

Classes for your scripts

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/389765/1785927/CommonUtils.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

लेखक
Anton Shevchuk
आवृत्ती
0.1.0
बनवली
2019-09-04
अपडेट केली
2026-03-29
आकार
3.7 KB
License
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