forked from simrail/simrail.pro
fix functions.ts merge
This commit is contained in:
parent
36bdfef25a
commit
9c84989063
7
.idea/jsLibraryMappings.xml
generated
7
.idea/jsLibraryMappings.xml
generated
@ -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>
|
@ -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();
|
Loading…
x
Reference in New Issue
Block a user