@easyappkit/utils
v1.0.0
Published
Common utilities and React hooks for Easy App Kit
Downloads
8
Maintainers
Readme
@easyappkit/utils
Common utilities and React hooks for Easy App Kit.
Installation
npm install @easyappkit/utilsUsage
Validation
import { isEmail, isStrongPassword, isEmpty } from '@easyappkit/utils';
isEmail('[email protected]'); // true
isStrongPassword('Abc12345'); // true
isEmpty(''); // trueFormatting
import { formatDate, formatCurrency, formatFileSize, truncate } from '@easyappkit/utils';
formatDate(new Date(), 'long'); // "December 5, 2025"
formatCurrency(1234.56); // "$1,234.56"
formatFileSize(1024000); // "1000 KB"
truncate('Long text here', 10); // "Long text..."React Hooks
import { useDebounce, useThrottle, useToggle, usePrevious } from '@easyappkit/utils';
// Debounce
function SearchInput() {
const [value, setValue] = useState('');
const debouncedValue = useDebounce(value, 500);
useEffect(() => {
// API call with debouncedValue
}, [debouncedValue]);
}
// Throttle
function ScrollHandler() {
const handleScroll = useThrottle(() => {
console.log('Scrolling...');
}, 1000);
return <ScrollView onScroll={handleScroll} />;
}
// Toggle
function ToggleExample() {
const [isOpen, toggle, setIsOpen] = useToggle(false);
return <Button onPress={toggle}>Toggle</Button>;
}
// Previous value
function Counter() {
const [count, setCount] = useState(0);
const prevCount = usePrevious(count);
return <Text>Current: {count}, Previous: {prevCount}</Text>;
}Helpers
import { sleep, randomId, chunk, unique, groupBy } from '@easyappkit/utils';
await sleep(1000); // Wait 1 second
const id = randomId(); // Generate random ID
const chunks = chunk([1,2,3,4,5], 2); // [[1,2], [3,4], [5]]
const uniqueItems = unique([1,2,2,3]); // [1,2,3]
const grouped = groupBy(
[{ type: 'a', val: 1 }, { type: 'b', val: 2 }],
'type'
); // { a: [...], b: [...] }License
MIT
