@tmlmobilidade/utils 20251031.1051.3 → 20251202.1817.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/README.md +239 -9
- package/dist/{src/http.js → http.js} +1 -1
- package/dist/index.d.ts +8 -17
- package/dist/index.js +8 -17
- package/dist/objects/fill-template.d.ts +7 -0
- package/dist/objects/fill-template.js +52 -0
- package/dist/{src/objects → objects}/index.d.ts +1 -0
- package/dist/{src/objects → objects}/index.js +1 -0
- package/dist/permissions.d.ts +46 -0
- package/dist/permissions.js +86 -0
- package/dist/{src/validate-query-params.js → validate-query-params.js} +1 -1
- package/package.json +21 -35
- package/dist/src/css/get-variable-value.d.ts +0 -1
- package/dist/src/css/get-variable-value.js +0 -8
- package/dist/src/css/index.d.ts +0 -1
- package/dist/src/css/index.js +0 -1
- package/dist/src/dates/dates.d.ts +0 -175
- package/dist/src/dates/dates.js +0 -385
- package/dist/src/dates/format.d.ts +0 -27
- package/dist/src/dates/format.js +0 -99
- package/dist/src/dates/index.d.ts +0 -4
- package/dist/src/dates/index.js +0 -4
- package/dist/src/dates/types.d.ts +0 -4
- package/dist/src/dates/types.js +0 -338
- package/dist/src/dates/utils.d.ts +0 -17
- package/dist/src/dates/utils.js +0 -53
- package/dist/src/files/files.d.ts +0 -64
- package/dist/src/files/files.js +0 -152
- package/dist/src/files/utils.d.ts +0 -20
- package/dist/src/files/utils.js +0 -47
- package/dist/src/geo/chunk-line.d.ts +0 -10
- package/dist/src/geo/chunk-line.js +0 -75
- package/dist/src/geo/constants.d.ts +0 -8
- package/dist/src/geo/constants.js +0 -8
- package/dist/src/geo/conversions.d.ts +0 -36
- package/dist/src/geo/conversions.js +0 -79
- package/dist/src/geo/coordinates.d.ts +0 -37
- package/dist/src/geo/coordinates.js +0 -64
- package/dist/src/geo/cut-line-at-length.d.ts +0 -10
- package/dist/src/geo/cut-line-at-length.js +0 -68
- package/dist/src/geo/geojson-collections.d.ts +0 -11
- package/dist/src/geo/geojson-collections.js +0 -29
- package/dist/src/geo/get-geofence-on-point.d.ts +0 -17
- package/dist/src/geo/get-geofence-on-point.js +0 -46
- package/dist/src/geo/index.d.ts +0 -9
- package/dist/src/geo/index.js +0 -9
- package/dist/src/geo/is-point-in-polygon.d.ts +0 -9
- package/dist/src/geo/is-point-in-polygon.js +0 -37
- package/dist/src/geo/measurements.d.ts +0 -42
- package/dist/src/geo/measurements.js +0 -71
- package/dist/src/logs/index.d.ts +0 -1
- package/dist/src/logs/index.js +0 -1
- package/dist/src/logs/logs.d.ts +0 -82
- package/dist/src/logs/logs.js +0 -145
- package/dist/src/math/coefficient-of-variation.d.ts +0 -6
- package/dist/src/math/coefficient-of-variation.js +0 -14
- package/dist/src/math/entropy.d.ts +0 -6
- package/dist/src/math/entropy.js +0 -20
- package/dist/src/math/index.d.ts +0 -3
- package/dist/src/math/index.js +0 -3
- package/dist/src/math/round-number-bias.d.ts +0 -6
- package/dist/src/math/round-number-bias.js +0 -11
- package/dist/src/navigation/index.d.ts +0 -1
- package/dist/src/navigation/index.js +0 -1
- package/dist/src/navigation/keep-url-params.d.ts +0 -8
- package/dist/src/navigation/keep-url-params.js +0 -13
- package/dist/src/nuqs/index.d.ts +0 -1
- package/dist/src/nuqs/index.js +0 -2
- package/dist/src/nuqs/parse-as-array-of-strings.d.ts +0 -1
- package/dist/src/nuqs/parse-as-array-of-strings.js +0 -43
- package/dist/src/permissions.d.ts +0 -46
- package/dist/src/permissions.js +0 -77
- package/dist/src/random/generate-random-number.d.ts +0 -8
- package/dist/src/random/generate-random-number.js +0 -14
- package/dist/src/random/generate-random-string.d.ts +0 -12
- package/dist/src/random/generate-random-string.js +0 -32
- package/dist/src/random/generate-random-token.d.ts +0 -8
- package/dist/src/random/generate-random-token.js +0 -12
- package/dist/src/random/index.d.ts +0 -3
- package/dist/src/random/index.js +0 -3
- package/dist/src/strings/index.d.ts +0 -2
- package/dist/src/strings/index.js +0 -2
- package/dist/src/strings/normalize-string.d.ts +0 -8
- package/dist/src/strings/normalize-string.js +0 -18
- package/dist/src/strings/validation.d.ts +0 -2
- package/dist/src/strings/validation.js +0 -7
- /package/dist/{src/batching → batching}/index.d.ts +0 -0
- /package/dist/{src/batching → batching}/index.js +0 -0
- /package/dist/{src/batching → batching}/perform-in-chunks.d.ts +0 -0
- /package/dist/{src/batching → batching}/perform-in-chunks.js +0 -0
- /package/dist/{src/caching → caching}/cache.d.ts +0 -0
- /package/dist/{src/caching → caching}/cache.js +0 -0
- /package/dist/{src/caching → caching}/index.d.ts +0 -0
- /package/dist/{src/caching → caching}/index.js +0 -0
- /package/dist/{src/generic → generic}/get-value-at-path.d.ts +0 -0
- /package/dist/{src/generic → generic}/get-value-at-path.js +0 -0
- /package/dist/{src/generic → generic}/index.d.ts +0 -0
- /package/dist/{src/generic → generic}/index.js +0 -0
- /package/dist/{src/generic → generic}/set-value-at-path.d.ts +0 -0
- /package/dist/{src/generic → generic}/set-value-at-path.js +0 -0
- /package/dist/{src/http.d.ts → http.d.ts} +0 -0
- /package/dist/{src/objects → objects}/compare-objects.d.ts +0 -0
- /package/dist/{src/objects → objects}/compare-objects.js +0 -0
- /package/dist/{src/objects → objects}/convert-object.d.ts +0 -0
- /package/dist/{src/objects → objects}/convert-object.js +0 -0
- /package/dist/{src/objects → objects}/flatten-object.d.ts +0 -0
- /package/dist/{src/objects → objects}/flatten-object.js +0 -0
- /package/dist/{src/objects → objects}/merge-objects.d.ts +0 -0
- /package/dist/{src/objects → objects}/merge-objects.js +0 -0
- /package/dist/{src/singleton-proxy.d.ts → singleton-proxy.d.ts} +0 -0
- /package/dist/{src/singleton-proxy.js → singleton-proxy.js} +0 -0
- /package/dist/{src/validate-query-params.d.ts → validate-query-params.d.ts} +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type Feature, type Point, type Polygon } from 'geojson';
|
|
2
|
-
/**
|
|
3
|
-
* Create a geofence around a given point with a given radius in meters (default is 50 meters).
|
|
4
|
-
* @param point A GeoJSON Point representation of the point to create the geofence around.
|
|
5
|
-
* @param radius The distance in meters to calculate the geofence radius. Default is 50 meters.
|
|
6
|
-
* @param steps The number of steps to use for the buffer. Default is 16.
|
|
7
|
-
* @returns The GeoJSON Feature of a Polygon.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getGeofenceOnPoint(point: Feature<Point>, radius?: number, steps?: number): Feature<Polygon>;
|
|
10
|
-
/**
|
|
11
|
-
* Create a geofence around a given position with a given radius in meters (default is 50 meters).
|
|
12
|
-
* @param position A tuple representing the coordinates of the point to create the geofence around.
|
|
13
|
-
* @param radius The distance in meters to calculate the geofence radius. Default is 50 meters.
|
|
14
|
-
* @param steps The number of steps to use for the buffer. Default is 16.
|
|
15
|
-
* @returns The GeoJSON Feature of a Polygon.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getGeofenceOnPosition(position: [number, number], radius?: number, steps?: number): Feature<Polygon>;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
import { EARTH_RADIUS } from './constants.js';
|
|
3
|
-
import { toFeatureFromObject, toPointFromPositions } from './conversions.js';
|
|
4
|
-
import { polygon } from '@turf/turf';
|
|
5
|
-
/**
|
|
6
|
-
* Create a geofence around a given point with a given radius in meters (default is 50 meters).
|
|
7
|
-
* @param point A GeoJSON Point representation of the point to create the geofence around.
|
|
8
|
-
* @param radius The distance in meters to calculate the geofence radius. Default is 50 meters.
|
|
9
|
-
* @param steps The number of steps to use for the buffer. Default is 16.
|
|
10
|
-
* @returns The GeoJSON Feature of a Polygon.
|
|
11
|
-
*/
|
|
12
|
-
export function getGeofenceOnPoint(point, radius = 50, steps = 16) {
|
|
13
|
-
// Extract the center coordinates from the point
|
|
14
|
-
const [centerLon, centerLat] = point.geometry.coordinates;
|
|
15
|
-
// Set the angle size based on the number of steps
|
|
16
|
-
const angleStep = (2 * Math.PI) / steps;
|
|
17
|
-
// Set an empty array to hold the coordinates of the polygon vertices
|
|
18
|
-
const coords = [];
|
|
19
|
-
// Calculate the coordinates of the polygon vertices
|
|
20
|
-
for (let i = 0; i < steps; i++) {
|
|
21
|
-
const angle = i * angleStep;
|
|
22
|
-
const dx = radius * Math.cos(angle);
|
|
23
|
-
const dy = radius * Math.sin(angle);
|
|
24
|
-
const newLat = centerLat + (dy / EARTH_RADIUS) * (180 / Math.PI);
|
|
25
|
-
const newLng = centerLon + (dx / (EARTH_RADIUS * Math.cos((centerLat * Math.PI) / 180))) * (180 / Math.PI);
|
|
26
|
-
coords.push([newLng, newLat]);
|
|
27
|
-
}
|
|
28
|
-
// Close the polygon by adding the first coordinate to the end
|
|
29
|
-
coords.push(coords[0]);
|
|
30
|
-
// Return the polygon feature
|
|
31
|
-
return polygon([coords]);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create a geofence around a given position with a given radius in meters (default is 50 meters).
|
|
35
|
-
* @param position A tuple representing the coordinates of the point to create the geofence around.
|
|
36
|
-
* @param radius The distance in meters to calculate the geofence radius. Default is 50 meters.
|
|
37
|
-
* @param steps The number of steps to use for the buffer. Default is 16.
|
|
38
|
-
* @returns The GeoJSON Feature of a Polygon.
|
|
39
|
-
*/
|
|
40
|
-
export function getGeofenceOnPosition(position, radius = 50, steps = 16) {
|
|
41
|
-
// Create a point feature from the coordinates
|
|
42
|
-
const newPoint = toPointFromPositions(position);
|
|
43
|
-
const newFeature = toFeatureFromObject(newPoint);
|
|
44
|
-
// Call the getGeofenceOnPoint function to create the geofence
|
|
45
|
-
return getGeofenceOnPoint(newFeature, radius, steps);
|
|
46
|
-
}
|
package/dist/src/geo/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './chunk-line.js';
|
|
2
|
-
export * from './constants.js';
|
|
3
|
-
export * from './conversions.js';
|
|
4
|
-
export * from './coordinates.js';
|
|
5
|
-
export * from './cut-line-at-length.js';
|
|
6
|
-
export * from './geojson-collections.js';
|
|
7
|
-
export * from './get-geofence-on-point.js';
|
|
8
|
-
export * from './is-point-in-polygon.js';
|
|
9
|
-
export * from './measurements.js';
|
package/dist/src/geo/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './chunk-line.js';
|
|
2
|
-
export * from './constants.js';
|
|
3
|
-
export * from './conversions.js';
|
|
4
|
-
export * from './coordinates.js';
|
|
5
|
-
export * from './cut-line-at-length.js';
|
|
6
|
-
export * from './geojson-collections.js';
|
|
7
|
-
export * from './get-geofence-on-point.js';
|
|
8
|
-
export * from './is-point-in-polygon.js';
|
|
9
|
-
export * from './measurements.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Feature, type Point, type Polygon, type Position } from 'geojson';
|
|
2
|
-
/**
|
|
3
|
-
* Check if a point is inside a polygon using the ray-casting algorithm.
|
|
4
|
-
* @param point A GeoJSON Point representation of the point to check.
|
|
5
|
-
* @param geofence A GeoJSON Polygon representation of the geofence.
|
|
6
|
-
* @returns A boolean indicating if the point is inside the polygon.
|
|
7
|
-
* @see https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
|
|
8
|
-
*/
|
|
9
|
-
export declare function isPointInPolygon(point: Feature<Point> | Position, polygon: Feature<Polygon>): boolean;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
/**
|
|
3
|
-
* Check if a point is inside a polygon using the ray-casting algorithm.
|
|
4
|
-
* @param point A GeoJSON Point representation of the point to check.
|
|
5
|
-
* @param geofence A GeoJSON Polygon representation of the geofence.
|
|
6
|
-
* @returns A boolean indicating if the point is inside the polygon.
|
|
7
|
-
* @see https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
|
|
8
|
-
*/
|
|
9
|
-
export function isPointInPolygon(point, polygon) {
|
|
10
|
-
//
|
|
11
|
-
const pt = Array.isArray(point) ? point : point.geometry.coordinates;
|
|
12
|
-
const [x, y] = pt;
|
|
13
|
-
const ring = polygon.geometry.coordinates[0]; // Outer ring only
|
|
14
|
-
let inside = false;
|
|
15
|
-
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
16
|
-
const xi = ring[i][0], yi = ring[i][1];
|
|
17
|
-
const xj = ring[j][0], yj = ring[j][1];
|
|
18
|
-
const intersectsVertically = (yi > y) !== (yj > y);
|
|
19
|
-
const edgeSlope = (xj - xi) / (yj - yi + 1e-10); // slope of the edge
|
|
20
|
-
const xIntersect = edgeSlope * (y - yi) + xi;
|
|
21
|
-
const isToRight = x < xIntersect;
|
|
22
|
-
const intersects = intersectsVertically && isToRight;
|
|
23
|
-
if (intersects)
|
|
24
|
-
inside = !inside;
|
|
25
|
-
}
|
|
26
|
-
return inside;
|
|
27
|
-
}
|
|
28
|
-
// /**
|
|
29
|
-
// * Check if a point is inside a geofence polygon.
|
|
30
|
-
// * @param point A GeoJSON Point representation of the point to check.
|
|
31
|
-
// * @param geofence A GeoJSON Polygon representation of the geofence.
|
|
32
|
-
// * @returns A boolean indicating if the point is inside the geofence polygon.
|
|
33
|
-
// */
|
|
34
|
-
// export function isInsideGeofence(point: Position, geofence: Feature<Polygon>): boolean {
|
|
35
|
-
// // Check if the point is inside the polygon
|
|
36
|
-
// return isPointInPolygon(point, geofence);
|
|
37
|
-
// }
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type Point, type Position } from 'geojson';
|
|
2
|
-
/**
|
|
3
|
-
* Calculates the distance between two points, in meters.
|
|
4
|
-
* This is a wrapper function around the `getDistanceBetweenPositions` function.
|
|
5
|
-
* @param pointA The first point.
|
|
6
|
-
* @param pointB The second point.
|
|
7
|
-
* @returns The distance between the two points, in meters.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getDistanceBetweenPoints(pointA: Point, pointB: Point): number;
|
|
10
|
-
/**
|
|
11
|
-
* Calculates the distance between two coordinate positions, in meters.
|
|
12
|
-
* This function uses the Haversine formula to calculate the distance
|
|
13
|
-
* between two points on the Earth's surface, given their latitude and longitude.
|
|
14
|
-
* The formula accounts for the curvature of the Earth.
|
|
15
|
-
* It is important to note that this function assumes the Earth is a perfect sphere,
|
|
16
|
-
* which is not entirely accurate, but it provides a good approximation for small distances.
|
|
17
|
-
* @param positionA The first position.
|
|
18
|
-
* @param positionB The second position.
|
|
19
|
-
* @returns The distance between the two points, in meters.
|
|
20
|
-
*/
|
|
21
|
-
export declare function getDistanceBetweenPositions(positionA: Position, positionB: Position): number;
|
|
22
|
-
/**
|
|
23
|
-
* Interpolates between two points at a given ratio (0..1).
|
|
24
|
-
* This is a wrapper function around the `interpolatePosition` function.
|
|
25
|
-
* @param pointA The first point.
|
|
26
|
-
* @param pointB The second point.
|
|
27
|
-
* @param ratio The ratio at which to interpolate (0 = pointA, 1 = pointB).
|
|
28
|
-
* @returns The interpolated point.
|
|
29
|
-
*/
|
|
30
|
-
export declare function interpolatePoints(pointA: Point, pointB: Point, ratio: number): Point;
|
|
31
|
-
/**
|
|
32
|
-
* Linearly interpolates between two positions at a given ratio (0..1).
|
|
33
|
-
* This function is useful for calculating intermediate points
|
|
34
|
-
* along a line segment defined by two positions.
|
|
35
|
-
* @param positionA The first position.
|
|
36
|
-
* @param positionB The second position.
|
|
37
|
-
* @param ratio The ratio at which to interpolate (0 = positionA, 1 = positionB).
|
|
38
|
-
* A ratio of 0.5 would give the midpoint between the two positions.
|
|
39
|
-
* A ratio of 0.25 would give a point closer to positionA.
|
|
40
|
-
* @returns The interpolated position.
|
|
41
|
-
*/
|
|
42
|
-
export declare function interpolatePositions(positionA: Position, positionB: Position, ratio: number): Position;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
import { METERS_PER_DEGREE } from './constants.js';
|
|
3
|
-
import { toPointFromPositions } from './conversions.js';
|
|
4
|
-
/**
|
|
5
|
-
* Calculates the distance between two points, in meters.
|
|
6
|
-
* This is a wrapper function around the `getDistanceBetweenPositions` function.
|
|
7
|
-
* @param pointA The first point.
|
|
8
|
-
* @param pointB The second point.
|
|
9
|
-
* @returns The distance between the two points, in meters.
|
|
10
|
-
*/
|
|
11
|
-
export function getDistanceBetweenPoints(pointA, pointB) {
|
|
12
|
-
return getDistanceBetweenPositions(pointA.coordinates, pointB.coordinates);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Calculates the distance between two coordinate positions, in meters.
|
|
16
|
-
* This function uses the Haversine formula to calculate the distance
|
|
17
|
-
* between two points on the Earth's surface, given their latitude and longitude.
|
|
18
|
-
* The formula accounts for the curvature of the Earth.
|
|
19
|
-
* It is important to note that this function assumes the Earth is a perfect sphere,
|
|
20
|
-
* which is not entirely accurate, but it provides a good approximation for small distances.
|
|
21
|
-
* @param positionA The first position.
|
|
22
|
-
* @param positionB The second position.
|
|
23
|
-
* @returns The distance between the two points, in meters.
|
|
24
|
-
*/
|
|
25
|
-
export function getDistanceBetweenPositions(positionA, positionB) {
|
|
26
|
-
// Extract coordinates from the points
|
|
27
|
-
const [lngA, latA] = positionA;
|
|
28
|
-
const [lngB, latB] = positionB;
|
|
29
|
-
// Calculate the average latitude
|
|
30
|
-
const averageLatitude = (latA + latB) / 2;
|
|
31
|
-
// Calculate the differences in longitude and latitude
|
|
32
|
-
const dx = (lngB - lngA) * METERS_PER_DEGREE * Math.cos((averageLatitude * Math.PI) / 180);
|
|
33
|
-
const dy = (latB - latA) * METERS_PER_DEGREE;
|
|
34
|
-
// Calculate the distance using the Pythagorean theorem
|
|
35
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Interpolates between two points at a given ratio (0..1).
|
|
39
|
-
* This is a wrapper function around the `interpolatePosition` function.
|
|
40
|
-
* @param pointA The first point.
|
|
41
|
-
* @param pointB The second point.
|
|
42
|
-
* @param ratio The ratio at which to interpolate (0 = pointA, 1 = pointB).
|
|
43
|
-
* @returns The interpolated point.
|
|
44
|
-
*/
|
|
45
|
-
export function interpolatePoints(pointA, pointB, ratio) {
|
|
46
|
-
const result = interpolatePositions(pointA.coordinates, pointB.coordinates, ratio);
|
|
47
|
-
return toPointFromPositions(result);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Linearly interpolates between two positions at a given ratio (0..1).
|
|
51
|
-
* This function is useful for calculating intermediate points
|
|
52
|
-
* along a line segment defined by two positions.
|
|
53
|
-
* @param positionA The first position.
|
|
54
|
-
* @param positionB The second position.
|
|
55
|
-
* @param ratio The ratio at which to interpolate (0 = positionA, 1 = positionB).
|
|
56
|
-
* A ratio of 0.5 would give the midpoint between the two positions.
|
|
57
|
-
* A ratio of 0.25 would give a point closer to positionA.
|
|
58
|
-
* @returns The interpolated position.
|
|
59
|
-
*/
|
|
60
|
-
export function interpolatePositions(positionA, positionB, ratio) {
|
|
61
|
-
// Extract coordinates from the points
|
|
62
|
-
const lng = positionA[0] + (positionB[0] - positionA[0]) * ratio;
|
|
63
|
-
const lat = positionA[1] + (positionB[1] - positionA[1]) * ratio;
|
|
64
|
-
// Preserve elevation if present
|
|
65
|
-
if (positionA.length > 2 && positionB.length > 2) {
|
|
66
|
-
const alt = positionA[2] + (positionB[2] - positionA[2]) * ratio;
|
|
67
|
-
return [lng, lat, alt];
|
|
68
|
-
}
|
|
69
|
-
// Return the interpolated position
|
|
70
|
-
return [lng, lat];
|
|
71
|
-
}
|
package/dist/src/logs/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './logs.js';
|
package/dist/src/logs/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './logs.js';
|
package/dist/src/logs/logs.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
interface LogColumn {
|
|
2
|
-
/**
|
|
3
|
-
* Column alignment.
|
|
4
|
-
*/
|
|
5
|
-
a?: 'left' | 'right';
|
|
6
|
-
/**
|
|
7
|
-
* Column width.
|
|
8
|
-
*/
|
|
9
|
-
c?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Column text.
|
|
12
|
-
*/
|
|
13
|
-
t: number | string;
|
|
14
|
-
}
|
|
15
|
-
type LogMessage = (LogColumn | string)[] | string;
|
|
16
|
-
declare class LogsClass {
|
|
17
|
-
/**
|
|
18
|
-
* Logs a divider line in the console.
|
|
19
|
-
* @param message Optional message to display.
|
|
20
|
-
* @param size Width of the divider line. Default is `75`.
|
|
21
|
-
*/
|
|
22
|
-
divider(message?: string, size?: number): void;
|
|
23
|
-
/**
|
|
24
|
-
* Logs an error message in the console.
|
|
25
|
-
* @param message Error message to display.
|
|
26
|
-
* @param error Optional error object to display.
|
|
27
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
28
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
29
|
-
*/
|
|
30
|
-
error(message: LogMessage, error?: Error, spacesAfter?: number, spacesBefore?: number): void;
|
|
31
|
-
/**
|
|
32
|
-
* Logs an informational message in the console.
|
|
33
|
-
* @param message Informational message to display.
|
|
34
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
35
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
36
|
-
*/
|
|
37
|
-
info(message: LogMessage, spacesAfter?: number, spacesBefore?: number): void;
|
|
38
|
-
/**
|
|
39
|
-
* Initial message for program startup.
|
|
40
|
-
*/
|
|
41
|
-
init(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Logs a progress message in the console.
|
|
44
|
-
* @param message Progress message to display.
|
|
45
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
46
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
47
|
-
*/
|
|
48
|
-
progress(message: LogMessage, spacesAfter?: number, spacesBefore?: number): void;
|
|
49
|
-
/**
|
|
50
|
-
* Logs a spacer line in the console.
|
|
51
|
-
* @param lines Number of blank lines to add. Default is `1`.
|
|
52
|
-
*/
|
|
53
|
-
spacer(lines?: number): void;
|
|
54
|
-
/**
|
|
55
|
-
* Logs a success message in the console.
|
|
56
|
-
* @param message Success message to display.
|
|
57
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
58
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
59
|
-
*/
|
|
60
|
-
success(message: LogMessage, spacesAfter?: number, spacesBefore?: number): void;
|
|
61
|
-
/**
|
|
62
|
-
* Logs a termination message in the console.
|
|
63
|
-
* @param message Termination message to display.
|
|
64
|
-
*/
|
|
65
|
-
terminate(message: string): void;
|
|
66
|
-
/**
|
|
67
|
-
* Logs a title message in the console.
|
|
68
|
-
* @param message Title message to display.
|
|
69
|
-
*/
|
|
70
|
-
title(message: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Formats an array of log columns or strings into a single string.
|
|
73
|
-
* @param columns Array of log columns or strings to format.
|
|
74
|
-
* @returns Formatted string.
|
|
75
|
-
*/
|
|
76
|
-
private formatColumns;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Logger class for structured logging.
|
|
80
|
-
*/
|
|
81
|
-
export declare const Logs: LogsClass;
|
|
82
|
-
export {};
|
package/dist/src/logs/logs.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
/* * */
|
|
3
|
-
class LogsClass {
|
|
4
|
-
//
|
|
5
|
-
/**
|
|
6
|
-
* Logs a divider line in the console.
|
|
7
|
-
* @param message Optional message to display.
|
|
8
|
-
* @param size Width of the divider line. Default is `75`.
|
|
9
|
-
*/
|
|
10
|
-
divider(message, size = 75) {
|
|
11
|
-
console.log();
|
|
12
|
-
if (message)
|
|
13
|
-
console.log(`- ${message} ${'-'.repeat(size - 2 - message.length < 1 ? 1 : size - 2 - message.length)}`);
|
|
14
|
-
else
|
|
15
|
-
console.log('-'.repeat(size));
|
|
16
|
-
console.log();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Logs an error message in the console.
|
|
20
|
-
* @param message Error message to display.
|
|
21
|
-
* @param error Optional error object to display.
|
|
22
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
23
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
24
|
-
*/
|
|
25
|
-
error(message, error, spacesAfter, spacesBefore) {
|
|
26
|
-
if (spacesBefore && spacesBefore > 0)
|
|
27
|
-
this.spacer(spacesBefore);
|
|
28
|
-
if (Array.isArray(message))
|
|
29
|
-
console.error(`✘ ${this.formatColumns(message)}`, error ?? '');
|
|
30
|
-
else
|
|
31
|
-
console.error(`✘ ${message}`, error ?? '');
|
|
32
|
-
if (spacesAfter && spacesAfter > 0)
|
|
33
|
-
this.spacer(spacesAfter);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Logs an informational message in the console.
|
|
37
|
-
* @param message Informational message to display.
|
|
38
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
39
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
40
|
-
*/
|
|
41
|
-
info(message, spacesAfter, spacesBefore) {
|
|
42
|
-
if (spacesBefore && spacesBefore > 0)
|
|
43
|
-
this.spacer(spacesBefore);
|
|
44
|
-
if (Array.isArray(message))
|
|
45
|
-
console.log(`→ ${this.formatColumns(message)}`);
|
|
46
|
-
else
|
|
47
|
-
console.log(`→ ${message}`);
|
|
48
|
-
if (spacesAfter && spacesAfter > 0)
|
|
49
|
-
this.spacer(spacesAfter);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Initial message for program startup.
|
|
53
|
-
*/
|
|
54
|
-
init() {
|
|
55
|
-
const currentDate = new Date().toISOString();
|
|
56
|
-
console.log();
|
|
57
|
-
console.log('-'.repeat(currentDate.length));
|
|
58
|
-
console.log(currentDate);
|
|
59
|
-
console.log('-'.repeat(currentDate.length));
|
|
60
|
-
console.log();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Logs a progress message in the console.
|
|
64
|
-
* @param message Progress message to display.
|
|
65
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
66
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
67
|
-
*/
|
|
68
|
-
progress(message, spacesAfter, spacesBefore) {
|
|
69
|
-
if (spacesBefore && spacesBefore > 0)
|
|
70
|
-
this.spacer(spacesBefore);
|
|
71
|
-
if (Array.isArray(message))
|
|
72
|
-
console.log(`• ${this.formatColumns(message)}`);
|
|
73
|
-
else
|
|
74
|
-
console.log(`• ${message}`);
|
|
75
|
-
if (spacesAfter && spacesAfter > 0)
|
|
76
|
-
this.spacer(spacesAfter);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Logs a spacer line in the console.
|
|
80
|
-
* @param lines Number of blank lines to add. Default is `1`.
|
|
81
|
-
*/
|
|
82
|
-
spacer(lines = 1) {
|
|
83
|
-
for (let i = 0; i < lines; i++) {
|
|
84
|
-
console.log();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Logs a success message in the console.
|
|
89
|
-
* @param message Success message to display.
|
|
90
|
-
* @param spacesAfter Optional number of blank lines to add after the message.
|
|
91
|
-
* @param spacesBefore Optional number of blank lines to add before the message.
|
|
92
|
-
*/
|
|
93
|
-
success(message, spacesAfter, spacesBefore) {
|
|
94
|
-
if (spacesBefore && spacesBefore > 0)
|
|
95
|
-
this.spacer(spacesBefore);
|
|
96
|
-
if (Array.isArray(message))
|
|
97
|
-
console.log(`✓ ${this.formatColumns(message)}`);
|
|
98
|
-
else
|
|
99
|
-
console.log(`✓ ${message}`);
|
|
100
|
-
if (spacesAfter && spacesAfter > 0)
|
|
101
|
-
this.spacer(spacesAfter);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Logs a termination message in the console.
|
|
105
|
-
* @param message Termination message to display.
|
|
106
|
-
*/
|
|
107
|
-
terminate(message) {
|
|
108
|
-
console.log();
|
|
109
|
-
console.log('-'.repeat(message.length));
|
|
110
|
-
console.log(message);
|
|
111
|
-
console.log('-'.repeat(message.length));
|
|
112
|
-
console.log();
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Logs a title message in the console.
|
|
116
|
-
* @param message Title message to display.
|
|
117
|
-
*/
|
|
118
|
-
title(message) {
|
|
119
|
-
console.log();
|
|
120
|
-
console.log(`▶︎ ${message}`);
|
|
121
|
-
console.log();
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Formats an array of log columns or strings into a single string.
|
|
125
|
-
* @param columns Array of log columns or strings to format.
|
|
126
|
-
* @returns Formatted string.
|
|
127
|
-
*/
|
|
128
|
-
formatColumns(columns) {
|
|
129
|
-
return columns
|
|
130
|
-
.map((item) => {
|
|
131
|
-
if (typeof item === 'string')
|
|
132
|
-
return item;
|
|
133
|
-
if (!item.c)
|
|
134
|
-
return String(item.t);
|
|
135
|
-
if (item.a === 'right')
|
|
136
|
-
return String(item.t).padStart(item.c);
|
|
137
|
-
return String(item.t).padEnd(item.c);
|
|
138
|
-
})
|
|
139
|
-
.join('');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Logger class for structured logging.
|
|
144
|
-
*/
|
|
145
|
-
export const Logs = new LogsClass();
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
/**
|
|
3
|
-
* Calculates the coefficient of variation for an array of numbers.
|
|
4
|
-
* @param value An array of numbers.
|
|
5
|
-
* @returns The coefficient of variation.
|
|
6
|
-
*/
|
|
7
|
-
export function coefficientOfVariation(values) {
|
|
8
|
-
const mean = values.reduce((a, b) => a + b, 0) / values.length;
|
|
9
|
-
if (mean === 0)
|
|
10
|
-
return 0;
|
|
11
|
-
const variance = values.reduce((a, b) => a + (b - mean) ** 2, 0) / values.length;
|
|
12
|
-
const std = Math.sqrt(variance);
|
|
13
|
-
return std / mean;
|
|
14
|
-
}
|
package/dist/src/math/entropy.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
/**
|
|
3
|
-
* Calculates the entropy for an array of values.
|
|
4
|
-
* @param values An array of numbers representing values.
|
|
5
|
-
* @returns The entropy of the values.
|
|
6
|
-
*/
|
|
7
|
-
export function entropy(values) {
|
|
8
|
-
const counts = {};
|
|
9
|
-
for (const d of values) {
|
|
10
|
-
const bucket = Math.round(d); // 1-second bins
|
|
11
|
-
counts[bucket] = (counts[bucket] ?? 0) + 1;
|
|
12
|
-
}
|
|
13
|
-
const total = values.length;
|
|
14
|
-
let entropy = 0;
|
|
15
|
-
for (const count of Object.values(counts)) {
|
|
16
|
-
const p = count / total;
|
|
17
|
-
entropy -= p * Math.log2(p);
|
|
18
|
-
}
|
|
19
|
-
return entropy;
|
|
20
|
-
}
|
package/dist/src/math/index.d.ts
DELETED
package/dist/src/math/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
/**
|
|
3
|
-
* Calculates the round number bias for an array of values.
|
|
4
|
-
* @param values An array of numbers representing values.
|
|
5
|
-
* @returns The round number bias of the values.
|
|
6
|
-
*/
|
|
7
|
-
export function roundNumberBias(values) {
|
|
8
|
-
// Fraction of values that are "round" (multiples of 5 or 10)
|
|
9
|
-
const rounded = values.filter(d => d % 5 === 0 || d % 10 === 0).length;
|
|
10
|
-
return rounded / values.length;
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './keep-url-params.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './keep-url-params.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility function to keep URL parameters when navigating to a new destination.
|
|
3
|
-
* This function appends the provided search parameters to the destination URL.
|
|
4
|
-
* @param destination The base URL to which the search parameters will be appended.
|
|
5
|
-
* @param searchParams The search parameters to append. You can get this with `window.location.search`.
|
|
6
|
-
* @returns A new URL string that combines the destination and the search parameters.
|
|
7
|
-
*/
|
|
8
|
-
export declare function keepUrlParams(destination: string, searchParams?: string): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* * */
|
|
2
|
-
/**
|
|
3
|
-
* Utility function to keep URL parameters when navigating to a new destination.
|
|
4
|
-
* This function appends the provided search parameters to the destination URL.
|
|
5
|
-
* @param destination The base URL to which the search parameters will be appended.
|
|
6
|
-
* @param searchParams The search parameters to append. You can get this with `window.location.search`.
|
|
7
|
-
* @returns A new URL string that combines the destination and the search parameters.
|
|
8
|
-
*/
|
|
9
|
-
export function keepUrlParams(destination, searchParams) {
|
|
10
|
-
if (!searchParams)
|
|
11
|
-
return destination;
|
|
12
|
-
return `${destination}${searchParams}`;
|
|
13
|
-
}
|
package/dist/src/nuqs/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/src/nuqs/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// /* * */
|
|
2
|
-
export {};
|
|
3
|
-
// import { createParser } from 'nuqs';
|
|
4
|
-
// /* * */
|
|
5
|
-
// const parseFn = (queryValue: string) => {
|
|
6
|
-
// // Skip if the query value is invalid.
|
|
7
|
-
// if (!queryValue || typeof queryValue !== 'string') return null;
|
|
8
|
-
// // Handle the special case where the query value is 'none'.
|
|
9
|
-
// if (queryValue === 'none') return [];
|
|
10
|
-
// // Split the query value by commas, trim each item,
|
|
11
|
-
// // filter out empty items, and return a sorted unique string.
|
|
12
|
-
// return queryValue
|
|
13
|
-
// .split(',')
|
|
14
|
-
// .map(item => item.trim())
|
|
15
|
-
// .filter(item => item !== 'none' && item !== '');
|
|
16
|
-
// };
|
|
17
|
-
// /* * */
|
|
18
|
-
// const serializeFn = (value: string[]) => {
|
|
19
|
-
// // Skip if the value is not a valid array.
|
|
20
|
-
// if (!Array.isArray(value)) return null;
|
|
21
|
-
// // Handle the special case where the value is empty.
|
|
22
|
-
// if (value.length === 0) return 'none';
|
|
23
|
-
// // Return a sorted unique string of values.
|
|
24
|
-
// // This ensures that the values are unique and sorted,
|
|
25
|
-
// // which is essential for consistent filtering.
|
|
26
|
-
// return Array
|
|
27
|
-
// .from(new Set(value))
|
|
28
|
-
// .sort()
|
|
29
|
-
// .map(item => item.trim())
|
|
30
|
-
// .join(',');
|
|
31
|
-
// };
|
|
32
|
-
// /* * */
|
|
33
|
-
// const eqFn = (a: string[], b: string[]) => {
|
|
34
|
-
// // Skip if the values are not valid arrays.
|
|
35
|
-
// if (!Array.isArray(a) || !Array.isArray(b)) return null;
|
|
36
|
-
// // Check if the arrays are equal by quickly comparing their lengths
|
|
37
|
-
// if (a.length !== b.length) return false;
|
|
38
|
-
// // If the length is the same ensure they're equal by also
|
|
39
|
-
// // checking if every item in one array is included in the other.
|
|
40
|
-
// return a.every(item => b.includes(item)) && b.every(item => a.includes(item));
|
|
41
|
-
// };
|
|
42
|
-
// /* * */
|
|
43
|
-
// export const parseAsArrayOfStrings = createParser({ eq: eqFn, parse: parseFn, serialize: serializeFn });
|