@idlebox/common 1.3.4 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/docs/package-public.d.ts +40 -0
  2. package/generate/main.ts +56 -0
  3. package/generate/package.json +3 -0
  4. package/generate/tsconfig.json +9 -0
  5. package/lib/_export_all_in_one_index.cjs +3 -1
  6. package/lib/_export_all_in_one_index.cjs.map +1 -1
  7. package/lib/_export_all_in_one_index.js +1 -0
  8. package/lib/_export_all_in_one_index.js.map +1 -1
  9. package/lib/string/concatType.generated.cjs +9 -0
  10. package/lib/string/concatType.generated.cjs.map +10 -0
  11. package/lib/string/concatType.generated.js +5 -0
  12. package/lib/string/concatType.generated.js.map +1 -0
  13. package/package.json +2 -1
  14. package/src/array/arrayDiff.ts +0 -31
  15. package/src/array/arraySame.ts +0 -15
  16. package/src/array/arrayUnique.ts +0 -50
  17. package/src/array/normalizeArray.ts +0 -13
  18. package/src/array/sortAlpha.ts +0 -15
  19. package/src/date/consts.ts +0 -5
  20. package/src/date/isInvalid.ts +0 -6
  21. package/src/date/sibling.ts +0 -28
  22. package/src/date/timeString.ts +0 -150
  23. package/src/date/unix.ts +0 -13
  24. package/src/debugging/tryInspect.ts +0 -37
  25. package/src/error/convertUnknown.ts +0 -10
  26. package/src/error/getFrame.ts +0 -13
  27. package/src/function/asyncCallbackList.ts +0 -75
  28. package/src/function/callbackList.ts +0 -84
  29. package/src/function/delayCallbackList.ts +0 -45
  30. package/src/function/functionName.ts +0 -39
  31. package/src/lifecycle/dispose/bridges/rxjs.ts +0 -6
  32. package/src/lifecycle/dispose/disposableEvent.ts +0 -117
  33. package/src/lifecycle/dispose/disposedError.ts +0 -16
  34. package/src/lifecycle/dispose/lifecycle.async.ts +0 -61
  35. package/src/lifecycle/dispose/lifecycle.global.ts +0 -61
  36. package/src/lifecycle/dispose/lifecycle.sync.ts +0 -79
  37. package/src/lifecycle/dispose/lifecycle.ts +0 -28
  38. package/src/lifecycle/event/event.ts +0 -63
  39. package/src/lifecycle/promise/cancel.ts +0 -16
  40. package/src/lifecycle/promise/cancellationToken/driver.browser.ts +0 -55
  41. package/src/lifecycle/promise/cancellationToken/driver.common.ts +0 -43
  42. package/src/lifecycle/promise/cancellationToken/source.ts +0 -48
  43. package/src/lifecycle/promise/deferredPromise.ts +0 -102
  44. package/src/lifecycle/timeout/timeout.ts +0 -48
  45. package/src/lifecycle/timeout/timeoutError.ts +0 -16
  46. package/src/log/logger.ts +0 -148
  47. package/src/mapSet/customSet.ts +0 -91
  48. package/src/mapSet/extendMap.ts +0 -40
  49. package/src/misc/assertNotNull.ts +0 -21
  50. package/src/object/definePublicConstant.ts +0 -10
  51. package/src/object/initOnRead.ts +0 -27
  52. package/src/object/objectPath.ts +0 -10
  53. package/src/object/objectSame.ts +0 -52
  54. package/src/path/isAbsolute.ts +0 -11
  55. package/src/path/normalizePath.ts +0 -8
  56. package/src/path/pathArray.ts +0 -42
  57. package/src/platform/globalObject.ts +0 -18
  58. package/src/platform/globalSingleton.ts +0 -82
  59. package/src/platform/globalSymbol.ts +0 -36
  60. package/src/platform/os.ts +0 -45
  61. package/src/promise/awaitIterator.ts +0 -19
  62. package/src/promise/finishAllPromise.ts +0 -50
  63. package/src/promise/promiseBool.ts +0 -10
  64. package/src/promise/promisePool.ts +0 -40
  65. package/src/promise/timeoutPromisePool.ts +0 -22
  66. package/src/reflection/classes/hookClass.ts +0 -47
  67. package/src/reflection/classes/singleton.ts +0 -33
  68. package/src/reflection/methods/bind.ts +0 -30
  69. package/src/reflection/methods/initOnRead.ts +0 -11
  70. package/src/reflection/methods/memorize.ts +0 -33
  71. package/src/string/castCase.ts +0 -44
  72. package/src/string/escapeRegexp.ts +0 -4
  73. package/src/string/pad2.ts +0 -11
  74. package/src/string/sizeString.ts +0 -52
  75. package/src/tsconfig.json +0 -12
