release: v4.1.0

This commit is contained in:
Amruth Pillai
2024-05-05 14:55:06 +02:00
parent 68252c35fc
commit e87b05a93a
282 changed files with 11461 additions and 10713 deletions

View File

@ -2,10 +2,10 @@ import { LayoutLocator } from "./types";
// Function to find a specific item in a layout
export const findItemInLayout = (item: string, layout: string[][][]): LayoutLocator | null => {
for (let page = 0; page < layout.length; page++) {
for (let column = 0; column < layout[page].length; column++) {
for (let section = 0; section < layout[page][column].length; section++) {
if (layout[page][column][section] === item) {
for (const [page, element] of layout.entries()) {
for (const [column, element_] of element.entries()) {
for (const [section, element__] of element_.entries()) {
if (element__ === item) {
return { page, column, section };
}
}
@ -46,7 +46,7 @@ export const moveItemInLayout = (
newLayout[target.page][target.column].splice(target.section, 0, item);
return newLayout;
} catch (error) {
} catch {
return layout;
}
};

View File

@ -1,11 +1,7 @@
export const hexToRgb = (hex: string, alpha = 0) => {
const r = parseInt(hex.slice(1, 3), 16),
g = parseInt(hex.slice(3, 5), 16),
b = parseInt(hex.slice(5, 7), 16);
const r = Number.parseInt(hex.slice(1, 3), 16),
g = Number.parseInt(hex.slice(3, 5), 16),
b = Number.parseInt(hex.slice(5, 7), 16);
if (alpha) {
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
} else {
return `rgb(${r}, ${g}, ${b})`;
}
return alpha ? `rgba(${r}, ${g}, ${b}, ${alpha})` : `rgb(${r}, ${g}, ${b})`;
};

View File

@ -7,16 +7,20 @@ export const parseCSV = async (string: string) => {
Papa.parse(string, {
header: true,
skipEmptyLines: true,
complete: (results) => resolve(results.data as Json[]),
error: (error: Error) => reject(error),
complete: (results) => {
resolve(results.data as Json[]);
},
error: (error: Error) => {
reject(error);
},
});
});
};
/**
* Parser for cases when we receive an array like structure f.e. a in the LinkedIn Profile.csv import
* Parser for cases when we receive an array like structure f.e. in the LinkedIn Profile.csv import
* @param csvEntry array-like entry such as [TAG:https://some.link,TAG:https://someother.link]
* @returns
*/
export const parseArrayLikeCSVEntry = (csvEntry: string) =>
csvEntry.replace(/^\[/, "").replace(/$\]/, "").split(",");
csvEntry.replace(/^\[/, "").replace(/$]/, "").split(",");

View File

@ -24,12 +24,10 @@ export const deepSearchAndParseDates = (obj: any, dateKeys: string[]): any => {
for (const key of keys) {
let value = obj[key];
if (dateKeys.includes(key)) {
if (typeof value === "string") {
const parsedDate = new Date(value);
if (!isNaN(parsedDate.getTime())) {
value = parsedDate;
}
if (dateKeys.includes(key) && typeof value === "string") {
const parsedDate = new Date(value);
if (!Number.isNaN(parsedDate.getTime())) {
value = parsedDate;
}
}

View File

@ -3,7 +3,7 @@ export type Font = {
category: string;
subsets: string[];
variants: string[];
files: { [key: string]: string };
files: Record<string, string>;
};
export const fonts: Font[] = [

View File

@ -5,6 +5,6 @@ export const linearTransform = (
outMin: number,
outMax: number,
) => {
if (inMax === inMin) return value === inMax ? outMin : NaN;
if (inMax === inMin) return value === inMax ? outMin : Number.NaN;
return ((value - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
};

View File

@ -3,16 +3,17 @@ import { adjectives, animals, uniqueNamesGenerator } from "unique-names-generato
import { LayoutLocator, SortablePayload } from "./types";
export const getInitials = (name: string) => {
// eslint-disable-next-line unicorn/better-regex
const regex = new RegExp(/(\p{L}{1})\p{L}+/, "gu");
const initials = [...name.matchAll(regex)] || [];
const initials = [...name.matchAll(regex)];
return ((initials.shift()?.[1] || "") + (initials.pop()?.[1] || "")).toUpperCase();
return ((initials.shift()?.[1] ?? "") + (initials.pop()?.[1] ?? "")).toUpperCase();
};
export const isUrl = (string: string | null | undefined) => {
if (!string) return false;
const urlRegex = /https?:\/\/[^ \n]+/i;
const urlRegex = /https?:\/\/[^\n ]+/i;
return urlRegex.test(string);
};
@ -23,7 +24,7 @@ export const isEmptyString = (string: string) => {
};
export const extractUrl = (string: string) => {
const urlRegex = /https?:\/\/[^ \n]+/i;
const urlRegex = /https?:\/\/[^\n ]+/i;
const result = string.match(urlRegex);
return result ? result[0] : null;
@ -34,7 +35,7 @@ export const kebabCase = (string?: string | null) => {
return (
string
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.match(/[A-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z]+\d*|[A-Z]|\d+/g)
?.join("-")
.toLowerCase() ?? ""
);
@ -52,13 +53,13 @@ export const generateRandomName = () => {
export const processUsername = (string?: string | null) => {
if (!string) return "";
return string.replace(/[^a-zA-Z0-9-.]/g, "").toLowerCase();
return string.replace(/[^\d.A-Za-z-]/g, "").toLowerCase();
};
export const parseLayoutLocator = (payload: SortablePayload | null): LayoutLocator => {
if (!payload) return { page: 0, column: 0, section: 0 };
const section = payload.index as number;
const section = payload.index;
const [page, column] = payload.containerId.split(".").map(Number);
return { page, column, section };

View File

@ -42,7 +42,7 @@ describe("linearTransform", () => {
it("returns NaN if input maximum equals input minimum", () => {
const value = 5;
const result = linearTransform(value, 0, 0, 0, 100);
expect(result).toBe(NaN);
expect(result).toBe(Number.NaN);
});
it("returns NaN if input range is zero (avoids division by zero)", () => {

View File

@ -31,7 +31,7 @@ describe("exclude", () => {
age: 30,
email: "alice@example.com",
};
const keysToExclude: Array<keyof TestObject> = [];
const keysToExclude: (keyof TestObject)[] = [];
const result = exclude(object, keysToExclude);
expect(result).toEqual(object);

View File

@ -53,7 +53,7 @@ describe("kebabCase", () => {
describe("generateRandomName", () => {
it("generates a random name", () => {
const name = generateRandomName();
expect(name).toMatch(/^[A-Z][a-z]+ [A-Z][a-z]+ [A-Z][a-z]+$/);
expect(name).toMatch(/^(?:[A-Z][a-z]+ ){2}[A-Z][a-z]+$/);
});
});