Skip to content

Commit

Permalink
feat(utils): Optimize isEmpty function
Browse files Browse the repository at this point in the history
- Created `utils.ts` and added a micro-optimized version of `isEmpty` from 'i18n-mini/lib/utils', which is ~70% faster.
- Updated `DateTime.tsx` and `Numeric.tsx` components to use the new optimized `isEmpty` function.
  • Loading branch information
RoachxD committed Aug 12, 2023
1 parent d7c2f0b commit 7e6316e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/DateTime.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { splitProps } from 'solid-js';
import { isEmpty } from 'i18n-mini/lib/utils';
import type { DateTimeOptions } from 'i18n-mini/lib/types';
import { splitProps } from 'solid-js';
import { useI18n } from '../context';
import { isEmpty } from '../utils';

export interface DateTimeProps extends DateTimeOptions {
date: number | string | Date;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Numeric.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { splitProps, mergeProps } from 'solid-js';
import { isEmpty } from 'i18n-mini/lib/utils';
import type { NumberOptions, NumberStyle } from 'i18n-mini/lib/types';
import { splitProps, mergeProps } from 'solid-js';
import { useI18n } from '../context';
import { isEmpty } from '../utils';

export interface NumericProps extends Omit<NumberOptions, 'style'> {
value: number;
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function isEmpty<T extends object>(value: T): boolean {
for (const prop in value) {
if (value[prop]) {
return false;
}
}

return true;
}

0 comments on commit 7e6316e

Please sign in to comment.