@ev-core/core 0.6.1 → 0.6.2
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.
- package/dist/esm/html/element-attributer.d.ts +7 -0
- package/dist/esm/html/element-attributer.js +15 -0
- package/dist/esm/html/element-classer.d.ts +3 -0
- package/dist/esm/html/element-classer.js +13 -0
- package/dist/esm/html/element-listening.d.ts +8 -0
- package/dist/esm/html/element-listening.js +13 -0
- package/dist/esm/html/element-manager.d.ts +42 -0
- package/dist/esm/html/element-manager.js +115 -0
- package/dist/esm/html/element-styler.d.ts +3 -0
- package/dist/esm/html/element-styler.js +15 -0
- package/dist/esm/html/index.d.ts +6 -0
- package/dist/esm/html/index.js +6 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/interfaces/disposable.d.ts +4 -0
- package/dist/esm/interfaces/disposable.js +2 -0
- package/dist/esm/services/event-listener-service.d.ts +23 -0
- package/dist/esm/services/event-listener-service.js +54 -0
- package/dist/esm/utils/array.d.ts +2 -0
- package/dist/esm/utils/array.js +9 -0
- package/dist/esm/utils/date.d.ts +3 -0
- package/dist/esm/utils/date.js +33 -0
- package/dist/esm/utils/file.d.ts +16 -0
- package/dist/esm/utils/file.js +56 -0
- package/dist/esm/utils/guid.d.ts +2 -0
- package/dist/esm/utils/guid.js +7 -0
- package/dist/esm/utils/is-of.d.ts +10 -0
- package/dist/esm/utils/is-of.js +29 -0
- package/dist/esm/utils/mime-types.d.ts +23 -0
- package/dist/esm/utils/mime-types.js +54 -0
- package/dist/esm/utils/name-of.d.ts +2 -0
- package/dist/esm/utils/name-of.js +10 -0
- package/dist/esm/utils/object.d.ts +2 -0
- package/dist/esm/utils/object.js +14 -0
- package/dist/esm/utils/slugify.d.ts +2 -0
- package/dist/esm/utils/slugify.js +14 -0
- package/dist/esm/utils/strings.d.ts +3 -0
- package/dist/esm/utils/strings.js +5 -0
- package/dist/esm/utils/url.d.ts +2 -0
- package/dist/esm/utils/url.js +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function addAttrs(el, attrs) {
|
|
2
|
+
if (el && attrs) {
|
|
3
|
+
Object.keys(attrs).forEach(k => {
|
|
4
|
+
el.setAttribute(k, attrs[k]);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function removeAttrs(el, attrs) {
|
|
9
|
+
if (el && attrs) {
|
|
10
|
+
Object.keys(attrs).forEach(k => {
|
|
11
|
+
el.removeAttribute(k);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=element-attributer.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function removeClasses(el, classes) {
|
|
2
|
+
if (el && classes?.length) {
|
|
3
|
+
let list = typeof classes == 'string' ? classes.split(' ') : classes;
|
|
4
|
+
el.classList.remove(...list);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function addClasses(el, classes) {
|
|
8
|
+
if (el && classes?.length) {
|
|
9
|
+
let list = typeof classes == 'string' ? classes.split(' ') : classes;
|
|
10
|
+
el.classList.add(...list);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=element-classer.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function removeEventListeners(el?: HTMLElement, events?: IElementTogglerListener[]): void;
|
|
2
|
+
export declare function addEventListeners(el?: HTMLElement, events?: IElementTogglerListener[]): void;
|
|
3
|
+
export interface IElementTogglerListener {
|
|
4
|
+
key: string;
|
|
5
|
+
event: <K extends keyof HTMLElementEventMap>(ev: HTMLElementEventMap[K]) => any;
|
|
6
|
+
options?: boolean | AddEventListenerOptions;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=element-listening.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function removeEventListeners(el, events) {
|
|
2
|
+
if (el && events?.length) {
|
|
3
|
+
events.forEach(e => {
|
|
4
|
+
el?.removeEventListener(e.key, e.event, e.options);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function addEventListeners(el, events) {
|
|
9
|
+
if (el && events?.length) {
|
|
10
|
+
events.forEach(e => el.addEventListener(e.key, e.event, e.options));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=element-listening.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IElementTogglerListener } from "./element-listening";
|
|
2
|
+
export declare class ElementManager implements IElementTogglerArgs {
|
|
3
|
+
private _counter;
|
|
4
|
+
get counter(): number;
|
|
5
|
+
el?: HTMLElement;
|
|
6
|
+
attrs: {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
};
|
|
9
|
+
css: Partial<CSSStyleDeclaration>;
|
|
10
|
+
classes: string[];
|
|
11
|
+
listeners: IElementTogglerListener[];
|
|
12
|
+
data: any;
|
|
13
|
+
static create: (args: IElementTogglerArgs) => ElementManager;
|
|
14
|
+
private constructor();
|
|
15
|
+
private setProperties;
|
|
16
|
+
private get mutableProperties();
|
|
17
|
+
get properties(): IElementTogglerArgs;
|
|
18
|
+
setElement(el: HTMLElement, cleanPrevious?: boolean): void;
|
|
19
|
+
apply(cb?: (args: IElementTogglerArgs) => void, cleanPrevious?: boolean): this;
|
|
20
|
+
private count;
|
|
21
|
+
remove(): this;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
private removeListeners;
|
|
24
|
+
private removeClass;
|
|
25
|
+
private removeCss;
|
|
26
|
+
private removeAttrs;
|
|
27
|
+
private applyListeners;
|
|
28
|
+
private applyClass;
|
|
29
|
+
private applyCss;
|
|
30
|
+
private applyAttrs;
|
|
31
|
+
}
|
|
32
|
+
export interface IElementTogglerArgs {
|
|
33
|
+
el?: HTMLElement;
|
|
34
|
+
attrs?: {
|
|
35
|
+
[key: string]: string;
|
|
36
|
+
};
|
|
37
|
+
css?: Partial<CSSStyleDeclaration>;
|
|
38
|
+
classes?: string[];
|
|
39
|
+
listeners?: IElementTogglerListener[];
|
|
40
|
+
data?: any;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=element-manager.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { addAttrs, removeAttrs } from "./element-attributer";
|
|
2
|
+
import { addClasses, removeClasses } from "./element-classer";
|
|
3
|
+
import { addEventListeners, removeEventListeners } from "./element-listening";
|
|
4
|
+
import { addStyles, removeStyles } from "./element-styler";
|
|
5
|
+
export class ElementManager {
|
|
6
|
+
get counter() { return this._counter; }
|
|
7
|
+
constructor(args) {
|
|
8
|
+
this._counter = 0;
|
|
9
|
+
this.setProperties(args);
|
|
10
|
+
}
|
|
11
|
+
setProperties(args) {
|
|
12
|
+
this.el = args.el;
|
|
13
|
+
this.css = args.css ?? {};
|
|
14
|
+
this.classes = args?.classes ?? [];
|
|
15
|
+
this.attrs = args?.attrs ?? {};
|
|
16
|
+
this.data = args?.data;
|
|
17
|
+
}
|
|
18
|
+
get mutableProperties() {
|
|
19
|
+
return {
|
|
20
|
+
el: this.el,
|
|
21
|
+
attrs: this.attrs,
|
|
22
|
+
classes: this.classes,
|
|
23
|
+
css: this.css,
|
|
24
|
+
listeners: this.listeners,
|
|
25
|
+
data: this.data,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
;
|
|
29
|
+
get properties() {
|
|
30
|
+
return {
|
|
31
|
+
attrs: Object.assign({}, this.attrs ?? {}),
|
|
32
|
+
classes: this.classes?.slice() ?? [],
|
|
33
|
+
css: Object.assign({}, this.css ?? {}),
|
|
34
|
+
data: this.data
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
setElement(el, cleanPrevious = true) {
|
|
38
|
+
if (cleanPrevious) {
|
|
39
|
+
this.remove();
|
|
40
|
+
}
|
|
41
|
+
this.el = el;
|
|
42
|
+
}
|
|
43
|
+
apply(cb, cleanPrevious = true) {
|
|
44
|
+
let current = this.mutableProperties;
|
|
45
|
+
if (cb) {
|
|
46
|
+
cb(current);
|
|
47
|
+
}
|
|
48
|
+
if (cleanPrevious) {
|
|
49
|
+
this.remove();
|
|
50
|
+
}
|
|
51
|
+
this.setProperties(current);
|
|
52
|
+
this
|
|
53
|
+
.applyListeners()
|
|
54
|
+
.applyClass()
|
|
55
|
+
.applyCss()
|
|
56
|
+
.applyAttrs()
|
|
57
|
+
.count();
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
count() {
|
|
61
|
+
this._counter++;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
remove() {
|
|
65
|
+
return this
|
|
66
|
+
.removeListeners()
|
|
67
|
+
.removeClass()
|
|
68
|
+
.removeCss()
|
|
69
|
+
.removeAttrs();
|
|
70
|
+
}
|
|
71
|
+
dispose() {
|
|
72
|
+
this.removeListeners();
|
|
73
|
+
this.setProperties({
|
|
74
|
+
el: undefined,
|
|
75
|
+
attrs: {},
|
|
76
|
+
classes: [],
|
|
77
|
+
css: {},
|
|
78
|
+
listeners: []
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
removeListeners() {
|
|
82
|
+
removeEventListeners(this.el, this.listeners);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
removeClass() {
|
|
86
|
+
removeClasses(this.el, this.classes);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
removeCss() {
|
|
90
|
+
removeStyles(this.el, this.css);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
removeAttrs() {
|
|
94
|
+
removeAttrs(this.el, this.attrs);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
applyListeners() {
|
|
98
|
+
addEventListeners(this.el, this.listeners);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
applyClass() {
|
|
102
|
+
addClasses(this.el, this.classes);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
applyCss() {
|
|
106
|
+
addStyles(this.el, this.css);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
applyAttrs() {
|
|
110
|
+
addAttrs(this.el, this.attrs);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
ElementManager.create = (args) => new ElementManager(args);
|
|
115
|
+
//# sourceMappingURL=element-manager.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function addStyles(el, css) {
|
|
2
|
+
if (el && css) {
|
|
3
|
+
Object.keys(css).forEach(k => {
|
|
4
|
+
el.style[k] = css[k];
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function removeStyles(el, css) {
|
|
9
|
+
if (el && css) {
|
|
10
|
+
Object.keys(css).forEach(k => {
|
|
11
|
+
el.style[k] = undefined;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=element-styler.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './interfaces/disposable';
|
|
2
|
+
export * as Htmler from './html';
|
|
3
|
+
export * from './utils/array';
|
|
4
|
+
export * from './utils/date';
|
|
5
|
+
export * from './utils/file';
|
|
6
|
+
export * from './utils/guid';
|
|
7
|
+
export * from './utils/is-of';
|
|
8
|
+
export * from './utils/mime-types';
|
|
9
|
+
export * from './utils/name-of';
|
|
10
|
+
export * from './utils/object';
|
|
11
|
+
export * from './utils/slugify';
|
|
12
|
+
export * from './utils/strings';
|
|
13
|
+
export * from './utils/url';
|
|
14
|
+
export * from './services/event-listener-service';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './interfaces/disposable';
|
|
2
|
+
export * as Htmler from './html';
|
|
3
|
+
export * from './utils/array';
|
|
4
|
+
export * from './utils/date';
|
|
5
|
+
export * from './utils/file';
|
|
6
|
+
export * from './utils/guid';
|
|
7
|
+
export * from './utils/is-of';
|
|
8
|
+
export * from './utils/mime-types';
|
|
9
|
+
export * from './utils/name-of';
|
|
10
|
+
export * from './utils/object';
|
|
11
|
+
export * from './utils/slugify';
|
|
12
|
+
export * from './utils/strings';
|
|
13
|
+
export * from './utils/url';
|
|
14
|
+
export * from './services/event-listener-service';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IDisposable } from "../interfaces/disposable";
|
|
2
|
+
export type TEventType = (keyof DocumentEventMap) | string;
|
|
3
|
+
export declare class DomListenerService {
|
|
4
|
+
private listeners;
|
|
5
|
+
register(element: Document | HTMLElement, event: TEventType, callback: (event: Event) => void, capture?: boolean): DomListenerItem;
|
|
6
|
+
getListeners(): DomListenerItem[];
|
|
7
|
+
private remove;
|
|
8
|
+
}
|
|
9
|
+
export declare class DomListenerItem implements IDisposable {
|
|
10
|
+
readonly element: Document | HTMLElement | Window;
|
|
11
|
+
readonly event: TEventType;
|
|
12
|
+
private readonly callback;
|
|
13
|
+
readonly capture: boolean;
|
|
14
|
+
private removeCallback;
|
|
15
|
+
private isActive;
|
|
16
|
+
constructor(element: Document | HTMLElement | Window, event: TEventType, callback: (event: Event) => void, capture: boolean, removeCallback: (listener: DomListenerItem) => void);
|
|
17
|
+
activate(): this;
|
|
18
|
+
deactivate(): this;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
private delayedAttach;
|
|
21
|
+
private attach;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=event-listener-service.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class DomListenerService {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = [];
|
|
4
|
+
}
|
|
5
|
+
register(element, event, callback, capture = false) {
|
|
6
|
+
const listener = new DomListenerItem(element, event, callback, capture, this.remove.bind(this));
|
|
7
|
+
this.listeners.push(listener);
|
|
8
|
+
return listener;
|
|
9
|
+
}
|
|
10
|
+
getListeners() {
|
|
11
|
+
return this.listeners;
|
|
12
|
+
}
|
|
13
|
+
remove(listener) {
|
|
14
|
+
const index = this.listeners.indexOf(listener);
|
|
15
|
+
if (index !== -1) {
|
|
16
|
+
this.listeners.splice(index, 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class DomListenerItem {
|
|
21
|
+
constructor(element, event, callback, capture, removeCallback) {
|
|
22
|
+
this.element = element;
|
|
23
|
+
this.event = event;
|
|
24
|
+
this.callback = callback;
|
|
25
|
+
this.capture = capture;
|
|
26
|
+
this.removeCallback = removeCallback;
|
|
27
|
+
this.isActive = false;
|
|
28
|
+
}
|
|
29
|
+
activate() {
|
|
30
|
+
if (!this.isActive) {
|
|
31
|
+
this.delayedAttach();
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
deactivate() {
|
|
36
|
+
if (this.isActive) {
|
|
37
|
+
this.element.removeEventListener(this.event, this.callback, this.capture);
|
|
38
|
+
this.isActive = false;
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
dispose() {
|
|
43
|
+
this.deactivate();
|
|
44
|
+
this.removeCallback(this); // Notify the service to remove this from its tracking list
|
|
45
|
+
}
|
|
46
|
+
delayedAttach() {
|
|
47
|
+
setTimeout(() => { this.attach(); }, 0);
|
|
48
|
+
}
|
|
49
|
+
attach() {
|
|
50
|
+
this.element.addEventListener(this.event, this.callback, this.capture);
|
|
51
|
+
this.isActive = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=event-listener-service.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function dateParse(value) {
|
|
2
|
+
if (value == undefined) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
if (value instanceof Date) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (typeof value == 'string') {
|
|
9
|
+
if (value.toLowerCase() == 'today') {
|
|
10
|
+
return new Date();
|
|
11
|
+
}
|
|
12
|
+
let v = new Date(String(value));
|
|
13
|
+
if (isValidDate(v)) {
|
|
14
|
+
return v;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let number = Number.parseInt(String(value));
|
|
18
|
+
if (Number.isInteger(number)) {
|
|
19
|
+
const d = new Date();
|
|
20
|
+
d.setDate(d.getDate() + number);
|
|
21
|
+
return d;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
function isValidDate(date) {
|
|
26
|
+
try {
|
|
27
|
+
return Number.isInteger(date.getTime());
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class FileinputCall {
|
|
2
|
+
private readonly doc;
|
|
3
|
+
private el;
|
|
4
|
+
constructor(doc?: Document);
|
|
5
|
+
call(opts?: IFileInputOptions): Promise<FileList>;
|
|
6
|
+
private init;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
9
|
+
export interface IFileInputOptions {
|
|
10
|
+
multiple?: boolean;
|
|
11
|
+
accept?: string;
|
|
12
|
+
capture?: string;
|
|
13
|
+
webkitdirectory?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function saveAs(blob: File | Blob, filename: string, globalWindow?: Window & typeof globalThis): void;
|
|
16
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export class FileinputCall {
|
|
2
|
+
constructor(doc = document) {
|
|
3
|
+
this.doc = doc;
|
|
4
|
+
this.el = null;
|
|
5
|
+
}
|
|
6
|
+
call(opts) {
|
|
7
|
+
this.init(opts);
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
this.el.onchange = () => {
|
|
10
|
+
const files = this.el.files;
|
|
11
|
+
this.destroy(); // Clean up after selection
|
|
12
|
+
resolve(files);
|
|
13
|
+
};
|
|
14
|
+
this.el.click();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
init(opts) {
|
|
18
|
+
this.destroy();
|
|
19
|
+
this.el = this.doc.createElement('input');
|
|
20
|
+
this.el.type = 'file';
|
|
21
|
+
// Hide the input element
|
|
22
|
+
this.el.style.display = 'none';
|
|
23
|
+
// Append to the document to ensure the file picker works in all browsers
|
|
24
|
+
this.doc.body.appendChild(this.el);
|
|
25
|
+
// Allowed options for the file input element
|
|
26
|
+
const allowedOptions = [
|
|
27
|
+
'multiple',
|
|
28
|
+
'accept',
|
|
29
|
+
'capture',
|
|
30
|
+
'webkitdirectory',
|
|
31
|
+
];
|
|
32
|
+
if (opts) {
|
|
33
|
+
allowedOptions.forEach((key) => {
|
|
34
|
+
if (opts[key] !== undefined) {
|
|
35
|
+
this.el[key] = opts[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
destroy() {
|
|
41
|
+
if (this.el && this.el.parentElement) {
|
|
42
|
+
this.el.parentElement.removeChild(this.el);
|
|
43
|
+
this.el = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function saveAs(blob, filename, globalWindow = window) {
|
|
48
|
+
const a = globalWindow.document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
|
|
49
|
+
a.download = filename;
|
|
50
|
+
a.rel = 'noopener';
|
|
51
|
+
a.href = globalWindow.URL.createObjectURL(blob);
|
|
52
|
+
const timeout = 40 * 1000;
|
|
53
|
+
globalWindow.setTimeout(() => URL.revokeObjectURL(a.href), timeout);
|
|
54
|
+
globalWindow.setTimeout(() => a.click(), 0);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function uuidv4() {
|
|
2
|
+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => {
|
|
3
|
+
const parsed = Number.parseInt(c);
|
|
4
|
+
return (parsed ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> parsed / 4).toString(16);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=guid.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type InstanceType = 'string' | 'number' | 'boolean' | 'bigint' | 'function' | 'symbol' | 'undefined' | Object | any;
|
|
2
|
+
export declare function isPrimitive(arg: any): boolean;
|
|
3
|
+
export declare function typeOf(obj: any): any;
|
|
4
|
+
export declare function instanceOf(obj: any, type: InstanceType): any;
|
|
5
|
+
export declare function isString(obj: any): obj is string;
|
|
6
|
+
export declare function isNumber(obj: any): obj is number;
|
|
7
|
+
export declare function isBool(obj: any): obj is boolean;
|
|
8
|
+
export declare function isDate(obj: any): obj is Date;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=is-of.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function isPrimitive(arg) {
|
|
2
|
+
const type = typeof arg;
|
|
3
|
+
return arg == null || (type != "object" && type != "function");
|
|
4
|
+
}
|
|
5
|
+
export function typeOf(obj) { return Object.getPrototypeOf(obj).constructor; }
|
|
6
|
+
export function instanceOf(obj, type) {
|
|
7
|
+
if (isPrimitive(obj)) {
|
|
8
|
+
return typeof obj === type;
|
|
9
|
+
}
|
|
10
|
+
const objType = typeOf(obj);
|
|
11
|
+
return (
|
|
12
|
+
// Allow native instanceof in case of Symbol.hasInstance
|
|
13
|
+
obj instanceof type ||
|
|
14
|
+
// Handle case where is of type type
|
|
15
|
+
typeof obj === type ||
|
|
16
|
+
// Handle general case
|
|
17
|
+
type.isPrototypeOf(objType) ||
|
|
18
|
+
// Handle special case where type.prototype acts as a
|
|
19
|
+
// prototype of the object but its type isn't in the
|
|
20
|
+
// prototype chain of the obj's type
|
|
21
|
+
// OPTIONALLY remove this case if you don't want
|
|
22
|
+
// primitives to be considered instances of Object
|
|
23
|
+
type.prototype.isPrototypeOf(objType.prototype));
|
|
24
|
+
}
|
|
25
|
+
export function isString(obj) { return typeof obj === 'string'; }
|
|
26
|
+
export function isNumber(obj) { return typeof obj === 'number'; }
|
|
27
|
+
export function isBool(obj) { return typeof obj === 'boolean'; }
|
|
28
|
+
export function isDate(obj) { return obj instanceof Date; }
|
|
29
|
+
//# sourceMappingURL=is-of.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare class MimeType {
|
|
2
|
+
readonly type: string;
|
|
3
|
+
readonly exts: string[];
|
|
4
|
+
constructor(type: string, exts: string[]);
|
|
5
|
+
}
|
|
6
|
+
declare class MimeGroup {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly types: MimeType[];
|
|
9
|
+
constructor(name: string, types: MimeType[]);
|
|
10
|
+
findExtension(type: string): string;
|
|
11
|
+
findExtensions(type: string): string[];
|
|
12
|
+
findType(extension: string): string;
|
|
13
|
+
}
|
|
14
|
+
export declare const imageMimeTypes: MimeType[];
|
|
15
|
+
declare class MimeFinder {
|
|
16
|
+
readonly image: MimeGroup;
|
|
17
|
+
findExtension(type: string): MimeGroup;
|
|
18
|
+
findExtensions(type: string): MimeGroup;
|
|
19
|
+
findType(type: string): MimeGroup;
|
|
20
|
+
}
|
|
21
|
+
export declare const mimes: MimeFinder;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=mime-types.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class MimeType {
|
|
2
|
+
constructor(type, exts) {
|
|
3
|
+
this.type = type;
|
|
4
|
+
this.exts = exts;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class MimeGroup {
|
|
8
|
+
constructor(name, types) {
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.types = types;
|
|
11
|
+
}
|
|
12
|
+
findExtension(type) {
|
|
13
|
+
return this.types.find(e => e.type == type)?.exts?.find(e => e);
|
|
14
|
+
}
|
|
15
|
+
findExtensions(type) {
|
|
16
|
+
return this.types.find(e => e.type == type)?.exts;
|
|
17
|
+
}
|
|
18
|
+
findType(extension) {
|
|
19
|
+
return this.types.find(t => t.exts.some(e => e == extension))?.type;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const imageMimeTypes = [
|
|
23
|
+
new MimeType('image/gif', ['gif']),
|
|
24
|
+
new MimeType('image/jpeg', ['jpeg', 'jpg']),
|
|
25
|
+
new MimeType('image/png', ['png']),
|
|
26
|
+
new MimeType('image/apng', ['apng']),
|
|
27
|
+
new MimeType('image/tiff', ['tif', 'tiff']),
|
|
28
|
+
new MimeType('image/vnd.wap.wbmp', ['wbmp']),
|
|
29
|
+
new MimeType('image/x-icon', ['ico']),
|
|
30
|
+
new MimeType('image/x-jng', ['jng']),
|
|
31
|
+
new MimeType('image/x-ms-bmp', ['bmp']),
|
|
32
|
+
new MimeType('image/svg+xml', ['svg']),
|
|
33
|
+
new MimeType('image/webp', ['webp']),
|
|
34
|
+
new MimeType('image/avif', ['avif'])
|
|
35
|
+
];
|
|
36
|
+
class MimeFinder {
|
|
37
|
+
constructor() {
|
|
38
|
+
this.image = new MimeGroup('image', imageMimeTypes);
|
|
39
|
+
}
|
|
40
|
+
findExtension(type) {
|
|
41
|
+
return [this.image]
|
|
42
|
+
.find(x => x.findExtension(type));
|
|
43
|
+
}
|
|
44
|
+
findExtensions(type) {
|
|
45
|
+
return [this.image]
|
|
46
|
+
.find(x => x.findExtensions(type));
|
|
47
|
+
}
|
|
48
|
+
findType(type) {
|
|
49
|
+
return [this.image]
|
|
50
|
+
.find(x => x.findType(type));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export const mimes = new MimeFinder();
|
|
54
|
+
//# sourceMappingURL=mime-types.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function nameof(selector, deep = true) {
|
|
2
|
+
const s = '' + selector;
|
|
3
|
+
const m = s.match(/return\s+([A-Z0-9$_.]+)/i)
|
|
4
|
+
|| s.match(/.*?(?:=>|function.*?{(?!\s*return))\s*([A-Z0-9$_.]+)/i);
|
|
5
|
+
const name = m && m[1] || "";
|
|
6
|
+
const splitted = name.split('.');
|
|
7
|
+
splitted.shift();
|
|
8
|
+
return deep ? splitted.join('.') : splitted.pop() ?? '';
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=name-of.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function trimStrings(obj) {
|
|
2
|
+
Object.keys(obj).forEach(key => {
|
|
3
|
+
if (!obj[key]) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (typeof obj[key] === 'string') {
|
|
7
|
+
obj[key] = obj[key].trim();
|
|
8
|
+
}
|
|
9
|
+
else if (typeof obj[key] === 'object') {
|
|
10
|
+
trimStrings(obj[key]);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function slugify(string) {
|
|
2
|
+
const a = 'àáäâãåăæçèéëêǵḧìíïîḿńǹñòóöôœøṕŕßśșțùúüûǘẃẍÿź·/_,:;';
|
|
3
|
+
const b = 'aaaaaaaaceeeeghiiiimnnnooooooprssstuuuuuwxyz------';
|
|
4
|
+
const p = new RegExp(a.split('').join('|'), 'g');
|
|
5
|
+
return string.toString().toLowerCase()
|
|
6
|
+
.replace(/\s+/g, '-') // Replace spaces with -
|
|
7
|
+
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
|
|
8
|
+
.replace(/&/g, '-and-') // Replace & with 'and'
|
|
9
|
+
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
|
|
10
|
+
.replace(/\-\-+/g, '-') // Replace multiple - with single -
|
|
11
|
+
.replace(/^-+/, '') // Trim - from start of text
|
|
12
|
+
.replace(/-+$/, ''); // Trim - from end of text
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=slugify.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
|
|
2
|
+
export function trimWhiteSpace(s, allOccurences = true) {
|
|
3
|
+
return s.replace(new RegExp('\\s', allOccurences ? 'g' : undefined), "");
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=strings.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ev-core/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Core library for ev-core",
|
|
5
5
|
"types": "dist/esm/index.d.ts",
|
|
6
6
|
"module": "dist/esm/index.mjs",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"clean": "rimraf dist && mkdir dist",
|
|
23
23
|
"build": "pnpm run build:cjs && pnpm run build:esm",
|
|
24
24
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
25
|
-
"build:esm": "tsc -p tsconfig.esm.json && ts2mjs dist/esm
|
|
25
|
+
"build:esm": "tsc -p tsconfig.esm.json && ts2mjs dist/esm"
|
|
26
26
|
}
|
|
27
27
|
}
|