Add vendor creation
Signed-off-by: Bryan Frimin <bryan@getprobo.com> Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
fe3128da2a
commit
c2a69b5428
12
packages/helpers/src/array.test.ts
Normal file
12
packages/helpers/src/array.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { isEmpty } from "./array";
|
||||
|
||||
describe("array", () => {
|
||||
it("should check if an array is empty", () => {
|
||||
expect(isEmpty([])).toBe(true);
|
||||
expect(isEmpty([1, 2, 3])).toBe(false);
|
||||
expect(isEmpty(null)).toBe(true);
|
||||
expect(isEmpty(undefined)).toBe(true);
|
||||
expect(isEmpty([[], false])).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -18,3 +18,13 @@ export function groupBy<T>(
|
||||
{} as Record<string, T[]>,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a value is empty (null, undefined, empty string, empty array, empty object)
|
||||
*/
|
||||
export function isEmpty(v: unknown) {
|
||||
if (Array.isArray(v)) {
|
||||
return v.find((v) => !isEmpty(v)) === undefined;
|
||||
}
|
||||
return !v;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export { objectKeys } from "./object";
|
||||
export { sprintf } from "./string";
|
||||
export { sprintf, faviconUrl } from "./string";
|
||||
export {
|
||||
getTreatment,
|
||||
getRiskImpacts,
|
||||
getRiskLikelihoods,
|
||||
getSeverity,
|
||||
} from "./risk";
|
||||
export { times, groupBy } from "./array";
|
||||
export { times, groupBy, isEmpty } from "./array";
|
||||
export { randomInt } from "./number";
|
||||
|
||||
@@ -7,3 +7,16 @@ export function sprintf(str: string, ...params: unknown[]): string {
|
||||
return params[i++] as string;
|
||||
});
|
||||
}
|
||||
|
||||
export function faviconUrl(url?: string | null): string | null {
|
||||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
return `https://www.google.com/s2/favicons?domain=${parsedUrl.hostname}&sz=64`;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user