@@ -1,52 +0,0 @@
1
- import { isArraySame } from '../array/arraySame';
2
-
3
- /**
4
- * Should ensure a and b is none-null before call this
5
- * @returns true when a and b has EXACTLY same keys and values
6
- */
7
- export function isObjectSame(a: any, b: any) {
8
- if (a === b) {
9
- return true;
10
- }
11
- const aks = Object.keys(a);
12
- if (!isArraySame(aks, Object.keys(b))) {
13
- return false;
14
- }
15
-
16
- for (const k of aks) {
17
- if (a[k] !== b[k]) {
18
- return false;
19
- }
20
- }
21
- return true;
22
- }
23
-
24
- /**
25
- * Should ensure a and b is none-null before call this
26
- * @returns true when a and b has EXACTLY same keys and values, recursive compare all object values
27
- */
28
- export function isObjectSameRecursive(a: any, b: any) {
29
- const aks = Object.keys(a);
30
- if (!isArraySame(aks, Object.keys(b))) {
31
- return false;
32
- }
33
-
34
- for (const k of aks) {
35
- if (a[k] !== b[k]) {
36
- const av = a[k],
37
- bv = b[k];
38
- if (av && bv && typeof av === 'object' && typeof bv === 'object') {
39
- if (Array.isArray(av)) {
40
- if (Array.isArray(bv)) {
41
- if (isArraySame(av, bv)) continue;
42
- }
43
- } else if (!Array.isArray(bv)) {
44
- if (isObjectSameRecursive(a[k], b[k])) continue;
45
- }
46
- }
47
-
48
- return false;
49
- }
50
- }
51
- return true;
52
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * return true if a path is absolute:
3
- * - /xxxx
4
- * - \xxxx
5
- * - c:/
6
- * - c:\
7
- * - http://
8
- */
9
- export function isAbsolute(path: string) {
10
- return /^\/|^\\|^[a-z]:[\\/]|^[^:]{1,10}:\/\//i.test(path);
11
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * replace // to /
3
- * replace \ to /
4
- * remove ending /
5
- */
6
- export function normalizePath(p: string) {
7
- return p.replace(/\\+/, '/').replace(/\/\/+/, '/').replace(/\/+$/, '');
8
- }
@@ -1,42 +0,0 @@
1
- import { normalizePath } from './normalizePath';
2
-
3
- /**
4
- * Work on "PATH"-like values
5
- */
6
- export class PathArray extends Set<string> {
7
- constructor(init: string, private readonly sep: ':' | ';') {
8
- super();
9
- if (init) this.add(init);
10
- }
11
-
12
- add(paths: string) {
13
- for (const p of paths.split(this.sep)) {
14
- if (!p) continue;
15
- super.add(normalizePath(p));
16
- }
17
- return this;
18
- }
19
-
20
- delete(paths: string) {
21
- let anyRet = false;
22
- for (const p of paths.split(this.sep)) {
23
- anyRet = anyRet || super.delete(normalizePath(p));
24
- }
25
- return anyRet;
26
- }
27
-
28
- has(path: string): boolean {
29
- return super.has(normalizePath(path));
30
- }
31
-
32
- toString() {
33
- return [...this.values()].join(this.sep);
34
- }
35
-
36
- /**
37
- * @returns an array with `part` append to every element
38
- */
39
- join(part: string) {
40
- return [...this.values()].map((p) => normalizePath(p + '/' + part));
41
- }
42
- }
@@ -1,18 +0,0 @@
1
- declare const global: any;
2
- declare const window: any;
3
-
4
- /**
5
- * globalThis when supported.
6
- * if not, window in browser, global in nodejs
7
- * @public
8
- */
9
- export const globalObject: any =
10
- typeof globalThis === 'undefined' ? (typeof window === 'undefined' ? global : window) : globalThis;
11
-
12
- export function ensureGlobalObject<T>(symbol: string, constructor: () => T): T {
13
- const sm = Symbol.for(symbol);
14
- if (!globalObject[sm]) {
15
- globalObject[sm] = constructor();
16
- }
17
- return globalObject[sm];
18
- }
@@ -1,82 +0,0 @@
1
- import { functionName } from '../function/functionName';
2
- import { ensureGlobalObject } from './globalObject';
3
-
4
- const singletonRegistry = ensureGlobalObject(`@@idlebox/global-singleton`, () => {
5
- return new Map<string | symbol, any>();
6
- });
7
-
8
- /**
9
- * Get an singleton instance from window/global space
10
- * if symbol did not exists, create it and assign to window/global
11
- * @public
12
- */
13
- export function globalSingletonStrong<T>(symbol: symbol | string, constructor: () => T): T;
14
- /**
15
- * Get an singleton instance from window/global space
16
- * @public
17
- */
18
- export function globalSingletonStrong<T>(symbol: symbol | string): T | undefined;
19
-
20
- export function globalSingletonStrong<T>(symbol: symbol | string, constructor?: () => T): T | undefined {
21
- let object = singletonRegistry.get(symbol);
22
- if (object instanceof WeakRef) {
23
- const target = object.deref();
24
- if (target !== undefined) {
25
- object = target;
26
- } else if (constructor) {
27
- object = constructor();
28
- if (object === undefined)
29
- throw new TypeError(`singleton constructor (${functionName(constructor)}) returned undefined.`);
30
- } else {
31
- singletonRegistry.delete(symbol);
32
- return undefined;
33
- }
34
- singletonRegistry.set(symbol, object);
35
- } else if (object === undefined && constructor) {
36
- object = constructor();
37
- if (object === undefined)
38
- throw new TypeError(`singleton constructor (${functionName(constructor)}) returned undefined.`);
39
- singletonRegistry.set(symbol, object);
40
- }
41
- return object;
42
- }
43
-
44
- /**
45
- * Delete a key from window/global space
46
- * use with care
47
- * @public
48
- */
49
- export function globalSingletonDelete(symbol: symbol | string) {
50
- singletonRegistry.delete(symbol);
51
- }
52
-
53
- /**
54
- * Same with globalSingletonStrong, but save instance in a WeakMap, so it maybe delete by gc if no reference
55
- * @public
56
- */
57
- export function globalSingleton<T>(symbol: symbol | string, constructor: () => T): T;
58
- /**
59
- * Same with globalSingletonStrong, but save instance in a WeakMap, so it maybe delete by gc if no reference
60
- * @public
61
- */
62
- export function globalSingleton<T>(symbol: symbol | string): T | undefined;
63
- export function globalSingleton<T>(symbol: symbol | string, constructor?: () => T): T | undefined {
64
- if (singletonRegistry.has(symbol)) {
65
- let object = singletonRegistry.get(symbol);
66
- if (object instanceof WeakRef) {
67
- object = object.deref();
68
- if (object) return object;
69
- singletonRegistry.delete(symbol);
70
- } else {
71
- return object; // strong
72
- }
73
- }
74
-
75
- if (constructor) {
76
- const object = new WeakRef(constructor() as any);
77
- singletonRegistry.set(symbol, object);
78
- return object.deref();
79
- }
80
-
81
- return undefined;
82
- }
@@ -1,36 +0,0 @@
1
- import { ensureGlobalObject } from './globalObject';
2
-
3
- const symbolRegistry = ensureGlobalObject(`@@idlebox/global-symbol`, () => {
4
- return {} as Record<string, Record<string, symbol>>;
5
- });
6
-
7
- /**
8
- * Get a symbol singleton, if not exists, create it
9
- *
10
- * this is very like Symbol.for, but not real global symbol
11
- * @public
12
- */
13
- export function createSymbol(category: string, name: string): symbol {
14
- if (symbolRegistry[category] && symbolRegistry[category][name]) {
15
- return symbolRegistry[category][name];
16
- } else {
17
- if (!symbolRegistry[category]) {
18
- symbolRegistry[category] = {};
19
- }
20
- symbolRegistry[category][name] = Symbol(name);
21
- return symbolRegistry[category][name];
22
- }
23
- }
24
-
25
- /**
26
- * Delete a symbol from window/global object
27
- * @public
28
- */
29
- export function deleteSymbol(category: string, name: string) {
30
- if (symbolRegistry[category] && symbolRegistry[category][name]) {
31
- delete symbolRegistry[category][name];
32
- if (Object.keys(symbolRegistry[category]).length === 0) {
33
- delete symbolRegistry[category];
34
- }
35
- }
36
- }
@@ -1,45 +0,0 @@
1
- declare const process: any;
2
- declare const navigator: any;
3
-
4
- let _isWindows = false;
5
- let _isMacintosh = false;
6
- let _isLinux = false;
7
- let _isNative = false;
8
- let _isWeb = false;
9
- let _userAgent: string;
10
-
11
- export const isElectron =
12
- typeof process !== 'undefined' &&
13
- typeof process.versions !== 'undefined' &&
14
- typeof process.versions.electron !== 'undefined';
15
- export const isElectronRenderer = isElectron && process.type === 'renderer';
16
- export const isElectronMain = !isElectronRenderer;
17
-
18
- if (typeof navigator === 'object' && !isElectronRenderer) {
19
- _userAgent = navigator.userAgent;
20
- _isWindows = _userAgent.indexOf('Windows') >= 0;
21
- _isMacintosh = _userAgent.indexOf('Macintosh') >= 0;
22
- _isLinux = _userAgent.indexOf('Linux') >= 0;
23
- _isWeb = true;
24
- } else if (typeof process === 'object') {
25
- _userAgent = `nodejs(${process.versions.node})`;
26
- if (process.versions.electron) {
27
- _userAgent += ` electron(${process.versions.electron})`;
28
- if (isElectronRenderer) {
29
- _userAgent += ' ' + navigator.userAgent;
30
- }
31
- }
32
- _isWindows = process.platform === 'win32';
33
- _isMacintosh = process.platform === 'darwin';
34
- _isLinux = process.platform === 'linux';
35
- _isNative = true;
36
- } else {
37
- _userAgent = 'unsupported';
38
- }
39
-
40
- export const isWindows = _isWindows;
41
- export const isMacintosh = _isMacintosh;
42
- export const isLinux = _isLinux;
43
- export const isNative = _isNative;
44
- export const isWeb = _isWeb;
45
- export const userAgent = _userAgent;
@@ -1,19 +0,0 @@
1
- /**
2
- * Convert Iterator into Promise, resolve with the last value from Iterator
3
- */
4
- export async function awaitIterator<T>(generator: Iterator<T>): Promise<T> {
5
- let lastValue: any = {};
6
- do {
7
- const itr: IteratorResult<any> = generator.next(lastValue);
8
- if (itr.done) {
9
- return itr.value || lastValue;
10
- }
11
- if (itr.value[Symbol.iterator]) {
12
- lastValue = await awaitIterator(<any>itr.value);
13
- } else if (itr.value.then) {
14
- lastValue = await itr.value;
15
- } else {
16
- lastValue = itr.value;
17
- }
18
- } while (true);
19
- }
@@ -1,50 +0,0 @@
1
- /** @deprecated */
2
- export interface PromiseResultArray<T> {
3
- count: number;
4
- fulfilledResult: T[];
5
- fulfilled: number[];
6
- rejectedResult: Error[];
7
- rejected: number[];
8
- }
9
-
10
- /**
11
- * @deprecated Use Promise.allSettled instead
12
- */
13
- export function finishAllPromise<T>(ps: Promise<T>[]) {
14
- return new Promise<PromiseResultArray<T>>((resolve) => {
15
- const fulfilledResult: T[] = [];
16
- const rejectedResult: Error[] = [];
17
- const fulfilled: number[] = [];
18
- const rejected: number[] = [];
19
- let last = ps.length;
20
-
21
- const toDone = () => {
22
- if (last === 0) {
23
- resolve({
24
- count: ps.length,
25
- fulfilledResult,
26
- fulfilled,
27
- rejectedResult,
28
- rejected,
29
- });
30
- }
31
- };
32
-
33
- ps.forEach((p, index) => {
34
- p.then(
35
- (t) => {
36
- fulfilledResult[index] = t;
37
- fulfilled.push(index);
38
- last--;
39
- toDone();
40
- },
41
- (e) => {
42
- rejectedResult[index] = e;
43
- rejected.push(index);
44
- last--;
45
- toDone();
46
- }
47
- );
48
- });
49
- });
50
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * resolve with true when `p` resolve
3
- * resolve with false when `p` reject (and drop error)
4
- */
5
- export function promiseBool(p: Promise<any>): Promise<boolean> {
6
- return p.then(
7
- () => true,
8
- () => false
9
- );
10
- }
@@ -1,40 +0,0 @@
1
- import { CanceledError } from '../lifecycle/promise/cancel';
2
- import { DeferredPromise } from '../lifecycle/promise/deferredPromise';
3
-
4
- export class PromisePool {
5
- protected readonly promiseList: Record<string, DeferredPromise<any>> = {};
6
-
7
- size() {
8
- return Object.keys(this.promiseList).length;
9
- }
10
-
11
- create(id: string) {
12
- if (this.promiseList[id]) {
13
- throw new Error('duplicate promise with id ' + id);
14
- }
15
- const dfd = new DeferredPromise<any>();
16
- this.promiseList[id] = dfd;
17
- return dfd.p;
18
- }
19
-
20
- has(id: string) {
21
- return this.promiseList.hasOwnProperty(id);
22
- }
23
-
24
- done(id: string, data: any) {
25
- this.promiseList[id].complete(data);
26
- delete this.promiseList[id];
27
- }
28
-
29
- error(id: string, e: Error) {
30
- this.promiseList[id].error(e);
31
- delete this.promiseList[id];
32
- }
33
-
34
- dispose() {
35
- const e = new CanceledError();
36
- for (const id of Object.keys(this.promiseList)) {
37
- this.error(id, e);
38
- }
39
- }
40
- }
@@ -1,22 +0,0 @@
1
- import { TimeoutError } from '../lifecycle/timeout/timeoutError';
2
- import { PromisePool } from './promisePool';
3
-
4
- export class TimeoutPromisePool extends PromisePool {
5
- constructor(private readonly defaultTimeoutMs = 50000) {
6
- super();
7
- }
8
-
9
- create(id: string, timeoutMs: number = this.defaultTimeoutMs, timeoutMsg?: string) {
10
- const p = super.create(id);
11
-
12
- const to = setTimeout(() => {
13
- this.error(id, new TimeoutError(timeoutMs, timeoutMsg));
14
- }, timeoutMs);
15
-
16
- p.finally(() => {
17
- clearTimeout(to);
18
- });
19
-
20
- return p;
21
- }
22
- }
@@ -1,47 +0,0 @@
1
- export const hookClassSymbol = Symbol('@gongt/hookClass');
2
-
3
- interface IConstructorOf<T> extends Object {
4
- new (...args: any[]): T;
5
- }
6
-
7
- interface IHooks<T, TC> {
8
- afterConstruct?: ((obj: T) => void)[];
9
- beforeConstruct?: ((obj: TC) => T | void)[];
10
- }
11
-
12
- export function hookClass<TC extends IConstructorOf<T>, T>(target: TC): IHooks<T, TC> {
13
- if ((target as any)[hookClassSymbol]) {
14
- return (target as any)[hookClassSymbol];
15
- }
16
-
17
- const hooks = {} as IHooks<T, TC>;
18
-
19
- const proxyTarget = new Proxy(target, {
20
- construct(target: any, argArray: any): object {
21
- if (hooks.beforeConstruct) {
22
- for (const beforeCb of hooks.beforeConstruct) {
23
- const ret = beforeCb(target);
24
- if (ret) {
25
- return ret as any;
26
- }
27
- }
28
- }
29
- const d = new target(...argArray);
30
- if (hooks.afterConstruct) {
31
- for (const afterCb of hooks.afterConstruct) {
32
- afterCb(d);
33
- }
34
- }
35
- return d;
36
- },
37
- });
38
-
39
- Object.defineProperty(proxyTarget, hookClassSymbol, {
40
- value: hooks,
41
- enumerable: false,
42
- configurable: false,
43
- writable: false,
44
- });
45
-
46
- return hooks;
47
- }
@@ -1,33 +0,0 @@
1
- import { hookClass } from './hookClass';
2
-
3
- export const singletonSymbol = Symbol('@gongt/singleton');
4
-
5
- export enum SingletonType {
6
- Throw,
7
- Return,
8
- }
9
-
10
- export function singleton(type: SingletonType = SingletonType.Return): ClassDecorator {
11
- return (target: any): any => {
12
- const hook = hookClass(target);
13
- if (!hook.beforeConstruct) {
14
- hook.beforeConstruct = [];
15
- }
16
- if (!hook.afterConstruct) {
17
- hook.afterConstruct = [];
18
- }
19
-
20
- hook.beforeConstruct.push((cls) => {
21
- if (cls[singletonSymbol]) {
22
- if (type === SingletonType.Return) {
23
- return cls[singletonSymbol];
24
- } else {
25
- throw new Error(`Duplicate new singleton class [${target.name}]`);
26
- }
27
- }
28
- });
29
- hook.afterConstruct.push((obj) => {
30
- target[singletonSymbol] = obj;
31
- });
32
- };
33
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * Auto bind `this` to class method
3
- */
4
- export const bindThis: MethodDecorator = <T>(
5
- _target: Object,
6
- propertyKey: string | symbol,
7
- descriptor: TypedPropertyDescriptor<T>
8
- ) => {
9
- const oldFunc = descriptor.value;
10
- if (typeof oldFunc === 'function') {
11
- return {
12
- enumerable: true,
13
- configurable: true,
14
- get: function (this: any) {
15
- delete this[propertyKey];
16
-
17
- const fn = oldFunc.bind(this);
18
- Object.defineProperty(this, propertyKey, {
19
- value: fn,
20
- writable: false,
21
- enumerable: true,
22
- configurable: false,
23
- });
24
- return fn;
25
- },
26
- };
27
- } else {
28
- throw new TypeError('@bindThis can only use with method, but not property.');
29
- }
30
- };
@@ -1,11 +0,0 @@
1
- import { InitFunc, initOnRead } from '../../object/initOnRead';
2
-
3
- /**
4
- * Decorater version of `initOnRead`
5
- * @see initOnRead
6
- */
7
- export function init<O, T extends keyof O>(init: InitFunc<O, O[T]>): PropertyDecorator {
8
- return function (target: O, propertyKey: T) {
9
- initOnRead<O, T>(target, propertyKey, init);
10
- } as any;
11
- }
@@ -1,33 +0,0 @@
1
- export const memorizeValueSymbol = Symbol('@gongt/memorizeValue');
2
-
3
- /**
4
- * Decorate class method/getter
5
- *
6
- * remember first return value of method/getter, directlly return memorized value when call it again
7
- */
8
- export const memo: MethodDecorator = <T>(
9
- _target: Object,
10
- propertyKey: string | symbol,
11
- descriptor: TypedPropertyDescriptor<T>
12
- ) => {
13
- const original: Function = (descriptor.value ? descriptor.value : descriptor.get) as any;
14
- if (descriptor.set || typeof original !== 'function') {
15
- throw new TypeError('@memo should only use on method, or getter. Not property and setter.');
16
- }
17
-
18
- if (descriptor.get) {
19
- descriptor.get = function memo_getter(this: any) {
20
- const value = original.call(this, arguments);
21
- Object.defineProperty(this, propertyKey, { value });
22
- return value;
23
- };
24
- } else {
25
- descriptor.value = function memo_method(this: any) {
26
- const value = original.call(this, arguments);
27
- Object.defineProperty(this, propertyKey, { value: () => value });
28
- return value;
29
- } as any;
30
- }
31
-
32
- return descriptor;
33
- };
@@ -1,44 +0,0 @@
1
- /** @public */
2
- export function camelCase(str: string) {
3
- return str.replace(/[-.\/_][a-z]/g, (s) => {
4
- return s[1].toUpperCase();
5
- });
6
- }
7
-
8
- /**
9
- * Uppercase first char
10
- * @public
11
- */
12
- export function ucfirst<T extends string>(str: T): Capitalize<T> {
13
- return <any>(str[0].toUpperCase() + str.slice(1));
14
- }
15
-
16
- /**
17
- * lowercase first char
18
- * @public
19
- */
20
- export function lcfirst<T extends string>(str: T): Uncapitalize<T> {
21
- return <any>(str[0].toLowerCase() + str.slice(1));
22
- }
23
-
24
- /** @public */
25
- export function linux_case(str: string) {
26
- return str
27
- .replace(/^[A-Z]/, (s) => {
28
- return s.toLowerCase();
29
- })
30
- .replace(/[A-Z]/g, (s) => {
31
- return '_' + s.toLowerCase();
32
- });
33
- }
34
-
35
- /** @public */
36
- export function linux_case_hyphen(str: string) {
37
- return str
38
- .replace(/^[A-Z]/, (s) => {
39
- return s.toLowerCase();
40
- })
41
- .replace(/[A-Z]/g, (s) => {
42
- return '-' + s.toLowerCase();
43
- });
44
- }
@@ -1,4 +0,0 @@
1
- /** @public */
2
- export function escapeRegExp(str: string) {
3
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
4
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Pad number to two digits string, used in time format
3
- * @public
4
- */
5
- export function pad2(s: number) {
6
- if (s < 10) {
7
- return '0' + s;
8
- } else {
9
- return '' + s;
10
- }
11
- }