mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
fix: build
This commit is contained in:
@@ -12,13 +12,12 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {omitBy, isNil, reject, isEmpty, isArray, isObject} from 'lodash';
|
||||
|
||||
/**
|
||||
* Filters only defined elements
|
||||
*/
|
||||
export function rejectNil<T>(array: Array<T | undefined | null>): T[] {
|
||||
return reject(array, isNil) as T[];
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
return array.filter(it => it == null) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,5 +32,13 @@ export function mapNotNil<T, S>(array: readonly T[], transform: (element: T) =>
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function cleanupEmpty<T extends object>(object: T): T {
|
||||
return omitBy(object, it => isNil(it) || ((isObject(it) || isArray(it)) && isEmpty(it))) as T;
|
||||
const out = {} as T;
|
||||
for (const key in object) {
|
||||
const value = object[key]
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
if (value != null && (typeof value !== 'object' || Object.values(value).length > 0)) {
|
||||
out[key] = value
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {readdirSync, statSync} from 'fs';
|
||||
import {flatMap} from 'lodash';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
@@ -24,9 +23,9 @@ export function expandPathToFilesSync(sourcePath: string, accept: (fileName: str
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
return directory.isDirectory()
|
||||
? flatMap(readdirSync(fullPath), fragment =>
|
||||
? readdirSync(fullPath).flatMap(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
)
|
||||
)
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user