everyday-helper 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -262,6 +262,8 @@ declare function useEventListener<K extends keyof WindowEventMap>(event: K, hand
262
262
 
263
263
  declare const useResizeListener: (callback: () => void, active: boolean) => void;
264
264
 
265
+ declare function useKeyPress(targetKey: string): boolean;
266
+
265
267
  declare const isBrowser: () => boolean;
266
268
  declare const safeWindow: () => (Window & typeof globalThis) | undefined;
267
269
 
@@ -1249,4 +1251,4 @@ declare const bounceIn: (order?: number, className?: string, style?: CSSProperti
1249
1251
  style: CSSProperties;
1250
1252
  };
1251
1253
 
1252
- export { type ClassValue, CookieManager, DateFormats, type DateInput, FormDataBuilder, type PrintStyle, addAsteriskIf, addToDate, animate, areAllValuesComplete, average, bounceIn, capitalize, capitalizeWords, checkArrEquality, chunk, cleanObject, clone, cn, compactArr, compactStr, compareDates, compose, concatIf, constant, convertBase64ToFile, convertFileToBase64, count, countOccurrences, createFormData, createStorage, curry, debounce, deepClone, deepFreeze, deepMerge, delay, difference, endOf, endsWith, entries, eqIgnoreCase, extractBase64FromDataUrl, fadeIn, fileToArrayBuffer, filterObject, first, firstSeveral, flatten, flattenDeep, flip, formatDate, formatDateRange, formatRelativeTime, fromPairs, generateQuery, get, getAge, getDateDifference, getEndpoint, getImageUrl, groupBy, has, hasAzerbaijanCountryCode, identity, includesIgnoreCase, intersection, invert, isBetweenDates, isBrowser, isEmpty, isEqual, isFuture, isLoggedIn, isNotEmpty, isNulOrUndefined, isObject, isPast, isSameDay, isString, isStringSimilar, isToday, isTomorrow, isValidDate, isYesterday, keys, last, lastSeveral, lazyLoad, local, mapKeys, mapValues, max, memoize, merge, min, negate, noop, normalizePhone, normalizeWhitespace, now, omit, once, padEnd, padStart, parseDate, partial, partition, pick, pushIf, rateLimit, reject, repeat, retry, reverse, reverseArr, safeCall, safeWindow, sample, sampleSize, scaleIn, session, set, shuffle, slideInDown, slideInLeft, slideInRight, slideInUp, slugify, sortBy, startOf, startsWith, subtractFromDate, sum, throttle, timeId, tinyId, toCamelCase, toISOString, toKebabCase, toPascalCase, toSnakeCase, toUnixTimestamp, toUpperSnakeCase, trim, trimEnd, trimStart, truncate, tryCatch, tryCatchAsync, unflatten, union, unique, uniqueBy, useAppLocation, useDebounce, useDownloadFile, useEscapeKey, useEventListener, useInterval, useMediaQuery, useMount, useOnlineStatus, useOutsideClick, usePortal, usePrevious, usePrint, useResizeListener, useScrollLock, useToggle, useUnmount, useUpdateEffect, useWindowSize, values, withAzerbaijanCountryCode, without, zip };
1254
+ export { type ClassValue, CookieManager, DateFormats, type DateInput, FormDataBuilder, type PrintStyle, addAsteriskIf, addToDate, animate, areAllValuesComplete, average, bounceIn, capitalize, capitalizeWords, checkArrEquality, chunk, cleanObject, clone, cn, compactArr, compactStr, compareDates, compose, concatIf, constant, convertBase64ToFile, convertFileToBase64, count, countOccurrences, createFormData, createStorage, curry, debounce, deepClone, deepFreeze, deepMerge, delay, difference, endOf, endsWith, entries, eqIgnoreCase, extractBase64FromDataUrl, fadeIn, fileToArrayBuffer, filterObject, first, firstSeveral, flatten, flattenDeep, flip, formatDate, formatDateRange, formatRelativeTime, fromPairs, generateQuery, get, getAge, getDateDifference, getEndpoint, getImageUrl, groupBy, has, hasAzerbaijanCountryCode, identity, includesIgnoreCase, intersection, invert, isBetweenDates, isBrowser, isEmpty, isEqual, isFuture, isLoggedIn, isNotEmpty, isNulOrUndefined, isObject, isPast, isSameDay, isString, isStringSimilar, isToday, isTomorrow, isValidDate, isYesterday, keys, last, lastSeveral, lazyLoad, local, mapKeys, mapValues, max, memoize, merge, min, negate, noop, normalizePhone, normalizeWhitespace, now, omit, once, padEnd, padStart, parseDate, partial, partition, pick, pushIf, rateLimit, reject, repeat, retry, reverse, reverseArr, safeCall, safeWindow, sample, sampleSize, scaleIn, session, set, shuffle, slideInDown, slideInLeft, slideInRight, slideInUp, slugify, sortBy, startOf, startsWith, subtractFromDate, sum, throttle, timeId, tinyId, toCamelCase, toISOString, toKebabCase, toPascalCase, toSnakeCase, toUnixTimestamp, toUpperSnakeCase, trim, trimEnd, trimStart, truncate, tryCatch, tryCatchAsync, unflatten, union, unique, uniqueBy, useAppLocation, useDebounce, useDownloadFile, useEscapeKey, useEventListener, useInterval, useKeyPress, useMediaQuery, useMount, useOnlineStatus, useOutsideClick, usePortal, usePrevious, usePrint, useResizeListener, useScrollLock, useToggle, useUnmount, useUpdateEffect, useWindowSize, values, withAzerbaijanCountryCode, without, zip };
package/dist/index.js CHANGED
@@ -754,6 +754,21 @@ var useResizeListener = (callback, active) => {
754
754
  // src/hooks/useCopyToClipboard.ts
755
755
  import { useState as useState5 } from "react";
756
756
 
757
+ // src/hooks/useKeyPress.ts
758
+ import { useCallback as useCallback4, useState as useState6 } from "react";
759
+ function useKeyPress(targetKey) {
760
+ const [pressed, setPressed] = useState6(false);
761
+ const downHandler = useCallback4((e) => {
762
+ if (e.key === targetKey) setPressed(true);
763
+ }, [targetKey]);
764
+ const upHandler = useCallback4((e) => {
765
+ if (e.key === targetKey) setPressed(false);
766
+ }, [targetKey]);
767
+ useEventListener("keydown", downHandler);
768
+ useEventListener("keyup", upHandler);
769
+ return pressed;
770
+ }
771
+
757
772
  // src/utils/common-utils.ts
758
773
  function isNulOrUndefined(v) {
759
774
  return v === null || v === void 0;
@@ -827,16 +842,24 @@ var pad = (n) => String(n).padStart(2, "0");
827
842
  var formatDate = (date, format = "DD MMM YYYY" /* DD_MMM_YYYY_WITH_SPACE */) => {
828
843
  const d = toDate(date);
829
844
  if (!d) return void 0;
830
- const formatter = new Intl.DateTimeFormat("en-GB", {
831
- day: "2-digit",
832
- month: "short",
833
- year: "numeric"
834
- });
835
845
  if (format === "DD MMM YYYY" /* DD_MMM_YYYY_WITH_SPACE */) {
836
- const str = formatter.format(d);
837
- return str.replace(",", "");
846
+ return new Intl.DateTimeFormat("en-GB", {
847
+ day: "2-digit",
848
+ month: "short",
849
+ year: "numeric"
850
+ }).format(d).replace(",", "");
838
851
  }
839
- return format.replace("YYYY", d.getFullYear().toString()).replace("MM", pad(d.getMonth() + 1)).replace("DD", pad(d.getDate()));
852
+ const tokens = {
853
+ YYYY: d.getFullYear().toString(),
854
+ MM: pad(d.getMonth() + 1),
855
+ DD: pad(d.getDate()),
856
+ HH: pad(d.getHours()),
857
+ mm: pad(d.getMinutes())
858
+ };
859
+ return Object.entries(tokens).reduce(
860
+ (acc, [token, value]) => acc.replace(new RegExp(token, "g"), value),
861
+ format
862
+ );
840
863
  };
841
864
  var formatRelativeTime = (date, baseDate) => {
842
865
  const d = toDate(date);
@@ -844,14 +867,11 @@ var formatRelativeTime = (date, baseDate) => {
844
867
  if (!d) return void 0;
845
868
  const diff = d.getTime() - base.getTime();
846
869
  const abs = Math.abs(diff);
847
- if (abs < 6e4)
848
- return diff < 0 ? "seconds ago" : "in seconds";
870
+ if (abs < 6e4) return diff < 0 ? "seconds ago" : "in seconds";
849
871
  const minutes = Math.round(abs / 6e4);
850
- if (minutes < 60)
851
- return diff < 0 ? `${minutes} minutes ago` : `in ${minutes} minutes`;
872
+ if (minutes < 60) return diff < 0 ? `${minutes} minutes ago` : `in ${minutes} minutes`;
852
873
  const hours = Math.round(abs / 36e5);
853
- if (hours < 24)
854
- return diff < 0 ? `${hours} hours ago` : `in ${hours} hours`;
874
+ if (hours < 24) return diff < 0 ? `${hours} hours ago` : `in ${hours} hours`;
855
875
  const days = Math.round(abs / 864e5);
856
876
  return diff < 0 ? `${days} days ago` : `in ${days} days`;
857
877
  };
@@ -1849,6 +1869,7 @@ export {
1849
1869
  useEscapeKey,
1850
1870
  useEventListener,
1851
1871
  useInterval,
1872
+ useKeyPress,
1852
1873
  useMediaQuery,
1853
1874
  useMount,
1854
1875
  useOnlineStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "everyday-helper",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A lightweight collection of React hooks, utility functions, and helpers for modern React development",
5
5
  "license": "MIT",
6
6
  "type": "module",