@trackunit/shared-utils 0.0.3-alpha-bfdefa6ec9.0
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 +17 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +8676 -0
- package/index.esm.js +8614 -0
- package/package.json +17 -0
- package/src/DateTimeFormat.d.ts +19 -0
- package/src/DateUtils.d.ts +29 -0
- package/src/GeoJsonUtils.d.ts +26 -0
- package/src/TimePeriod.d.ts +12 -0
- package/src/UnitOfMeasurementConverter.d.ts +14 -0
- package/src/addressUtils.d.ts +32 -0
- package/src/arrayUtils.d.ts +24 -0
- package/src/chameleonUtils.d.ts +4 -0
- package/src/constants/align.d.ts +6 -0
- package/src/constants/hourIntervals.d.ts +1 -0
- package/src/constants/index.d.ts +3 -0
- package/src/constants/size.d.ts +6 -0
- package/src/dimensionHelpers.d.ts +11 -0
- package/src/doNothing.d.ts +4 -0
- package/src/enumUtils.d.ts +28 -0
- package/src/exhaustiveCheck.d.ts +14 -0
- package/src/fastArrayOperations.d.ts +14 -0
- package/src/filter.d.ts +25 -0
- package/src/groupBy/groupBy.d.ts +9 -0
- package/src/idUtils.d.ts +26 -0
- package/src/index.d.ts +25 -0
- package/src/maybe.d.ts +4 -0
- package/src/objectUtils.d.ts +8 -0
- package/src/pathUtils.d.ts +18 -0
- package/src/pictureUtils/pictureUtils.d.ts +42 -0
- package/src/sorting/sorting.d.ts +84 -0
- package/src/stringUtils.d.ts +30 -0
- package/src/timePeriodConverter/timePeriodConverter.d.ts +34 -0
- package/src/typeUtils.d.ts +32 -0
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trackunit/shared-utils",
|
|
3
|
+
"version": "0.0.3-alpha-bfdefa6ec9.0",
|
|
4
|
+
"repository": "https://github.com/Trackunit/manager",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=18.x"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@sentry/react": "7.57.0",
|
|
11
|
+
"crossfilter2": "1.5.4",
|
|
12
|
+
"moment": "2.29.4"
|
|
13
|
+
},
|
|
14
|
+
"module": "./index.esm.js",
|
|
15
|
+
"main": "./index.cjs.js",
|
|
16
|
+
"peerDependencies": {}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare enum HoursAndMinutesFormat {
|
|
2
|
+
HOURS_MIN_SEC_LONG = "HOURS_MIN_SEC_LONG",
|
|
3
|
+
HOURS_MIN_SEC = "HOURS_MIN_SEC",
|
|
4
|
+
HOURS_MIN_LONG = "HOURS_MIN_LONG",
|
|
5
|
+
HOURS_MIN = "HOURS_MIN",
|
|
6
|
+
HOURS_LONG = "HOURS_LONG"
|
|
7
|
+
}
|
|
8
|
+
export declare enum DateTimeFormat {
|
|
9
|
+
DATE = "L",
|
|
10
|
+
DATE_LONG = "LL",
|
|
11
|
+
DATE_LONG_TIME = "LLL",
|
|
12
|
+
DATE_SHORT = "ll",
|
|
13
|
+
DATE_SHORT_TIME = "lll",
|
|
14
|
+
TIME_SHORT = "LT",
|
|
15
|
+
TIME_LONG = "LTS",
|
|
16
|
+
YEAR = "YYYY",
|
|
17
|
+
YEAR_MONTH_DAY = "yyyy-MM-DD",
|
|
18
|
+
MONTH_DAY = "MMM, Do"
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Converts a date to a string in ISO format.
|
|
3
|
+
* @param date A date object or a date string.
|
|
4
|
+
* @returns {string | null} A string in ISO format or null if the input is invalid.
|
|
5
|
+
* @example getISOStringFromDate(new Date("2021-05-19T12:34:56")) // "2021-05-19T12:34:56.000Z"
|
|
6
|
+
*/
|
|
7
|
+
export declare const getISOStringFromDate: (date: Date | string | undefined | null) => string | null;
|
|
8
|
+
/**
|
|
9
|
+
* @description Returns the difference between two dates in the specified unit.
|
|
10
|
+
* @param date1 The first date.
|
|
11
|
+
* @param date2 The second date.
|
|
12
|
+
* @param unit The unit to return the difference in.
|
|
13
|
+
* @returns {number} The difference between the two dates in the specified unit.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getDifferenceBetweenDates: (date1: Date, date2: Date, unit: "days" | "hours" | "minutes" | "seconds") => number;
|
|
16
|
+
/**
|
|
17
|
+
* @description Returns the start of the day for a given date.
|
|
18
|
+
* @param date A date object or a date string.
|
|
19
|
+
* @returns {Date} The start of the day for the given date.
|
|
20
|
+
* @example getStartOfDay(new Date("2021-05-19T12:34:56")) // "2021-05-19T00:00:00"
|
|
21
|
+
*/
|
|
22
|
+
export declare const getStartOfDay: <T extends string | number | Date>(date: T) => Date;
|
|
23
|
+
/**
|
|
24
|
+
* @description Returns the end of the day for a given date.
|
|
25
|
+
* @param date A date object or a date string.
|
|
26
|
+
* @returns {Date} The end of the day for the given date.
|
|
27
|
+
* @example getEndOfDay(new Date("2021-05-19T12:34:56")) // "2021-05-19T23:59:59"
|
|
28
|
+
*/
|
|
29
|
+
export declare const getEndOfDay: <T extends string | number | Date>(date: T) => Date;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface PointCoordinate {
|
|
2
|
+
longitude: number;
|
|
3
|
+
latitude: number;
|
|
4
|
+
}
|
|
5
|
+
interface GeoJSONGeometry {
|
|
6
|
+
type?: unknown;
|
|
7
|
+
coordinates?: number[] | number[][] | null;
|
|
8
|
+
}
|
|
9
|
+
interface GeoJsonFeature {
|
|
10
|
+
type?: unknown;
|
|
11
|
+
geometry?: GeoJSONGeometry | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @description Extracts a point coordinate from a GeoJSON object.
|
|
15
|
+
* @param geoObject A GeoJSON object.
|
|
16
|
+
* @returns {PointCoordinate} A point coordinate.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getPointCoordinateFromGeoJsonObject: (geoObject: GeoJsonFeature | GeoJSONGeometry | undefined | null) => PointCoordinate | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* @description Extracts multiple point coordinates from a GeoJSON object.
|
|
21
|
+
* @param geoObject A GeoJSON object.
|
|
22
|
+
* @returns {PointCoordinate[]} An array of point coordinates.
|
|
23
|
+
* @example getMultipleCoordinatesFromGeoJsonObject({ type: "Point", coordinates: [1, 2] }) // [{ longitude: 1, latitude: 2 }]
|
|
24
|
+
*/
|
|
25
|
+
export declare const getMultipleCoordinatesFromGeoJsonObject: (geoObject: GeoJsonFeature | GeoJSONGeometry | undefined | null) => PointCoordinate[] | undefined;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum TimePeriod {
|
|
2
|
+
THIS_WEEK = "THIS_WEEK",
|
|
3
|
+
LAST_WEEK = "LAST_WEEK",
|
|
4
|
+
THIS_MONTH = "THIS_MONTH",
|
|
5
|
+
LAST_MONTH = "LAST_MONTH"
|
|
6
|
+
}
|
|
7
|
+
export declare enum DayPeriod {
|
|
8
|
+
LAST_24_HOURS = "LAST_24_HOURS",
|
|
9
|
+
LAST_7_DAYS = "LAST_7_DAYS",
|
|
10
|
+
LAST_30_DAYS = "LAST_30_DAYS",
|
|
11
|
+
LIFETIME = "LIFETIME"
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts meters to yards
|
|
3
|
+
*
|
|
4
|
+
* @param value The value to convert
|
|
5
|
+
* @returns {number | undefined} The converted value
|
|
6
|
+
*/
|
|
7
|
+
export declare const convertMetersToYards: (value: number) => number | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Converts yards to meters
|
|
10
|
+
*
|
|
11
|
+
* @param value The value to convert
|
|
12
|
+
* @returns {number | undefined} The converted value
|
|
13
|
+
*/
|
|
14
|
+
export declare const convertYardsToMeters: (value: number) => number | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface Address {
|
|
2
|
+
/** The city of the address. */
|
|
3
|
+
city?: string | null;
|
|
4
|
+
/** The country of the address. */
|
|
5
|
+
country?: string | null;
|
|
6
|
+
/** The street address. */
|
|
7
|
+
streetAddress?: string | null;
|
|
8
|
+
/** The zip code or postal code of the address. */
|
|
9
|
+
zipCode?: string | null;
|
|
10
|
+
}
|
|
11
|
+
interface Coordinates {
|
|
12
|
+
/** The latitude of the coordinate. */
|
|
13
|
+
latitude: number;
|
|
14
|
+
/** The longitude of the coordinate. */
|
|
15
|
+
longitude: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @description Formats an address into a single string.
|
|
19
|
+
* @param address The address to format.
|
|
20
|
+
* @returns {string} The formatted address.
|
|
21
|
+
* @example formatAddress({ streetAddress: "Street 1", zipCode: "12345", city: "City", country: "Country" }) // "Street 1, 12345 City, Country"
|
|
22
|
+
*/
|
|
23
|
+
export declare const formatAddress: (address: Address | null | undefined) => string | null;
|
|
24
|
+
/**
|
|
25
|
+
* @description Formats coordinates into a single string.
|
|
26
|
+
* @param coordinates The coordinates to format.
|
|
27
|
+
* @param toFixed The number of digits to appear after the decimal point.
|
|
28
|
+
* @returns {string} The formatted coordinates.
|
|
29
|
+
* @example formatCoordinates({ latitude: 1.234567, longitude: 2.345678 }) // "1.234567, 2.345678"
|
|
30
|
+
*/
|
|
31
|
+
export declare const formatCoordinates: (coordinates: Coordinates, toFixed?: number) => string;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** toggle whether a value is in an array or not */
|
|
2
|
+
export declare function toggle<T>(array: T[] | null | undefined, value: T | null | undefined): T[];
|
|
3
|
+
/** Ensure the argument is an array, if not, create array with that element in it */
|
|
4
|
+
export declare function ensureArray<T>(arrayish: T | T[]): T[];
|
|
5
|
+
/**
|
|
6
|
+
* Returns the first item in an array, and logs a warning if there are more than one item in the array.
|
|
7
|
+
*
|
|
8
|
+
* @param array The array to get the first item from
|
|
9
|
+
* @param location The location from where this function is called
|
|
10
|
+
* @returns The first item in the array
|
|
11
|
+
* @example getFirstItemAndLogIfMore([1, 2, 3], "getFirstItemAndLogIfMore") // 1
|
|
12
|
+
*/
|
|
13
|
+
export declare const getFirstItemAndLogIfMore: <T>(array?: T[] | null | undefined, location?: string) => T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
16
|
+
*
|
|
17
|
+
* @param key The key to use to determine uniqueness
|
|
18
|
+
* @param previous The previous array of items to merge with the new array
|
|
19
|
+
* @param newArray The new array of items to merge with the previous array
|
|
20
|
+
* @returns A new array with the items from the previous array and the new array, but only if the item's key is unique.
|
|
21
|
+
*/
|
|
22
|
+
export declare const unionArraysByKey: <T extends object>(key: keyof T, previous: T[] | null | undefined, newArray: T[] | null | undefined) => T[];
|
|
23
|
+
/** Ensures if an array is equal to another array */
|
|
24
|
+
export declare const isStringArrayEqual: (first?: string[], second?: string[]) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hourIntervals: readonly ["0", "0–2", "2–4", "4–6", "6–8", "8–10", "10–12", "12–14", "14–16", "16–18", "18–20", "20–22", "22–24"];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import crossfilter from "crossfilter2";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the filtered record values where the value is over 0
|
|
4
|
+
*
|
|
5
|
+
* @param dimension the record dimension
|
|
6
|
+
*/
|
|
7
|
+
export declare const getDimensionValues: <RecordType, TValue extends crossfilter.NaturallyOrderedValue>(dimension: crossfilter.Dimension<RecordType, TValue>) => crossfilter.Grouping<crossfilter.NaturallyOrderedValue, crossfilter.NaturallyOrderedValue>[];
|
|
8
|
+
/**
|
|
9
|
+
* This value is used to group null or undefined values
|
|
10
|
+
*/
|
|
11
|
+
export declare const UNKNOWN_VALUE = "Unknown";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the enum value from a string value.
|
|
3
|
+
*
|
|
4
|
+
* @param val The string value to convert to an enum value.
|
|
5
|
+
* @param _enum The enum to convert the string value to.
|
|
6
|
+
* @returns {Record<string, string>} The enum value.
|
|
7
|
+
* @example enumFromValue("MACHINE", AssetType) // AssetType.MACHINE
|
|
8
|
+
*/
|
|
9
|
+
export declare const enumFromValue: <T extends Record<string, string>>(val: string, _enum: T) => T[keyof T];
|
|
10
|
+
/**
|
|
11
|
+
* Returns the enum value from a string value or undefined if the string value is undefined or null.
|
|
12
|
+
*
|
|
13
|
+
* @param _enum The enum to convert the string value to.
|
|
14
|
+
* @param val The string value to convert to an enum value.
|
|
15
|
+
* @returns {Record<string, string> | undefined} The enum value or undefined.
|
|
16
|
+
* @example enumFromValue("MACHINE", AssetType) // AssetType.MACHINE
|
|
17
|
+
*/
|
|
18
|
+
export declare const enumOrUndefinedFromValue: <T extends Record<string, string>>(_enum: T, val?: string | null) => T[keyof T] | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the enum value from a string value or undefined if the string value is undefined or null.
|
|
21
|
+
* This is a typesafe version of enumOrUndefinedFromValue.
|
|
22
|
+
*
|
|
23
|
+
* @param val The string value to convert to an enum value.
|
|
24
|
+
* @param _enum The enum to convert the string value to.
|
|
25
|
+
* @returns {Record<string, string> | undefined} The enum value or undefined.
|
|
26
|
+
* @example enumFromValue("MACHINE", AssetType) // AssetType.MACHINE
|
|
27
|
+
*/
|
|
28
|
+
export declare const enumFromValueTypesafe: <T extends Record<string, string>>(val: keyof T, _enum: T) => T[keyof T];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that will throw an error if it is called with a value that is not of type `never`.
|
|
3
|
+
* This is useful for exhaustiveness checks in switch statements.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const type: "foo" | "bar" | "other" =
|
|
7
|
+
* switch (type) {
|
|
8
|
+
* case "foo": return foo();
|
|
9
|
+
* case "bar": return bar();
|
|
10
|
+
* default: return exhaustiveCheck(type); // Will show a TS error as "other" is not of type "never"
|
|
11
|
+
* }
|
|
12
|
+
* @param value The value you want to check exhaustively
|
|
13
|
+
*/
|
|
14
|
+
export declare const exhaustiveCheck: (value: never) => never;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param arr1 An array of string or numbers
|
|
4
|
+
* @param arr2 An array of string or numbers
|
|
5
|
+
* @returns The elements shared between arr1 and arr2.
|
|
6
|
+
*/
|
|
7
|
+
export declare function intersection<T>(arr1: T[], arr2: T[]): T[];
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param arr1 An array of string or numbers
|
|
11
|
+
* @param arr2 An array of string or numbers
|
|
12
|
+
* @returns The elements present in arr1 but not arr2.
|
|
13
|
+
*/
|
|
14
|
+
export declare function difference<T>(arr1: T[], arr2: T[]): T[];
|
package/src/filter.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Maybe } from "./maybe";
|
|
2
|
+
/**
|
|
3
|
+
* Filter an array of items based on a list of properties and a search term.
|
|
4
|
+
* The provided properties will be matched based on the term split on space.
|
|
5
|
+
* All terms must have at least one match
|
|
6
|
+
* The terms can match the same property multiple times
|
|
7
|
+
*
|
|
8
|
+
* @param array The array to filter
|
|
9
|
+
* @param props The properties to filter by
|
|
10
|
+
* @param match The string to match against
|
|
11
|
+
* @returns {[]} The filtered array
|
|
12
|
+
* @example filterByMultiple([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], [p => p.name, p => p.surname], "John") // [{ name: "John", surname: "Doe" }]
|
|
13
|
+
*/
|
|
14
|
+
export declare function filterByMultiple<T>(array: T[] | null | undefined, props: (p: T) => Maybe<string>[] | null | undefined, match: string): T[];
|
|
15
|
+
/**
|
|
16
|
+
* Filter an array of items based on a list of properties and a search term.
|
|
17
|
+
* The provided properties will be matched based on the term split on space.
|
|
18
|
+
* All terms must have at least one match
|
|
19
|
+
* The terms can match the same property multiple times
|
|
20
|
+
*/
|
|
21
|
+
export declare const fuzzySearch: <T>(elementsToFilter: T[], filterableProps: (element: T) => string[], searchTerm: string) => T[];
|
|
22
|
+
/**
|
|
23
|
+
* Filter an array of items based on a search term.
|
|
24
|
+
*/
|
|
25
|
+
export declare const Search: <T>(elementsToSearch: T[], searchableProps: (element: T) => string[], searchTerm: string) => T[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Group an array of items by a key.
|
|
3
|
+
*
|
|
4
|
+
* @param list The array of items to group.
|
|
5
|
+
* @param getKey A function to get the key to group by.
|
|
6
|
+
* @returns A map of the items grouped by the key.
|
|
7
|
+
* @example groupBy([{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }], p => p.surname) // Map { "Doe" => [{ name: "John", surname: "Doe" }, { name: "Jane", surname: "Doe" }] }
|
|
8
|
+
*/
|
|
9
|
+
export declare function groupBy<T, K>(list: T[], getKey: (item: T) => K): Map<K, T[]>;
|
package/src/idUtils.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility function to test whether a string is a valid UUID or not.
|
|
3
|
+
*
|
|
4
|
+
* @param input A string.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isUUID: (input: string) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* A helper function that converts any value into a UUID.
|
|
9
|
+
*
|
|
10
|
+
* @param value The value that will be converted into a UUID.
|
|
11
|
+
*/
|
|
12
|
+
export declare const toUUID: (value: string | number) => string;
|
|
13
|
+
/**
|
|
14
|
+
* A helper function that converts a UUID to a valid machine ID.
|
|
15
|
+
*
|
|
16
|
+
* @param uuid The UUID that should be converted to a valid machine ID
|
|
17
|
+
* @returns {number} The converted machine ID
|
|
18
|
+
*/
|
|
19
|
+
export declare const toID: (uuid: string) => number;
|
|
20
|
+
/**
|
|
21
|
+
* A helper function that converts a list of UUID to a list of valid machine IDs.
|
|
22
|
+
* NOTE that NaN will be removed so list cannot be expected to be of same size.
|
|
23
|
+
*
|
|
24
|
+
* @param uuid The list of UUIDs that should be converted to a list of valid machine IDs
|
|
25
|
+
*/
|
|
26
|
+
export declare const toIDs: (ids: string[] | null | undefined) => number[];
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from "./DateTimeFormat";
|
|
2
|
+
export * from "./DateUtils";
|
|
3
|
+
export * from "./GeoJsonUtils";
|
|
4
|
+
export * from "./TimePeriod";
|
|
5
|
+
export * from "./UnitOfMeasurementConverter";
|
|
6
|
+
export * from "./addressUtils";
|
|
7
|
+
export * from "./arrayUtils";
|
|
8
|
+
export * from "./chameleonUtils";
|
|
9
|
+
export * from "./constants";
|
|
10
|
+
export * from "./dimensionHelpers";
|
|
11
|
+
export * from "./doNothing";
|
|
12
|
+
export * from "./enumUtils";
|
|
13
|
+
export * from "./exhaustiveCheck";
|
|
14
|
+
export * from "./fastArrayOperations";
|
|
15
|
+
export * from "./filter";
|
|
16
|
+
export * from "./groupBy/groupBy";
|
|
17
|
+
export * from "./idUtils";
|
|
18
|
+
export * from "./maybe";
|
|
19
|
+
export * from "./objectUtils";
|
|
20
|
+
export * from "./pathUtils";
|
|
21
|
+
export * from "./pictureUtils/pictureUtils";
|
|
22
|
+
export * from "./sorting/sorting";
|
|
23
|
+
export * from "./stringUtils";
|
|
24
|
+
export * from "./timePeriodConverter/timePeriodConverter";
|
|
25
|
+
export * from "./typeUtils";
|
package/src/maybe.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes all undefined keys from an object.
|
|
3
|
+
*
|
|
4
|
+
* @param obj The object to delete undefined keys from.
|
|
5
|
+
* @returns The object without undefined keys.
|
|
6
|
+
* @example deleteUndefinedKeys({ a: 1, b: undefined }) // { a: 1 }
|
|
7
|
+
*/
|
|
8
|
+
export declare const deleteUndefinedKeys: <T extends Record<string, unknown>>(obj: T) => T;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param path the path to manipulate
|
|
3
|
+
* @param apiHost the api host to remove from the path
|
|
4
|
+
* @returns {string} the updated path or empty string if null or undefined is passed in
|
|
5
|
+
* @example trimPath("https://api.example.com/api/v1/asset/123") // "asset/<...>"
|
|
6
|
+
* @example trimPath("https://api.example.com/api/v1/asset/123?test=true") // "asset/<...>"
|
|
7
|
+
* @example trimPath("https://api.example.com/api/v1/asset/123?test=true", "https://api.example.com/api/v1") // "asset/<...>"
|
|
8
|
+
* @example trimPath("https://api.example.com/api/v1/asset/123?test=true", "https://api.example.com/api/v1/") // "asset/<...>"
|
|
9
|
+
*/
|
|
10
|
+
export declare const trimPath: (path: string, apiHost?: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Removes UUIDs and numbers from a string and replaces them with <...>
|
|
13
|
+
*
|
|
14
|
+
* @param str the string to manipulate and remove UUIDs and replace with <...> also if path with number like asset/123/gnyf will return asset/<...>/gnyf
|
|
15
|
+
* @returns {string } the updated string or empty string if null or undefined is passed in
|
|
16
|
+
* @example trimIds("asset/123") // "asset/<...>"
|
|
17
|
+
*/
|
|
18
|
+
export declare const trimIds: (str: string | null | undefined) => string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface IResizeImageOptions {
|
|
2
|
+
maxSize: number;
|
|
3
|
+
file: File;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Resize a blob to be no larger than the max parameters, while maintaining the aspect ratio
|
|
7
|
+
*
|
|
8
|
+
* @param blob The blob to resize
|
|
9
|
+
* @param newWidth The max width of the resized blob
|
|
10
|
+
* @param newHeight The max height of the resized blob
|
|
11
|
+
* @returns {Promise<Blob>} A promise that resolves to the resized blob
|
|
12
|
+
* @example resizeBlob(blob, 100, 100).then(resizedBlob => { ... })
|
|
13
|
+
*/
|
|
14
|
+
export declare const resizeBlob: (blob: Blob, newWidth: number, newHeight: number) => Promise<Blob>;
|
|
15
|
+
/**
|
|
16
|
+
* Resize width and height to be contained within the max parameters, while maintaining the aspect ratio
|
|
17
|
+
*/
|
|
18
|
+
export declare const getResizedDimensions: (width: number, height: number, maxWidth: number, maxHeight: number) => {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resize an image to be no larger than the maxSize on each dimension
|
|
24
|
+
*/
|
|
25
|
+
export declare const resizeImage: (settings: IResizeImageOptions) => Promise<Blob>;
|
|
26
|
+
/**
|
|
27
|
+
* Convert a blob to a base64 string
|
|
28
|
+
*
|
|
29
|
+
* @param blob The blob to convert
|
|
30
|
+
* @returns {Promise<string>} A promise that resolves to the base64 string
|
|
31
|
+
* @example convertBlobToBase64(blob).then(base64 => { ... })
|
|
32
|
+
*/
|
|
33
|
+
export declare const convertBlobToBase64: (blob: Blob) => Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Check if the given file is a valid image format
|
|
36
|
+
*
|
|
37
|
+
* @param file The file to check
|
|
38
|
+
* @returns {boolean} True if the file is a valid image format
|
|
39
|
+
* @example isValidImage(file) // true
|
|
40
|
+
*/
|
|
41
|
+
export declare const isValidImage: (file: File) => boolean;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Maybe } from "../maybe";
|
|
2
|
+
/**
|
|
3
|
+
* Compare two strings
|
|
4
|
+
*
|
|
5
|
+
* @param a First string
|
|
6
|
+
* @param b Second string
|
|
7
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
8
|
+
* @example stringCompare("a", "b") // -1
|
|
9
|
+
*/
|
|
10
|
+
export declare const stringCompare: (a: Maybe<string>, b: Maybe<string>) => number;
|
|
11
|
+
/**
|
|
12
|
+
* Compare two strings
|
|
13
|
+
*
|
|
14
|
+
* @param a First string
|
|
15
|
+
* @param b Second string
|
|
16
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
17
|
+
* @example stringCompare("a", "b") // -1
|
|
18
|
+
*/
|
|
19
|
+
export declare const stringNaturalCompare: (a: Maybe<string>, b: Maybe<string>) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Compare two strings
|
|
22
|
+
*
|
|
23
|
+
* @param key The key of the object to compare
|
|
24
|
+
* @example stringCompareFromKey("a", "b") // -1
|
|
25
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
26
|
+
* @example stringCompare("a", "b") // -1
|
|
27
|
+
* @example stringCompareFromKey("a", "b") // -1
|
|
28
|
+
*/
|
|
29
|
+
export declare const stringCompareFromKey: <T>(key: keyof T) => (a: T, b: T) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Compare two dates
|
|
32
|
+
*
|
|
33
|
+
* @param a First date
|
|
34
|
+
* @param b Second date
|
|
35
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
36
|
+
* @example dateCompare(new Date("2021-05-19T12:34:56"), new Date("2021-05-19T12:34:57")) // -1
|
|
37
|
+
* @example dateCompare(new Date("2021-05-19T12:34:56"), new Date("2021-05-19T12:34:56")) // 0
|
|
38
|
+
* @example dateCompare(new Date("2021-05-19T12:34:57"), new Date("2021-05-19T12:34:56")) // 1
|
|
39
|
+
*/
|
|
40
|
+
export declare const dateCompare: (a: Maybe<Date>, b: Maybe<Date>) => number;
|
|
41
|
+
/**
|
|
42
|
+
* Compare two numbers
|
|
43
|
+
*
|
|
44
|
+
* @param a First number
|
|
45
|
+
* @param b Second number
|
|
46
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
47
|
+
* @example numberCompare(1, 2) // -1
|
|
48
|
+
* @example numberCompare(1, 1) // 0
|
|
49
|
+
* @example numberCompare(2, 1) // 1
|
|
50
|
+
*/
|
|
51
|
+
export declare const numberCompare: (a: Maybe<number>, b: Maybe<number>) => number;
|
|
52
|
+
/**
|
|
53
|
+
* Compare two numbers
|
|
54
|
+
*
|
|
55
|
+
* @param a First number
|
|
56
|
+
* @param b Second number
|
|
57
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
58
|
+
* @example numberCompare(1, 2) // -1
|
|
59
|
+
* @example numberCompare(1, 1) // 0
|
|
60
|
+
* @example numberCompare(2, 1) // 1
|
|
61
|
+
*/
|
|
62
|
+
export declare const numberCompareUnknownAfterHighest: (a: Maybe<number>, b: Maybe<number>) => number;
|
|
63
|
+
/**
|
|
64
|
+
* Compare two arrays
|
|
65
|
+
*
|
|
66
|
+
* @param a First array
|
|
67
|
+
* @param b Second array
|
|
68
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
69
|
+
* @example arrayCompare([1, 2], [1, 3], numberCompare) // -1
|
|
70
|
+
* @example arrayCompare([1, 2], [1, 2], numberCompare) // 0
|
|
71
|
+
* @example arrayCompare([1, 3], [1, 2], numberCompare) // 1
|
|
72
|
+
*/
|
|
73
|
+
export declare const arrayLengthCompare: <T>(a: Maybe<T[]>, b: Maybe<T[]>) => number;
|
|
74
|
+
/**
|
|
75
|
+
* Compare two booleans
|
|
76
|
+
*
|
|
77
|
+
* @param a First boolean
|
|
78
|
+
* @param b Second boolean
|
|
79
|
+
* @returns {number} 0 if equal, -1 if a < b, 1 if a > b
|
|
80
|
+
* @example booleanCompare(true, false) // -1
|
|
81
|
+
* @example booleanCompare(true, true) // 0
|
|
82
|
+
* @example booleanCompare(false, true) // 1
|
|
83
|
+
*/
|
|
84
|
+
export declare const booleanCompare: (a: Maybe<boolean>, b: Maybe<boolean>) => number;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of a string
|
|
3
|
+
*
|
|
4
|
+
* @param s The string to capitalize
|
|
5
|
+
* @returns {string} The capitalized string
|
|
6
|
+
* @example capitalize("test") // "Test"
|
|
7
|
+
* @example capitalize("Test") // "Test"
|
|
8
|
+
* @example capitalize("test test") // "Test test"
|
|
9
|
+
* @example capitalize("test-test") // "Test-test"
|
|
10
|
+
*/
|
|
11
|
+
export declare const capitalize: (s: string | null | undefined) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Capitalizes the first letter. All other letters are converted to lowercase.
|
|
14
|
+
*
|
|
15
|
+
* @param s The string to capitalize
|
|
16
|
+
* @returns {string} The capitalized string
|
|
17
|
+
* @example titleCase("test") // "Test"
|
|
18
|
+
* @example titleCase("Test") // "Test"
|
|
19
|
+
* @example titleCase("test TeSt") // "Test test"
|
|
20
|
+
*/
|
|
21
|
+
export declare const titleCase: (s: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a string removing left padding and dashes
|
|
24
|
+
*
|
|
25
|
+
* @param id The id to convert
|
|
26
|
+
* @returns {number} The converted id
|
|
27
|
+
* @example removeLeftPadding("00000000-0000-0000-0000-000000000001") // 1
|
|
28
|
+
* @example removeLeftPadding("00000000-0000-0000-0000-000000000010") // 10
|
|
29
|
+
*/
|
|
30
|
+
export declare const removeLeftPadding: (id: string) => number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TimePeriod } from "../TimePeriod";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a time period to a list of daily intervals
|
|
4
|
+
*
|
|
5
|
+
* @param period The time period to convert
|
|
6
|
+
* @returns {Array<{ from: Date; to: Date }>} A list of daily intervals
|
|
7
|
+
* @example toDailyIntervals(TimePeriod.THIS_MONTH) // [{ from: "2021-05-01T00:00:00.000Z", to: "2021-05-31T23:59:59.999Z" }]
|
|
8
|
+
*/
|
|
9
|
+
export declare function toDailyIntervals(period: TimePeriod): {
|
|
10
|
+
from: Date;
|
|
11
|
+
to: Date;
|
|
12
|
+
}[];
|
|
13
|
+
/**
|
|
14
|
+
* Converts a time period to an interval
|
|
15
|
+
*
|
|
16
|
+
* @param period The time period to convert
|
|
17
|
+
* @returns {{ from: Date; to: Date }} An interval
|
|
18
|
+
* @example toInterval(TimePeriod.THIS_MONTH) // { from: "2021-05-01T00:00:00.000Z", to: "2021-05-31T23:59:59.999Z" }
|
|
19
|
+
*/
|
|
20
|
+
export declare function toInterval(period: TimePeriod): {
|
|
21
|
+
from: Date;
|
|
22
|
+
to: Date;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Converts a time period to a list of months
|
|
26
|
+
*
|
|
27
|
+
* @param period The time period to convert
|
|
28
|
+
* @returns {Array<{ year: number; month: number }>} A list of months
|
|
29
|
+
* @example toMonths(TimePeriod.THIS_MONTH) // [{ year: 2021, month: 5 }]
|
|
30
|
+
*/
|
|
31
|
+
export declare function toDates(period: TimePeriod): {
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infer the element type from the array type
|
|
3
|
+
*
|
|
4
|
+
* Use case:
|
|
5
|
+
* You have a GraphQL payload that returns an array of assets with a specific signature
|
|
6
|
+
* and wish be specific instead of just using Partial<Asset> as input for a component
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* interface SomeInterface {
|
|
10
|
+
* asset: ArrayElement<SomeAssetsQueryQuery["assets"]["payload"]>;
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
|
|
15
|
+
/**
|
|
16
|
+
* Use with filter() to remove null and undefined from an array
|
|
17
|
+
*
|
|
18
|
+
* Example:
|
|
19
|
+
* [1, 2, 0, null].filter(nonNullable) // number[]
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare const nonNullable: <T>(value: T) => value is NonNullable<T>;
|
|
23
|
+
type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T;
|
|
24
|
+
/**
|
|
25
|
+
* Use with filter() to remove not-truthy items from an array
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
* [1, 2, 0, null].filter(truthy) // number[]
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export declare const truthy: <T>(value: T) => value is Truthy<T>;
|
|
32
|
+
export {};
|