Skip to content

Commit

Permalink
Add jsdoc to packages
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Sep 24, 2023
1 parent 7ba4264 commit 8ab26df
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 95 additions & 1 deletion packages/bookcars-helper/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<T>(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;
98 changes: 96 additions & 2 deletions packages/bookcars-helper/index.js
Original file line number Diff line number Diff line change
@@ -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('.');
Expand All @@ -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';
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Loading

0 comments on commit 8ab26df

Please sign in to comment.