fix functions.ts merge

This commit is contained in:
Aleksander Wilczyński 2024-12-13 20:28:04 +01:00
parent 36bdfef25a
commit 9c84989063
Signed by untrusted user: alekswilc
GPG Key ID: D4464A248E5F27FE
2 changed files with 39 additions and 8 deletions

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$/packages/backend" libraries="{Node.js Core}" />
<file url="file://$PROJECT_DIR$/packages/frontend" libraries="{Node.js Core}" />
</component>
</project>

View File

@ -1,4 +1,42 @@
/*
* Copyright (C) 2024 Aleksander <alekswilc> Wilczyński (aleks@alekswilc.dev)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* See LICENSE for more.
*/
// TODO: typings
export const removeProperties = <T>(data: any, names: string[]) =>
{
for (const name of names)
{
delete data[ name ];
}
return data as T;
};
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
export const escapeRegexString = (str: string) => {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
}
export const isTruthyAndGreaterThanZero = (data: number) => {
if (!data) return false;
return data > 0;
}
export const arrayGroupBy = <T>(array: T[], predicate: (value: T, index: number, array: T[]) => string) =>
Object.values((array.reduce((acc, value, index, array) => {
(acc[predicate(value, index, array)] ||= []).push(value);
return acc;
}, {} as { [key: string]: T[] }))).flat();