tiny-essentials 1.8.3 → 1.8.5
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/TinyBasicsEs.js +31 -0
- package/dist/TinyBasicsEs.min.js +1 -1
- package/dist/TinyEssentials.js +31 -0
- package/dist/TinyEssentials.min.js +1 -1
- package/dist/legacy/crypto/decrypt.cjs +1 -1
- package/dist/legacy/crypto/decrypt.mjs +3 -3
- package/dist/legacy/crypto/default.cjs +0 -2
- package/dist/legacy/crypto/default.mjs +0 -1
- package/dist/legacy/crypto/encrypt.cjs +1 -2
- package/dist/legacy/crypto/encrypt.mjs +3 -4
- package/dist/legacy/crypto/index.cjs +1 -1
- package/dist/legacy/crypto/index.mjs +0 -1
- package/dist/legacy/firebase/database/presence.cjs +4 -1
- package/dist/legacy/firebase/database/presence.d.mts +3 -0
- package/dist/legacy/firebase/database/presence.mjs +4 -1
- package/dist/legacy/firebase/databaseLogger.cjs +2 -2
- package/dist/legacy/firebase/discord/get/cookie-session.cjs +2 -2
- package/dist/legacy/firebase/discord/get/errorValidator.cjs +2 -2
- package/dist/legacy/firebase/discord/http/login.cjs +7 -7
- package/dist/legacy/firebase/discord/http/logout.cjs +4 -4
- package/dist/legacy/firebase/discord/http/redirect.cjs +7 -7
- package/dist/legacy/firebase/discord/http/refreshToken.cjs +5 -5
- package/dist/legacy/firebase/discord/template/cookie-session.cjs +8 -8
- package/dist/legacy/firebase/logger.cjs +7 -7
- package/dist/legacy/firebase/mySQL.cjs +1 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +2 -2
- package/dist/legacy/get/countObj.cjs +2 -22
- package/dist/legacy/get/countObj.d.mts +2 -11
- package/dist/legacy/get/countObj.mjs +2 -22
- package/dist/legacy/get/decimalColor.cjs +10 -11
- package/dist/legacy/get/decimalColor.mjs +10 -10
- package/dist/legacy/get/objType.cjs +2 -40
- package/dist/legacy/get/objType.d.mts +2 -19
- package/dist/legacy/get/objType.mjs +2 -41
- package/dist/legacy/get/pagination.cjs +30 -25
- package/dist/legacy/get/pagination.d.mts +29 -12
- package/dist/legacy/get/pagination.mjs +30 -23
- package/dist/legacy/get/queryUrlByName.cjs +0 -2
- package/dist/legacy/get/queryUrlByName.mjs +0 -1
- package/dist/legacy/get/queryUrlJSON.cjs +2 -2
- package/dist/legacy/get/queryUrlJSON.mjs +1 -1
- package/dist/legacy/get/super_string_filter.cjs +14 -6
- package/dist/legacy/get/super_string_filter.mjs +11 -1
- package/dist/legacy/get/versionCheck.cjs +18 -19
- package/dist/legacy/get/versionCheck.d.mts +15 -5
- package/dist/legacy/get/versionCheck.mjs +16 -16
- package/dist/legacy/http/HTTP-1.0.cjs +2 -4
- package/dist/legacy/http/HTTP-1.0.d.mts +1 -1
- package/dist/legacy/http/HTTP-1.0.mjs +2 -3
- package/dist/legacy/http/auth.cjs +2 -4
- package/dist/legacy/http/auth.d.mts +4 -4
- package/dist/legacy/http/auth.mjs +2 -3
- package/dist/legacy/http/check_domain.cjs +15 -9
- package/dist/legacy/http/check_domain.d.mts +5 -6
- package/dist/legacy/http/check_domain.mjs +12 -8
- package/dist/legacy/http/csrfTokenAnalyze.cjs +5 -4
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +3 -3
- package/dist/legacy/http/csrfTokenAnalyze.mjs +7 -4
- package/dist/legacy/http/domainValidator.cjs +13 -9
- package/dist/legacy/http/domainValidator.d.mts +15 -6
- package/dist/legacy/http/domainValidator.mjs +11 -6
- package/dist/legacy/http/errorsCallback.cjs +10 -4
- package/dist/legacy/http/errorsCallback.d.mts +13 -3
- package/dist/legacy/http/errorsCallback.mjs +12 -4
- package/dist/legacy/http/fetch/json.cjs +1 -3
- package/dist/legacy/http/fetch/json.mjs +1 -1
- package/dist/legacy/http/fetch/text.cjs +1 -3
- package/dist/legacy/http/fetch/text.mjs +1 -1
- package/dist/legacy/http/fileCache.cjs +2 -5
- package/dist/legacy/http/fileCache.d.mts +3 -3
- package/dist/legacy/http/fileCache.mjs +2 -3
- package/dist/legacy/http/getDomainURL.cjs +4 -7
- package/dist/legacy/http/getDomainURL.d.mts +2 -2
- package/dist/legacy/http/getDomainURL.mjs +4 -5
- package/dist/legacy/http/userIP.cjs +7 -5
- package/dist/legacy/http/userIP.d.mts +10 -4
- package/dist/legacy/http/userIP.mjs +7 -4
- package/dist/legacy/index.cjs +3 -4
- package/dist/legacy/index.d.mts +8 -9
- package/dist/legacy/libs/arraySortPositions.cjs +1 -3
- package/dist/legacy/libs/arraySortPositions.d.mts +2 -2
- package/dist/legacy/libs/arraySortPositions.mjs +1 -2
- package/dist/legacy/libs/capitalize.cjs +0 -2
- package/dist/legacy/libs/capitalize.mjs +0 -1
- package/dist/legacy/libs/convertBytes.cjs +1 -3
- package/dist/legacy/libs/convertBytes.mjs +1 -2
- package/dist/legacy/libs/custom_module_loader.cjs +13 -9
- package/dist/legacy/libs/custom_module_loader.d.mts +1 -1
- package/dist/legacy/libs/custom_module_loader.mjs +10 -5
- package/dist/legacy/libs/dice.cjs +0 -2
- package/dist/legacy/libs/dice.mjs +0 -1
- package/dist/legacy/libs/markdown.cjs +13 -4
- package/dist/legacy/libs/markdown.d.mts +7 -71
- package/dist/legacy/libs/markdown.mjs +13 -3
- package/dist/legacy/libs/percentage.cjs +0 -2
- package/dist/legacy/libs/percentage.mjs +0 -1
- package/dist/legacy/libs/regex/getLetter.cjs +0 -2
- package/dist/legacy/libs/regex/getLetter.mjs +0 -1
- package/dist/legacy/libs/rule3.cjs +0 -2
- package/dist/legacy/libs/rule3.mjs +0 -1
- package/dist/legacy/momentjs/getAge.cjs +0 -3
- package/dist/legacy/momentjs/getAge.d.mts +1 -0
- package/dist/legacy/momentjs/getAge.mjs +0 -1
- package/dist/legacy/momentjs/index.cjs +1 -1
- package/dist/legacy/momentjs/index.mjs +0 -1
- package/dist/legacy/momentjs/timeDuration.cjs +1 -3
- package/dist/legacy/momentjs/timeDuration.d.mts +1 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -1
- package/dist/legacy/socket.io/antiFlood/index.cjs +1 -1
- package/dist/legacy/socket.io/antiFlood/index.mjs +0 -1
- package/dist/legacy/socket.io/antiFlood/install.cjs +3 -5
- package/dist/legacy/socket.io/antiFlood/install.d.mts +5 -3
- package/dist/legacy/socket.io/antiFlood/install.mjs +3 -3
- package/dist/legacy/socket.io/antiFlood/verify.cjs +10 -6
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +8 -3
- package/dist/legacy/socket.io/antiFlood/verify.mjs +10 -6
- package/dist/legacy/socket.io/cookie-session.cjs +1 -2
- package/dist/legacy/socket.io/cookie-session.mjs +1 -1
- package/dist/legacy/socket.io/discord.cjs +0 -3
- package/dist/legacy/socket.io/discord.mjs +0 -1
- package/dist/legacy/socket.io/index.cjs +0 -3
- package/dist/legacy/socket.io/index.mjs +0 -1
- package/dist/v1/basics/index.cjs +3 -0
- package/dist/v1/basics/index.d.mts +3 -1
- package/dist/v1/basics/index.mjs +3 -2
- package/dist/v1/index.cjs +3 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -2
- package/docs/basics/array.md +61 -0
- package/package.json +8 -2
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var moment = require('moment');
|
|
4
4
|
|
|
5
|
-
// @ts-nocheck
|
|
6
|
-
|
|
7
|
-
|
|
8
5
|
/**
|
|
9
6
|
* Calculates the time duration between the current time and a given time offset.
|
|
10
7
|
*
|
|
@@ -19,6 +16,7 @@ function timeDuration(timeData = 0, durationType = 'asSeconds', now = null) {
|
|
|
19
16
|
if (!now) now = moment();
|
|
20
17
|
|
|
21
18
|
var duration = moment.duration(now.clone().add(timeData, 'milliseconds').diff(now.clone()));
|
|
19
|
+
// @ts-ignore
|
|
22
20
|
const result = duration[durationType]();
|
|
23
21
|
|
|
24
22
|
// Complete
|
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
* @returns {number|null} The calculated duration in the specified unit (default: seconds), or `null` if `timeData` is not provided.
|
|
8
8
|
*/
|
|
9
9
|
export default function timeDuration(timeData?: number, durationType?: string, now?: moment.Moment | null): number | null;
|
|
10
|
+
import moment from 'moment';
|
|
10
11
|
//# sourceMappingURL=timeDuration.d.mts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import moment from 'moment';
|
|
3
2
|
/**
|
|
4
3
|
* Calculates the time duration between the current time and a given time offset.
|
|
@@ -14,6 +13,7 @@ export default function timeDuration(timeData = 0, durationType = 'asSeconds', n
|
|
|
14
13
|
if (!now)
|
|
15
14
|
now = moment();
|
|
16
15
|
var duration = moment.duration(now.clone().add(timeData, 'milliseconds').diff(now.clone()));
|
|
16
|
+
// @ts-ignore
|
|
17
17
|
const result = duration[durationType]();
|
|
18
18
|
// Complete
|
|
19
19
|
return result;
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
var userIP = require('../../http/userIP.cjs');
|
|
4
4
|
|
|
5
|
-
// @ts-nocheck
|
|
6
|
-
|
|
7
|
-
|
|
8
5
|
/**
|
|
9
6
|
* Installs the authorization middleware for socket connections.
|
|
10
7
|
*
|
|
11
8
|
* This middleware checks the user's IP address and allows or denies the socket connection based on whether
|
|
12
9
|
* the IP is in the block list or not.
|
|
13
10
|
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
11
|
+
* @param {*} io - The Socket.IO server instance.
|
|
12
|
+
* @param {Object} ioCache - The cache object containing blocked IPs.
|
|
16
13
|
* @param {Array<*>} ioCache.blocklick - The list of blocked IP addresses.
|
|
17
14
|
* @returns {void} This function does not return a value, it just sets the authorization logic for socket connections.
|
|
18
15
|
*/
|
|
19
16
|
function install(io, ioCache) {
|
|
17
|
+
// @ts-ignore
|
|
20
18
|
io.set('authorization', function (socket, callback) {
|
|
21
19
|
// Get User IP
|
|
22
20
|
const ip = userIP(socket.handshake);
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* This middleware checks the user's IP address and allows or denies the socket connection based on whether
|
|
5
5
|
* the IP is in the block list or not.
|
|
6
6
|
*
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
7
|
+
* @param {*} io - The Socket.IO server instance.
|
|
8
|
+
* @param {Object} ioCache - The cache object containing blocked IPs.
|
|
9
9
|
* @param {Array<*>} ioCache.blocklick - The list of blocked IP addresses.
|
|
10
10
|
* @returns {void} This function does not return a value, it just sets the authorization logic for socket connections.
|
|
11
11
|
*/
|
|
12
|
-
export default function install(io:
|
|
12
|
+
export default function install(io: any, ioCache: {
|
|
13
|
+
blocklick: Array<any>;
|
|
14
|
+
}): void;
|
|
13
15
|
//# sourceMappingURL=install.d.mts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import userIp from '../../http/userIP.mjs';
|
|
3
2
|
/**
|
|
4
3
|
* Installs the authorization middleware for socket connections.
|
|
@@ -6,12 +5,13 @@ import userIp from '../../http/userIP.mjs';
|
|
|
6
5
|
* This middleware checks the user's IP address and allows or denies the socket connection based on whether
|
|
7
6
|
* the IP is in the block list or not.
|
|
8
7
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
8
|
+
* @param {*} io - The Socket.IO server instance.
|
|
9
|
+
* @param {Object} ioCache - The cache object containing blocked IPs.
|
|
11
10
|
* @param {Array<*>} ioCache.blocklick - The list of blocked IP addresses.
|
|
12
11
|
* @returns {void} This function does not return a value, it just sets the authorization logic for socket connections.
|
|
13
12
|
*/
|
|
14
13
|
export default function install(io, ioCache) {
|
|
14
|
+
// @ts-ignore
|
|
15
15
|
io.set('authorization', function (socket, callback) {
|
|
16
16
|
// Get User IP
|
|
17
17
|
const ip = userIp(socket.handshake);
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var userIP = require('../../http/userIP.cjs');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/** @typedef {Record<string, { timeout: number, tries: number }>} FloodTimeout */
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Panel
|
|
9
|
+
*
|
|
10
|
+
* @type {FloodTimeout}
|
|
11
|
+
*/
|
|
7
12
|
|
|
8
|
-
// Panel
|
|
9
13
|
const floodPanel = {};
|
|
10
14
|
|
|
11
15
|
/**
|
|
@@ -27,14 +31,14 @@ setInterval(function () {
|
|
|
27
31
|
* If the attempts exceed a threshold, the IP is temporarily banned and disconnected.
|
|
28
32
|
*
|
|
29
33
|
* @param {Record<string, any>} socket - The socket object representing the connection.
|
|
30
|
-
* @param {
|
|
34
|
+
* @param {Object} ioCache - The cache object that holds the blocklist and flood panel data.
|
|
31
35
|
* @param {Array<*>} ioCache.blocklick - The list of blocked IPs.
|
|
32
|
-
* @param {Record<string, any>} floodPanel - The object tracking flooding attempts and timeouts for each IP.
|
|
33
36
|
* @returns {void} This function does not return anything, it modifies the floodPanel and blocklist.
|
|
34
37
|
*/
|
|
35
38
|
function verify(socket, ioCache) {
|
|
36
39
|
// Get User IP
|
|
37
|
-
const
|
|
40
|
+
const ipData = userIP(socket.handshake);
|
|
41
|
+
const ip = ipData.value ? ipData.value[0] : '';
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Verifies the IP for flooding attempts and manages timeout and blocklist.
|
|
@@ -71,7 +75,7 @@ function verify(socket, ioCache) {
|
|
|
71
75
|
|
|
72
76
|
// Catch-all Event Listener
|
|
73
77
|
var onevent = socket.onevent;
|
|
74
|
-
socket.onevent = function (packet) {
|
|
78
|
+
socket.onevent = function (/** @type {{ data: string[]; }} */ packet) {
|
|
75
79
|
var args = packet.data || [];
|
|
76
80
|
onevent.call(this, packet); // original call
|
|
77
81
|
packet.data = ['*'].concat(args);
|
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
* If the attempts exceed a threshold, the IP is temporarily banned and disconnected.
|
|
6
6
|
*
|
|
7
7
|
* @param {Record<string, any>} socket - The socket object representing the connection.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {Object} ioCache - The cache object that holds the blocklist and flood panel data.
|
|
9
9
|
* @param {Array<*>} ioCache.blocklick - The list of blocked IPs.
|
|
10
|
-
* @param {Record<string, any>} floodPanel - The object tracking flooding attempts and timeouts for each IP.
|
|
11
10
|
* @returns {void} This function does not return anything, it modifies the floodPanel and blocklist.
|
|
12
11
|
*/
|
|
13
|
-
export default function verify(socket: Record<string, any>, ioCache:
|
|
12
|
+
export default function verify(socket: Record<string, any>, ioCache: {
|
|
13
|
+
blocklick: Array<any>;
|
|
14
|
+
}): void;
|
|
15
|
+
export type FloodTimeout = Record<string, {
|
|
16
|
+
timeout: number;
|
|
17
|
+
tries: number;
|
|
18
|
+
}>;
|
|
14
19
|
//# sourceMappingURL=verify.d.mts.map
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import userIp from '../../http/userIP.mjs';
|
|
3
|
-
|
|
2
|
+
/** @typedef {Record<string, { timeout: number, tries: number }>} FloodTimeout */
|
|
3
|
+
/**
|
|
4
|
+
* Panel
|
|
5
|
+
*
|
|
6
|
+
* @type {FloodTimeout}
|
|
7
|
+
*/
|
|
4
8
|
const floodPanel = {};
|
|
5
9
|
/**
|
|
6
10
|
* Periodically decrements the timeout for each IP in the flood panel and removes expired entries.
|
|
@@ -21,14 +25,14 @@ setInterval(function () {
|
|
|
21
25
|
* If the attempts exceed a threshold, the IP is temporarily banned and disconnected.
|
|
22
26
|
*
|
|
23
27
|
* @param {Record<string, any>} socket - The socket object representing the connection.
|
|
24
|
-
* @param {
|
|
28
|
+
* @param {Object} ioCache - The cache object that holds the blocklist and flood panel data.
|
|
25
29
|
* @param {Array<*>} ioCache.blocklick - The list of blocked IPs.
|
|
26
|
-
* @param {Record<string, any>} floodPanel - The object tracking flooding attempts and timeouts for each IP.
|
|
27
30
|
* @returns {void} This function does not return anything, it modifies the floodPanel and blocklist.
|
|
28
31
|
*/
|
|
29
32
|
export default function verify(socket, ioCache) {
|
|
30
33
|
// Get User IP
|
|
31
|
-
const
|
|
34
|
+
const ipData = userIp(socket.handshake);
|
|
35
|
+
const ip = ipData.value ? ipData.value[0] : '';
|
|
32
36
|
/**
|
|
33
37
|
* Verifies the IP for flooding attempts and manages timeout and blocklist.
|
|
34
38
|
*/
|
|
@@ -59,7 +63,7 @@ export default function verify(socket, ioCache) {
|
|
|
59
63
|
}
|
|
60
64
|
// Catch-all Event Listener
|
|
61
65
|
var onevent = socket.onevent;
|
|
62
|
-
socket.onevent = function (packet) {
|
|
66
|
+
socket.onevent = function (/** @type {{ data: string[]; }} */ packet) {
|
|
63
67
|
var args = packet.data || [];
|
|
64
68
|
onevent.call(this, packet); // original call
|
|
65
69
|
packet.data = ['*'].concat(args);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// @ts-nocheck
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Handles the cookie session for a socket connection by simulating an Express request and response.
|
|
7
5
|
* This function uses the provided session module to manage session data for the socket connection.
|
|
@@ -13,6 +11,7 @@
|
|
|
13
11
|
function cookieSession(socket, sessionModule) {
|
|
14
12
|
return new Promise((resolve) => {
|
|
15
13
|
// Express Simulator
|
|
14
|
+
/** @type {Record<*,*>} */
|
|
16
15
|
let req = {
|
|
17
16
|
connection: { encrypted: false },
|
|
18
17
|
headers: { cookie: socket.request.headers.cookie },
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
/**
|
|
3
2
|
* Handles the cookie session for a socket connection by simulating an Express request and response.
|
|
4
3
|
* This function uses the provided session module to manage session data for the socket connection.
|
|
@@ -10,6 +9,7 @@
|
|
|
10
9
|
export default function cookieSession(socket, sessionModule) {
|
|
11
10
|
return new Promise((resolve) => {
|
|
12
11
|
// Express Simulator
|
|
12
|
+
/** @type {Record<*,*>} */
|
|
13
13
|
let req = {
|
|
14
14
|
connection: { encrypted: false },
|
|
15
15
|
headers: { cookie: socket.request.headers.cookie },
|
package/dist/v1/basics/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var arraySortPositions = require('../../legacy/libs/arraySortPositions.cjs');
|
|
3
4
|
var replaceAsync = require('../../legacy/libs/replaceAsync.cjs');
|
|
4
5
|
var array = require('./array.cjs');
|
|
5
6
|
var clock = require('./clock.cjs');
|
|
@@ -9,6 +10,7 @@ var text = require('./text.cjs');
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
exports.arraySortPositions = arraySortPositions;
|
|
12
14
|
exports.asyncReplace = replaceAsync;
|
|
13
15
|
exports.shuffleArray = array.shuffleArray;
|
|
14
16
|
exports.formatCustomTimer = clock.formatCustomTimer;
|
|
@@ -20,6 +22,7 @@ exports.countObj = objFilter.countObj;
|
|
|
20
22
|
exports.extendObjType = objFilter.extendObjType;
|
|
21
23
|
exports.objType = objFilter.objType;
|
|
22
24
|
exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
|
|
25
|
+
exports.formatBytes = simpleMath.formatBytes;
|
|
23
26
|
exports.getAge = simpleMath.getAge;
|
|
24
27
|
exports.getSimplePerc = simpleMath.getSimplePerc;
|
|
25
28
|
exports.ruleOfThree = simpleMath.ruleOfThree;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import arraySortPositions from '../../legacy/libs/arraySortPositions.mjs';
|
|
2
|
+
import { formatBytes } from './simpleMath.mjs';
|
|
1
3
|
import { addAiMarkerShortcut } from './text.mjs';
|
|
2
4
|
import { extendObjType } from './objFilter.mjs';
|
|
3
5
|
import { reorderObjTypeOrder } from './objFilter.mjs';
|
|
@@ -15,5 +17,5 @@ import { getTimeDuration } from './clock.mjs';
|
|
|
15
17
|
import { shuffleArray } from './array.mjs';
|
|
16
18
|
import { toTitleCase } from './text.mjs';
|
|
17
19
|
import { toTitleCaseLowerFirst } from './text.mjs';
|
|
18
|
-
export { addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
|
|
20
|
+
export { arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
|
|
19
21
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/v1/basics/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import arraySortPositions from '../../legacy/libs/arraySortPositions.mjs';
|
|
1
2
|
import asyncReplace from '../../legacy/libs/replaceAsync.mjs';
|
|
2
3
|
import { shuffleArray } from './array.mjs';
|
|
3
4
|
import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration } from './clock.mjs';
|
|
4
5
|
import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, } from './objFilter.mjs';
|
|
5
|
-
import { getAge, getSimplePerc, ruleOfThree } from './simpleMath.mjs';
|
|
6
|
+
import { formatBytes, getAge, getSimplePerc, ruleOfThree } from './simpleMath.mjs';
|
|
6
7
|
import { addAiMarkerShortcut, toTitleCase, toTitleCaseLowerFirst } from './text.mjs';
|
|
7
|
-
export { addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
8
|
+
export { arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
package/dist/v1/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var replaceAsync = require('../legacy/libs/replaceAsync.cjs');
|
|
4
4
|
var userLevel = require('../legacy/libs/userLevel.cjs');
|
|
5
|
+
var arraySortPositions = require('../legacy/libs/arraySortPositions.cjs');
|
|
5
6
|
var array = require('./basics/array.cjs');
|
|
6
7
|
var clock = require('./basics/clock.cjs');
|
|
7
8
|
var objFilter = require('./basics/objFilter.cjs');
|
|
@@ -14,6 +15,7 @@ var TinyPromiseQueue = require('./libs/TinyPromiseQueue.cjs');
|
|
|
14
15
|
|
|
15
16
|
exports.asyncReplace = replaceAsync;
|
|
16
17
|
exports.TinyLevelUp = userLevel;
|
|
18
|
+
exports.arraySortPositions = arraySortPositions;
|
|
17
19
|
exports.shuffleArray = array.shuffleArray;
|
|
18
20
|
exports.formatCustomTimer = clock.formatCustomTimer;
|
|
19
21
|
exports.formatDayTimer = clock.formatDayTimer;
|
|
@@ -25,6 +27,7 @@ exports.countObj = objFilter.countObj;
|
|
|
25
27
|
exports.extendObjType = objFilter.extendObjType;
|
|
26
28
|
exports.objType = objFilter.objType;
|
|
27
29
|
exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
|
|
30
|
+
exports.formatBytes = simpleMath.formatBytes;
|
|
28
31
|
exports.getAge = simpleMath.getAge;
|
|
29
32
|
exports.getSimplePerc = simpleMath.getSimplePerc;
|
|
30
33
|
exports.ruleOfThree = simpleMath.ruleOfThree;
|
package/dist/v1/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import ColorSafeStringify from './libs/ColorSafeStringify.mjs';
|
|
2
2
|
import TinyPromiseQueue from './libs/TinyPromiseQueue.mjs';
|
|
3
3
|
import TinyLevelUp from '../legacy/libs/userLevel.mjs';
|
|
4
|
+
import arraySortPositions from '../legacy/libs/arraySortPositions.mjs';
|
|
5
|
+
import { formatBytes } from './basics/simpleMath.mjs';
|
|
4
6
|
import { addAiMarkerShortcut } from './basics/text.mjs';
|
|
5
7
|
import { extendObjType } from './basics/objFilter.mjs';
|
|
6
8
|
import { reorderObjTypeOrder } from './basics/objFilter.mjs';
|
|
@@ -19,5 +21,5 @@ import { getTimeDuration } from './basics/clock.mjs';
|
|
|
19
21
|
import { shuffleArray } from './basics/array.mjs';
|
|
20
22
|
import { toTitleCase } from './basics/text.mjs';
|
|
21
23
|
import { toTitleCaseLowerFirst } from './basics/text.mjs';
|
|
22
|
-
export { ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
|
|
24
|
+
export { ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
|
|
23
25
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/v1/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import asyncReplace from '../legacy/libs/replaceAsync.mjs';
|
|
2
2
|
import TinyLevelUp from '../legacy/libs/userLevel.mjs';
|
|
3
|
+
import arraySortPositions from '../legacy/libs/arraySortPositions.mjs';
|
|
3
4
|
import { shuffleArray } from './basics/array.mjs';
|
|
4
5
|
import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './basics/clock.mjs';
|
|
5
6
|
import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, } from './basics/objFilter.mjs';
|
|
6
|
-
import { getAge, getSimplePerc, ruleOfThree } from './basics/simpleMath.mjs';
|
|
7
|
+
import { formatBytes, getAge, getSimplePerc, ruleOfThree } from './basics/simpleMath.mjs';
|
|
7
8
|
import { addAiMarkerShortcut, toTitleCase, toTitleCaseLowerFirst } from './basics/text.mjs';
|
|
8
9
|
import ColorSafeStringify from './libs/ColorSafeStringify.mjs';
|
|
9
10
|
import TinyPromiseQueue from './libs/TinyPromiseQueue.mjs';
|
|
10
|
-
export { ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
11
|
+
export { ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
package/docs/basics/array.md
CHANGED
|
@@ -44,3 +44,64 @@ You can find the original discussion here:
|
|
|
44
44
|
|
|
45
45
|
- **items** — An array of strings to shuffle.
|
|
46
46
|
- **Returns** — The same array instance, but now shuffled.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
# 📦 `arraySortPositions`
|
|
51
|
+
|
|
52
|
+
🔧 **Generates a comparator function** to sort an array of objects by a specified key, with optional reverse order.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 📌 Function Signature
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
arraySortPositions(item: string, isReverse?: boolean): (a: Object<string|number, *>, b: Object<string|number, *>) => number
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🧠 Parameters
|
|
65
|
+
|
|
66
|
+
| Name | Type | Default | Description |
|
|
67
|
+
| ----------- | --------- | ------- | ---------------------------------------------------------- |
|
|
68
|
+
| `item` | `string` | — | 🔑 The key to sort the objects by. |
|
|
69
|
+
| `isReverse` | `boolean` | `false` | 🔄 If `true`, the sorting will be in **descending** order. |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 🎯 Returns
|
|
74
|
+
|
|
75
|
+
🧩 A **comparator function** compatible with `Array.prototype.sort()`:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
(a, b) => number
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
It compares two objects based on the specified `item` key.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 💡 Examples
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const arr = [{ pos: 2 }, { pos: 1 }, { pos: 3 }];
|
|
89
|
+
arr.sort(arraySortPositions('pos'));
|
|
90
|
+
// 🔼 Ascending: [{ pos: 1 }, { pos: 2 }, { pos: 3 }]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
const arr = [{ pos: 2 }, { pos: 1 }, { pos: 3 }];
|
|
95
|
+
arr.sort(arraySortPositions('pos', true));
|
|
96
|
+
// 🔽 Descending: [{ pos: 3 }, { pos: 2 }, { pos: 1 }]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 🛠️ Use Case
|
|
102
|
+
|
|
103
|
+
Great for situations where you need to **dynamically sort objects** by one of their keys, such as:
|
|
104
|
+
|
|
105
|
+
* Sorting users by age
|
|
106
|
+
* Ordering tasks by priority
|
|
107
|
+
* Displaying leaderboard scores
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|
|
@@ -71,10 +71,16 @@
|
|
|
71
71
|
"@rollup/plugin-json": "^6.1.0",
|
|
72
72
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
73
73
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
74
|
+
"@types/lodash": "^4.17.16",
|
|
75
|
+
"@types/md5": "^2.3.5",
|
|
76
|
+
"@types/node-fetch": "^2.6.12",
|
|
77
|
+
"@types/tinycolor2": "^1.4.6",
|
|
74
78
|
"babel-preset-es2015": "^6.24.1",
|
|
75
79
|
"byte-length": "^1.0.2",
|
|
76
80
|
"clone": "^2.1.2",
|
|
77
81
|
"compare-versions": "^6.1.1",
|
|
82
|
+
"express": "^5.1.0",
|
|
83
|
+
"firebase": "^11.7.1",
|
|
78
84
|
"firebase-functions": "^6.3.2",
|
|
79
85
|
"latest-version": "^9.0.0",
|
|
80
86
|
"lodash": "^4.17.21",
|
|
@@ -82,7 +88,7 @@
|
|
|
82
88
|
"moment": "^2.30.1",
|
|
83
89
|
"moment-timezone": "^0.5.48",
|
|
84
90
|
"mysql": "^2.18.1",
|
|
85
|
-
"node-fetch": "2.7.0",
|
|
91
|
+
"node-fetch": "^2.7.0",
|
|
86
92
|
"node-polyfill-webpack-plugin": "^4.1.0",
|
|
87
93
|
"object-hash": "^3.0.0",
|
|
88
94
|
"prettier": "3.5.3",
|