1.6.1 • Published 10 months ago
@om-design/util v1.6.1
@om-design/util
a base util library
features
- typings & typings guards
- string operation
- math operation
- tree operation
- hash algorithm
- binary encoding & decoding
- collections
- functions
- style relevants
- dom relevants
demos
some basic usage for some modules
typings
import {Action, Action2, Func, Func2, Predicate, Tuple, Tuple2} from '@om-design/util'
const action: Action<string> = (arg: string): void => console.log(arg);
const action2: Action2<string, number> = (arg1: string, arg2: number): void => console.log(arg1, arg2);
const func: Func<string, boolean> = (arg: string): boolean => !!arg;
const func2: Func<string, number, boolean> = (arg1: string, arg2: number): boolean => !!(arg1 + arg2);
const predicate: Predicate<number> = (arg: number): boolean => arg === 5;
const tuple: Tuple<number> = [2];
const tuple2: Tuple2<number, string> = [2, 'hello world'];
string operation
import { pad, padRight, kebablize, pascalize, camelize } from '@om-design/util'
console.log(pad('12', 4)) // 0012
console.log(pad('12', 4, 'nn')) // nn12
console.log(padRight('12', 4)) // 1200
console.log(padRight('12', 4, 'nn')) // 12nn
console.log(kebablize('HelloWorld')) // hello-world
console.log(pascalize('hello-world')) // HelloWorld
console.log(camelize('HelloWorld')) // helloWorld
console.log(camelize('hello-world')) // helloWorld
math operation
import { clamp, toFixedEx } from '@om-design/util'
console.log(clamp(-1, 0, 100)) // 0
console.log(clamp(101, 0, 100)) // 100
console.log(clamp(2, 0, 100)) // 2
console.log(toFixedEx(99.9999,2), 99.9999.toFixed(2)) // 99.99 100.00
hash algorithm
import { murmurHash3, Murmur3 } from '@om-design/util';
(async()=>{
const str = 'hello world';
const hash1 = murmurHash3(str); // use javascript float number
const hash2 = await Murmur3.hash32Async(str); // use strickly int32 number
console.log(hash1, hash2, hash1 === hash2);
})();
style relevant
import { createRoot } from '@om-design/util';
const [bem] = createRoot('o');
console.log(bem('btn')) // o-btn
console.log(bem('btn',{active: true, hide: false})) // o-btn o-btn--active
console.log(bem('btn', ['long'])) // o-btn o-btn--long
cossole.log(bem('btn', ['long',{active: true}])) // o-btn o-btn--long o-btn--active
functions
import { debounce, throttle } from '@om-design/util';
const dfunc = debounce(()=>console.log(1), 200) // ship from lodash
const tfunc = throttle(() => console.log(2), 300) // ship from lodash
1.6.1
10 months ago
1.6.0
10 months ago
1.5.0
10 months ago
1.4.0
10 months ago
1.3.1
10 months ago
1.3.0
10 months ago
1.2.0
10 months ago
1.1.0
11 months ago
1.0.0
11 months ago
0.8.4
1 year ago
0.14.5
12 months ago
0.14.6
12 months ago
0.11.0
12 months ago
0.10.1
1 year ago
0.12.0
12 months ago
0.11.1
12 months ago
0.13.0
12 months ago
0.14.0
12 months ago
0.13.1
12 months ago
0.15.0
12 months ago
0.14.1
12 months ago
0.13.2
12 months ago
0.16.0
11 months ago
0.15.1
12 months ago
0.14.2
12 months ago
0.17.0
11 months ago
0.14.3
12 months ago
0.14.4
12 months ago
0.10.0
1 year ago
0.9.0
1 year ago
0.8.1
1 year ago
0.8.0
1 year ago
0.8.3
1 year ago
0.8.2
1 year ago
0.7.0
1 year ago
0.5.0
1 year ago
0.3.0
1 year ago
0.2.0
1 year ago
0.4.1
1 year ago
0.4.0
1 year ago
0.1.0
2 years ago