diff --git a/backend/package-lock.json b/backend/package-lock.json index 921fb28e6..b78e7fa40 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,12 +1,12 @@ { "name": "backend", - "version": "1.7.0", + "version": "1.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "backend", - "version": "1.7.0", + "version": "1.8.0", "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 52ab03e83..03b74c7fa 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "frontend", - "version": "1.7.0", + "version": "1.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "frontend", - "version": "1.7.0", + "version": "1.8.0", "dependencies": { "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", diff --git a/packages/bookcars-helper/index.d.ts b/packages/bookcars-helper/index.d.ts index 9ca8bdd8e..25cd28708 100644 --- a/packages/bookcars-helper/index.d.ts +++ b/packages/bookcars-helper/index.d.ts @@ -1,15 +1,109 @@ import * as bookcarsTypes from 'bookcars-types'; +/** + * Format a number. + * + * @export + * @param {?number} [x] + * @returns {string} + */ export declare function formatNumber(x?: number): string; +/** + * Format a Date number to two digits. + * + * @export + * @param {number} n + * @returns {string} + */ export declare function formatDatePart(n: number): string; +/** + * Capitalize a string. + * + * @export + * @param {string} str + * @returns {string} + */ export declare function capitalize(str: string): string; -export declare function isDate(date?: Date): boolean; +/** + * Check if a value is a Date. + * + * @export + * @param {?*} [value] + * @returns {boolean} + */ +export declare function isDate(value?: any): boolean; +/** + * Join two url parts. + * + * @param {?string} [part1] + * @param {?string} [part2] + * @returns {string} + */ export declare const joinURL: (part1?: string, part2?: string) => string; +/** + * Check if a string is an integer. + * + * @param {string} val + * @returns {boolean} + */ export declare const isInteger: (val: string) => boolean; +/** + * Check if a string is a year. + * + * @param {string} val + * @returns {boolean} + */ export declare const isYear: (val: string) => boolean; +/** + * Check if a string is a CVV. + * + * @param {string} val + * @returns {boolean} + */ export declare const isCvv: (val: string) => boolean; +/** + * Check if two arrays are equal. + * + * @param {*} a + * @param {*} b + * @returns {boolean} + */ export declare const arrayEqual: (a: any, b: any) => boolean; +/** + * Clone an object or array. + * + * @param {*} obj + * @returns {*} + */ export declare const clone: (obj: any) => any; +/** + * Clone an array. + * + * @export + * @template T + * @param {T[]} arr + * @returns {(T[] | undefined | null)} + */ export declare function cloneArray(arr: T[]): T[] | undefined | null; +/** + * Check if two filters are equal. + * + * @param {?(bookcarsTypes.Filter | null)} [a] + * @param {?(bookcarsTypes.Filter | null)} [b] + * @returns {boolean} + */ export declare const filterEqual: (a?: bookcarsTypes.Filter | null, b?: bookcarsTypes.Filter | null) => boolean; +/** + * Flatten Supplier array. + * + * @param {bookcarsTypes.User[]} companies + * @returns {string[]} + */ export declare const flattenCompanies: (companies: bookcarsTypes.User[]) => string[]; +/** + * Get number of days between two dates. + * + * @param {?Date} [from] + * @param {?Date} [to] + * @returns {*} + */ export declare const days: (from?: Date, to?: Date) => number; diff --git a/packages/bookcars-helper/index.js b/packages/bookcars-helper/index.js index efbe6c784..f98b0d702 100644 --- a/packages/bookcars-helper/index.js +++ b/packages/bookcars-helper/index.js @@ -1,3 +1,10 @@ +/** + * Format a number. + * + * @export + * @param {?number} [x] + * @returns {string} + */ export function formatNumber(x) { if (typeof x === 'number') { const parts = String(x % 1 !== 0 ? x.toFixed(2) : x).split('.'); @@ -6,15 +13,43 @@ export function formatNumber(x) { } return ''; } +/** + * Format a Date number to two digits. + * + * @export + * @param {number} n + * @returns {string} + */ export function formatDatePart(n) { return n > 9 ? String(n) : '0' + n; } +/** + * Capitalize a string. + * + * @export + * @param {string} str + * @returns {string} + */ export function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } -export function isDate(date) { - return date instanceof Date && !isNaN(date.valueOf()); +/** + * Check if a value is a Date. + * + * @export + * @param {?*} [value] + * @returns {boolean} + */ +export function isDate(value) { + return value instanceof Date && !isNaN(value.valueOf()); } +/** + * Join two url parts. + * + * @param {?string} [part1] + * @param {?string} [part2] + * @returns {string} + */ export const joinURL = (part1, part2) => { if (!part1 || !part2) { const msg = '[joinURL] part undefined'; @@ -29,15 +64,40 @@ export const joinURL = (part1, part2) => { } return part1 + '/' + part2; }; +/** + * Check if a string is an integer. + * + * @param {string} val + * @returns {boolean} + */ export const isInteger = (val) => { return /^\d+$/.test(val); }; +/** + * Check if a string is a year. + * + * @param {string} val + * @returns {boolean} + */ export const isYear = (val) => { return /^\d{2}$/.test(val); }; +/** + * Check if a string is a CVV. + * + * @param {string} val + * @returns {boolean} + */ export const isCvv = (val) => { return /^\d{3,4}$/.test(val); }; +/** + * Check if two arrays are equal. + * + * @param {*} a + * @param {*} b + * @returns {boolean} + */ export const arrayEqual = (a, b) => { if (a === b) { return true; @@ -59,9 +119,23 @@ export const arrayEqual = (a, b) => { } return true; }; +/** + * Clone an object or array. + * + * @param {*} obj + * @returns {*} + */ export const clone = (obj) => { return Array.isArray(obj) ? Array.from(obj) : Object.assign({}, obj); }; +/** + * Clone an array. + * + * @export + * @template T + * @param {T[]} arr + * @returns {(T[] | undefined | null)} + */ export function cloneArray(arr) { if (typeof arr === 'undefined') { return undefined; @@ -71,6 +145,13 @@ export function cloneArray(arr) { } return [...arr]; } +/** + * Check if two filters are equal. + * + * @param {?(bookcarsTypes.Filter | null)} [a] + * @param {?(bookcarsTypes.Filter | null)} [b] + * @returns {boolean} + */ export const filterEqual = (a, b) => { if (a === b) { return true; @@ -95,5 +176,18 @@ export const filterEqual = (a, b) => { } return true; }; +/** + * Flatten Supplier array. + * + * @param {bookcarsTypes.User[]} companies + * @returns {string[]} + */ export const flattenCompanies = (companies) => companies.map((company) => company._id ?? ''); +/** + * Get number of days between two dates. + * + * @param {?Date} [from] + * @param {?Date} [to] + * @returns {*} + */ export const days = (from, to) => (from && to && Math.ceil((to.getTime() - from.getTime()) / (1000 * 3600 * 24))) || 0; diff --git a/packages/bookcars-helper/index.ts b/packages/bookcars-helper/index.ts index b352db015..7ce11f1c0 100644 --- a/packages/bookcars-helper/index.ts +++ b/packages/bookcars-helper/index.ts @@ -1,5 +1,12 @@ import * as bookcarsTypes from 'bookcars-types' +/** + * Format a number. + * + * @export + * @param {?number} [x] + * @returns {string} + */ export function formatNumber(x?: number): string { if (typeof x === 'number') { const parts: string[] = String(x % 1 !== 0 ? x.toFixed(2) : x).split('.') @@ -9,18 +16,46 @@ export function formatNumber(x?: number): string { return '' } +/** + * Format a Date number to two digits. + * + * @export + * @param {number} n + * @returns {string} + */ export function formatDatePart(n: number): string { return n > 9 ? String(n) : '0' + n } +/** + * Capitalize a string. + * + * @export + * @param {string} str + * @returns {string} + */ export function capitalize(str: string): string { return str.charAt(0).toUpperCase() + str.slice(1) } -export function isDate(date?: Date): boolean { - return date instanceof Date && !isNaN(date.valueOf()) +/** + * Check if a value is a Date. + * + * @export + * @param {?*} [value] + * @returns {boolean} + */ +export function isDate(value?: any): boolean { + return value instanceof Date && !isNaN(value.valueOf()) } +/** + * Join two url parts. + * + * @param {?string} [part1] + * @param {?string} [part2] + * @returns {string} + */ export const joinURL = (part1?: string, part2?: string) => { if (!part1 || !part2) { const msg = '[joinURL] part undefined' @@ -37,18 +72,43 @@ export const joinURL = (part1?: string, part2?: string) => { return part1 + '/' + part2 } +/** + * Check if a string is an integer. + * + * @param {string} val + * @returns {boolean} + */ export const isInteger = (val: string) => { return /^\d+$/.test(val) } +/** + * Check if a string is a year. + * + * @param {string} val + * @returns {boolean} + */ export const isYear = (val: string) => { return /^\d{2}$/.test(val) } +/** + * Check if a string is a CVV. + * + * @param {string} val + * @returns {boolean} + */ export const isCvv = (val: string) => { return /^\d{3,4}$/.test(val) } +/** + * Check if two arrays are equal. + * + * @param {*} a + * @param {*} b + * @returns {boolean} + */ export const arrayEqual = (a: any, b: any) => { if (a === b) { return true @@ -73,10 +133,24 @@ export const arrayEqual = (a: any, b: any) => { return true } +/** + * Clone an object or array. + * + * @param {*} obj + * @returns {*} + */ export const clone = (obj: any) => { return Array.isArray(obj) ? Array.from(obj) : Object.assign({}, obj) } +/** + * Clone an array. + * + * @export + * @template T + * @param {T[]} arr + * @returns {(T[] | undefined | null)} + */ export function cloneArray(arr: T[]): T[] | undefined | null { if (typeof arr === 'undefined') { return undefined @@ -87,6 +161,13 @@ export function cloneArray(arr: T[]): T[] | undefined | null { return [...arr] } +/** + * Check if two filters are equal. + * + * @param {?(bookcarsTypes.Filter | null)} [a] + * @param {?(bookcarsTypes.Filter | null)} [b] + * @returns {boolean} + */ export const filterEqual = (a?: bookcarsTypes.Filter | null, b?: bookcarsTypes.Filter | null) => { if (a === b) { return true @@ -114,8 +195,21 @@ export const filterEqual = (a?: bookcarsTypes.Filter | null, b?: bookcarsTypes.F return true } +/** + * Flatten Supplier array. + * + * @param {bookcarsTypes.User[]} companies + * @returns {string[]} + */ export const flattenCompanies = (companies: bookcarsTypes.User[]): string[] => companies.map((company) => company._id ?? '') +/** + * Get number of days between two dates. + * + * @param {?Date} [from] + * @param {?Date} [to] + * @returns {*} + */ export const days = (from?: Date, to?: Date) => (from && to && Math.ceil((to.getTime() - from.getTime()) / (1000 * 3600 * 24))) || 0 diff --git a/packages/disable-react-devtools/index.d.ts b/packages/disable-react-devtools/index.d.ts index c85ee96a9..03932c5c3 100644 --- a/packages/disable-react-devtools/index.d.ts +++ b/packages/disable-react-devtools/index.d.ts @@ -3,4 +3,9 @@ declare global { __REACT_DEVTOOLS_GLOBAL_HOOK__?: Record | (() => any)>; } } +/** + * Disable React Developer Tools. + * + * @export + */ export declare function disableDevTools(): void; diff --git a/packages/disable-react-devtools/index.js b/packages/disable-react-devtools/index.js index 215c7a9a1..9e1b23a2d 100644 --- a/packages/disable-react-devtools/index.js +++ b/packages/disable-react-devtools/index.js @@ -1,3 +1,8 @@ +/** + * Disable React Developer Tools. + * + * @export + */ export function disableDevTools() { if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) return; diff --git a/packages/disable-react-devtools/index.ts b/packages/disable-react-devtools/index.ts index 89f2e29cd..56e9ff67d 100644 --- a/packages/disable-react-devtools/index.ts +++ b/packages/disable-react-devtools/index.ts @@ -7,6 +7,11 @@ declare global { } } +/** + * Disable React Developer Tools. + * + * @export + */ export function disableDevTools(): void { if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) return