Common.Utils

Classes for your scripts

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/389765/1785927/CommonUtils.js을(를) 사용하여 포함하는 라이브러리입니다.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

작성자
Anton Shevchuk
버전
0.1.0
생성일
2019-09-04
갱신일
2026-03-29
크기
3.7KB
라이선스
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