Skip to content

Commit 6227163

Browse files
author
Abstractn
committed
Ported module content and generated build files
1 parent 388d7f0 commit 6227163

7 files changed

Lines changed: 355 additions & 0 deletions

File tree

dist/abs-utils.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export declare function proportionalRange(oldMin: number, oldMax: number, newMin: number, newMax: number, value: number): number;
2+
export declare function rgbToHex(r: number, g: number, b: number): string | null;
3+
export declare function randomInt(min?: number, max?: number): number;
4+
export declare function getNode(query: string, context?: HTMLElement): HTMLElement | null;
5+
export declare function getNodes(query: string, context?: HTMLElement): Array<HTMLElement> | null;
6+
declare global {
7+
interface Document {
8+
getNode(query: string): HTMLElement | null;
9+
getNodes(query: string): HTMLElement[] | null;
10+
setStyle(property: string, value: string): void;
11+
setStyles(propertyObject: Record<string, string>): void;
12+
}
13+
interface Element {
14+
getNode(query: string): HTMLElement | null;
15+
getNodes(query: string): HTMLElement[] | null;
16+
setStyle(property: string, value: string): void;
17+
setStyles(propertyObject: Record<string, string>): void;
18+
}
19+
interface HTMLElement {
20+
getNode(query: string): HTMLElement | null;
21+
getNodes(query: string): HTMLElement[] | null;
22+
setStyle(property: string, value: string): void;
23+
setStyles(propertyObject: Record<string, string>): void;
24+
}
25+
interface Node {
26+
getNode(query: string): HTMLElement | null;
27+
getNodes(query: string): HTMLElement[] | null;
28+
setStyle(property: string, value: string): void;
29+
setStyles(propertyObject: Record<string, string>): void;
30+
}
31+
}
32+
export declare function absPolyfill(): void;

dist/abs-utils.js

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/abs-utils.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/abs-utils.nx.js

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/abs-utils.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
export function proportionalRange(
2+
oldMin: number, oldMax: number,
3+
newMin: number, newMax: number,
4+
value: number
5+
): number {
6+
return ((newMax - newMin) / (oldMax - oldMin)) * (value - oldMin) + newMin;
7+
}
8+
9+
export function rgbToHex(
10+
r: number,
11+
g: number,
12+
b: number
13+
): string | null {
14+
const isRedWithinRange = r > -1 && r < 256;
15+
const isGreenWithinRange = g > -1 && g < 256;
16+
const isBlueWithinRange = b > -1 && b < 256;
17+
if(isRedWithinRange && isGreenWithinRange && isBlueWithinRange) {
18+
return ((r << 16) | (g << 8) | b).toString(16).toUpperCase();
19+
} else {
20+
return null;
21+
}
22+
}
23+
24+
export function randomInt(
25+
min: number = 0,
26+
max: number = 1
27+
): number {
28+
min = Math.ceil(min);
29+
max = Math.floor(max);
30+
return Math.floor(Math.random() * (max - min + 1)) + min;
31+
}
32+
33+
export function getNode(
34+
query: string,
35+
context?: HTMLElement
36+
): HTMLElement | null {
37+
if(context) {
38+
return context.querySelector(query);
39+
} else {
40+
return document.querySelector(query);
41+
}
42+
}
43+
44+
export function getNodes(
45+
query: string,
46+
context?: HTMLElement
47+
): Array<HTMLElement> | null {
48+
if(context) {
49+
const res: Array<HTMLElement> = Array.from(context.querySelectorAll(query));
50+
return res.length ? res : null;
51+
} else {
52+
const res: Array<HTMLElement> = Array.from(document.querySelectorAll(query));
53+
return res.length ? res : null;
54+
}
55+
}
56+
57+
declare global {
58+
interface Document {
59+
getNode(query: string): HTMLElement | null;
60+
getNodes(query: string): HTMLElement[] | null;
61+
setStyle(property: string, value: string): void;
62+
setStyles(propertyObject: Record<string, string>): void;
63+
}
64+
interface Element {
65+
getNode(query: string): HTMLElement | null;
66+
getNodes(query: string): HTMLElement[] | null;
67+
setStyle(property: string, value: string): void;
68+
setStyles(propertyObject: Record<string, string>): void;
69+
}
70+
interface HTMLElement {
71+
getNode(query: string): HTMLElement | null;
72+
getNodes(query: string): HTMLElement[] | null;
73+
setStyle(property: string, value: string): void;
74+
setStyles(propertyObject: Record<string, string>): void;
75+
}
76+
interface Node {
77+
getNode(query: string): HTMLElement | null;
78+
getNodes(query: string): HTMLElement[] | null;
79+
setStyle(property: string, value: string): void;
80+
setStyles(propertyObject: Record<string, string>): void;
81+
}
82+
}
83+
84+
export function absPolyfill(): void {
85+
[Document, Element, HTMLElement, Node].forEach(NativeClass => {
86+
NativeClass.prototype.getNode = function (query: string) { return getNode(query, this); }
87+
NativeClass.prototype.getNodes = function (query: string) { return getNodes(query, this); };
88+
NativeClass.prototype.setStyle = function (property: string, value: string) { this.style[property] = value; };
89+
NativeClass.prototype.setStyles = function (propertyObject: Record<string, string>) {
90+
Object.keys(propertyObject).forEach(property => {
91+
this.style[property] = propertyObject[property];
92+
});
93+
};
94+
});
95+
}

src/abs-utils.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export declare function proportionalRange(oldMin: number, oldMax: number, newMin: number, newMax: number, value: number): number;
2+
export declare function rgbToHex(r: number, g: number, b: number): string | null;
3+
export declare function randomInt(min?: number, max?: number): number;
4+
export declare function getNode(query: string, context?: HTMLElement): HTMLElement | null;
5+
export declare function getNodes(query: string, context?: HTMLElement): Array<HTMLElement> | null;
6+
declare global {
7+
interface Document {
8+
getNode(query: string): HTMLElement | null;
9+
getNodes(query: string): HTMLElement[] | null;
10+
setStyle(property: string, value: string): void;
11+
setStyles(propertyObject: Record<string, string>): void;
12+
}
13+
interface Element {
14+
getNode(query: string): HTMLElement | null;
15+
getNodes(query: string): HTMLElement[] | null;
16+
setStyle(property: string, value: string): void;
17+
setStyles(propertyObject: Record<string, string>): void;
18+
}
19+
interface HTMLElement {
20+
getNode(query: string): HTMLElement | null;
21+
getNodes(query: string): HTMLElement[] | null;
22+
setStyle(property: string, value: string): void;
23+
setStyles(propertyObject: Record<string, string>): void;
24+
}
25+
interface Node {
26+
getNode(query: string): HTMLElement | null;
27+
getNodes(query: string): HTMLElement[] | null;
28+
setStyle(property: string, value: string): void;
29+
setStyles(propertyObject: Record<string, string>): void;
30+
}
31+
}
32+
export declare function absPolyfill(): void;

src/abs-utils.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
export function proportionalRange(
2+
oldMin: number, oldMax: number,
3+
newMin: number, newMax: number,
4+
value: number
5+
): number {
6+
return ((newMax - newMin) / (oldMax - oldMin)) * (value - oldMin) + newMin;
7+
}
8+
9+
export function rgbToHex(
10+
r: number,
11+
g: number,
12+
b: number
13+
): string | null {
14+
const isRedWithinRange = r > -1 && r < 256;
15+
const isGreenWithinRange = g > -1 && g < 256;
16+
const isBlueWithinRange = b > -1 && b < 256;
17+
if(isRedWithinRange && isGreenWithinRange && isBlueWithinRange) {
18+
return ((r << 16) | (g << 8) | b).toString(16).toUpperCase();
19+
} else {
20+
return null;
21+
}
22+
}
23+
24+
export function randomInt(
25+
min: number = 0,
26+
max: number = 1
27+
): number {
28+
min = Math.ceil(min);
29+
max = Math.floor(max);
30+
return Math.floor(Math.random() * (max - min + 1)) + min;
31+
}
32+
33+
export function getNode(
34+
query: string,
35+
context?: HTMLElement
36+
): HTMLElement | null {
37+
if(context) {
38+
return context.querySelector(query);
39+
} else {
40+
return document.querySelector(query);
41+
}
42+
}
43+
44+
export function getNodes(
45+
query: string,
46+
context?: HTMLElement
47+
): Array<HTMLElement> | null {
48+
if(context) {
49+
const res: Array<HTMLElement> = Array.from(context.querySelectorAll(query));
50+
return res.length ? res : null;
51+
} else {
52+
const res: Array<HTMLElement> = Array.from(document.querySelectorAll(query));
53+
return res.length ? res : null;
54+
}
55+
}
56+
57+
declare global {
58+
interface Document {
59+
getNode(query: string): HTMLElement | null;
60+
getNodes(query: string): HTMLElement[] | null;
61+
setStyle(property: string, value: string): void;
62+
setStyles(propertyObject: Record<string, string>): void;
63+
}
64+
interface Element {
65+
getNode(query: string): HTMLElement | null;
66+
getNodes(query: string): HTMLElement[] | null;
67+
setStyle(property: string, value: string): void;
68+
setStyles(propertyObject: Record<string, string>): void;
69+
}
70+
interface HTMLElement {
71+
getNode(query: string): HTMLElement | null;
72+
getNodes(query: string): HTMLElement[] | null;
73+
setStyle(property: string, value: string): void;
74+
setStyles(propertyObject: Record<string, string>): void;
75+
}
76+
interface Node {
77+
getNode(query: string): HTMLElement | null;
78+
getNodes(query: string): HTMLElement[] | null;
79+
setStyle(property: string, value: string): void;
80+
setStyles(propertyObject: Record<string, string>): void;
81+
}
82+
}
83+
84+
export function absPolyfill(): void {
85+
[Document, Element, HTMLElement, Node].forEach(NativeClass => {
86+
NativeClass.prototype.getNode = function (query: string) { return getNode(query, this); }
87+
NativeClass.prototype.getNodes = function (query: string) { return getNodes(query, this); };
88+
NativeClass.prototype.setStyle = function (property: string, value: string) { this.style[property] = value; };
89+
NativeClass.prototype.setStyles = function (propertyObject: Record<string, string>) {
90+
Object.keys(propertyObject).forEach(property => {
91+
this.style[property] = propertyObject[property];
92+
});
93+
};
94+
});
95+
}

0 commit comments

Comments
 (0)