@mdigitalcn/utils 2.0.0
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/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/esm/array/checkValueInArray.js +2 -0
- package/dist/esm/array/checkValueInArray.js.map +1 -0
- package/dist/esm/array/chunk.js +2 -0
- package/dist/esm/array/chunk.js.map +1 -0
- package/dist/esm/array/collectBy.js +2 -0
- package/dist/esm/array/collectBy.js.map +1 -0
- package/dist/esm/array/compact.js +2 -0
- package/dist/esm/array/compact.js.map +1 -0
- package/dist/esm/array/countBy.js +2 -0
- package/dist/esm/array/countBy.js.map +1 -0
- package/dist/esm/array/difference.js +2 -0
- package/dist/esm/array/difference.js.map +1 -0
- package/dist/esm/array/drop.js +2 -0
- package/dist/esm/array/drop.js.map +1 -0
- package/dist/esm/array/dropWhile.js +2 -0
- package/dist/esm/array/dropWhile.js.map +1 -0
- package/dist/esm/array/first.js +2 -0
- package/dist/esm/array/first.js.map +1 -0
- package/dist/esm/array/flatten.js +2 -0
- package/dist/esm/array/flatten.js.map +1 -0
- package/dist/esm/array/groupBy.js +2 -0
- package/dist/esm/array/groupBy.js.map +1 -0
- package/dist/esm/array/index.js +2 -0
- package/dist/esm/array/index.js.map +1 -0
- package/dist/esm/array/intersection.js +2 -0
- package/dist/esm/array/intersection.js.map +1 -0
- package/dist/esm/array/keyBy.js +2 -0
- package/dist/esm/array/keyBy.js.map +1 -0
- package/dist/esm/array/last.js +2 -0
- package/dist/esm/array/last.js.map +1 -0
- package/dist/esm/array/maxBy.js +2 -0
- package/dist/esm/array/maxBy.js.map +1 -0
- package/dist/esm/array/minBy.js +2 -0
- package/dist/esm/array/minBy.js.map +1 -0
- package/dist/esm/array/partition.js +2 -0
- package/dist/esm/array/partition.js.map +1 -0
- package/dist/esm/array/sameElementsInArrays.js +2 -0
- package/dist/esm/array/sameElementsInArrays.js.map +1 -0
- package/dist/esm/array/sample.js +2 -0
- package/dist/esm/array/sample.js.map +1 -0
- package/dist/esm/array/shuffle.js +2 -0
- package/dist/esm/array/shuffle.js.map +1 -0
- package/dist/esm/array/sortBy.js +2 -0
- package/dist/esm/array/sortBy.js.map +1 -0
- package/dist/esm/array/take.js +2 -0
- package/dist/esm/array/take.js.map +1 -0
- package/dist/esm/array/takeWhile.js +2 -0
- package/dist/esm/array/takeWhile.js.map +1 -0
- package/dist/esm/array/union.js +2 -0
- package/dist/esm/array/union.js.map +1 -0
- package/dist/esm/array/uniq.js +2 -0
- package/dist/esm/array/uniq.js.map +1 -0
- package/dist/esm/array/uniqBy.js +2 -0
- package/dist/esm/array/uniqBy.js.map +1 -0
- package/dist/esm/array/without.js +2 -0
- package/dist/esm/array/without.js.map +1 -0
- package/dist/esm/array/xor.js +2 -0
- package/dist/esm/array/xor.js.map +1 -0
- package/dist/esm/array/zip.js +2 -0
- package/dist/esm/array/zip.js.map +1 -0
- package/dist/esm/array/zipObject.js +2 -0
- package/dist/esm/array/zipObject.js.map +1 -0
- package/dist/esm/file/anyToString.js +2 -0
- package/dist/esm/file/anyToString.js.map +1 -0
- package/dist/esm/file/convertToFormData.js +2 -0
- package/dist/esm/file/convertToFormData.js.map +1 -0
- package/dist/esm/file/decodeURIValue.js +2 -0
- package/dist/esm/file/decodeURIValue.js.map +1 -0
- package/dist/esm/file/downloadFile.js +2 -0
- package/dist/esm/file/downloadFile.js.map +1 -0
- package/dist/esm/file/getBase64.js +2 -0
- package/dist/esm/file/getBase64.js.map +1 -0
- package/dist/esm/file/index.js +2 -0
- package/dist/esm/file/index.js.map +1 -0
- package/dist/esm/file/isFileArray.js +2 -0
- package/dist/esm/file/isFileArray.js.map +1 -0
- package/dist/esm/function/compose.js +2 -0
- package/dist/esm/function/compose.js.map +1 -0
- package/dist/esm/function/curry.js +2 -0
- package/dist/esm/function/curry.js.map +1 -0
- package/dist/esm/function/debounce.js +2 -0
- package/dist/esm/function/debounce.js.map +1 -0
- package/dist/esm/function/hexToRgba.js +2 -0
- package/dist/esm/function/hexToRgba.js.map +1 -0
- package/dist/esm/function/identity.js +2 -0
- package/dist/esm/function/identity.js.map +1 -0
- package/dist/esm/function/index.js +2 -0
- package/dist/esm/function/index.js.map +1 -0
- package/dist/esm/function/memoize.js +2 -0
- package/dist/esm/function/memoize.js.map +1 -0
- package/dist/esm/function/negate.js +2 -0
- package/dist/esm/function/negate.js.map +1 -0
- package/dist/esm/function/noop.js +2 -0
- package/dist/esm/function/noop.js.map +1 -0
- package/dist/esm/function/once.js +2 -0
- package/dist/esm/function/once.js.map +1 -0
- package/dist/esm/function/partial.js +2 -0
- package/dist/esm/function/partial.js.map +1 -0
- package/dist/esm/function/pipe.js +2 -0
- package/dist/esm/function/pipe.js.map +1 -0
- package/dist/esm/function/queryString.js +2 -0
- package/dist/esm/function/queryString.js.map +1 -0
- package/dist/esm/function/throttle.js +2 -0
- package/dist/esm/function/throttle.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/math/clamp.js +2 -0
- package/dist/esm/math/clamp.js.map +1 -0
- package/dist/esm/math/inRange.js +2 -0
- package/dist/esm/math/inRange.js.map +1 -0
- package/dist/esm/math/index.js +2 -0
- package/dist/esm/math/index.js.map +1 -0
- package/dist/esm/math/mean.js +2 -0
- package/dist/esm/math/mean.js.map +1 -0
- package/dist/esm/math/median.js +2 -0
- package/dist/esm/math/median.js.map +1 -0
- package/dist/esm/math/random.js +2 -0
- package/dist/esm/math/random.js.map +1 -0
- package/dist/esm/math/range.js +2 -0
- package/dist/esm/math/range.js.map +1 -0
- package/dist/esm/math/round.js +2 -0
- package/dist/esm/math/round.js.map +1 -0
- package/dist/esm/math/sum.js +2 -0
- package/dist/esm/math/sum.js.map +1 -0
- package/dist/esm/object/cloneDeep.js +2 -0
- package/dist/esm/object/cloneDeep.js.map +1 -0
- package/dist/esm/object/findKey.js +2 -0
- package/dist/esm/object/findKey.js.map +1 -0
- package/dist/esm/object/flattenObject.js +2 -0
- package/dist/esm/object/flattenObject.js.map +1 -0
- package/dist/esm/object/get.js +2 -0
- package/dist/esm/object/get.js.map +1 -0
- package/dist/esm/object/getTrue.js +2 -0
- package/dist/esm/object/getTrue.js.map +1 -0
- package/dist/esm/object/has.js +2 -0
- package/dist/esm/object/has.js.map +1 -0
- package/dist/esm/object/index.js +2 -0
- package/dist/esm/object/index.js.map +1 -0
- package/dist/esm/object/invert.js +2 -0
- package/dist/esm/object/invert.js.map +1 -0
- package/dist/esm/object/isEmpty.js +2 -0
- package/dist/esm/object/isEmpty.js.map +1 -0
- package/dist/esm/object/jsonParse.js +2 -0
- package/dist/esm/object/jsonParse.js.map +1 -0
- package/dist/esm/object/mapKeys.js +2 -0
- package/dist/esm/object/mapKeys.js.map +1 -0
- package/dist/esm/object/mapValues.js +2 -0
- package/dist/esm/object/mapValues.js.map +1 -0
- package/dist/esm/object/mergeDeep.js +2 -0
- package/dist/esm/object/mergeDeep.js.map +1 -0
- package/dist/esm/object/omit.js +2 -0
- package/dist/esm/object/omit.js.map +1 -0
- package/dist/esm/object/omitBy.js +2 -0
- package/dist/esm/object/omitBy.js.map +1 -0
- package/dist/esm/object/path.js +2 -0
- package/dist/esm/object/path.js.map +1 -0
- package/dist/esm/object/pathOr.js +2 -0
- package/dist/esm/object/pathOr.js.map +1 -0
- package/dist/esm/object/pick.js +2 -0
- package/dist/esm/object/pick.js.map +1 -0
- package/dist/esm/object/pickBy.js +2 -0
- package/dist/esm/object/pickBy.js.map +1 -0
- package/dist/esm/object/prop.js +2 -0
- package/dist/esm/object/prop.js.map +1 -0
- package/dist/esm/object/propOr.js +2 -0
- package/dist/esm/object/propOr.js.map +1 -0
- package/dist/esm/object/set.js +2 -0
- package/dist/esm/object/set.js.map +1 -0
- package/dist/esm/predicate/index.js +2 -0
- package/dist/esm/predicate/index.js.map +1 -0
- package/dist/esm/predicate/isArray.js +2 -0
- package/dist/esm/predicate/isArray.js.map +1 -0
- package/dist/esm/predicate/isBoolean.js +2 -0
- package/dist/esm/predicate/isBoolean.js.map +1 -0
- package/dist/esm/predicate/isDate.js +2 -0
- package/dist/esm/predicate/isDate.js.map +1 -0
- package/dist/esm/predicate/isEqual.js +2 -0
- package/dist/esm/predicate/isEqual.js.map +1 -0
- package/dist/esm/predicate/isError.js +2 -0
- package/dist/esm/predicate/isError.js.map +1 -0
- package/dist/esm/predicate/isFunction.js +2 -0
- package/dist/esm/predicate/isFunction.js.map +1 -0
- package/dist/esm/predicate/isNil.js +2 -0
- package/dist/esm/predicate/isNil.js.map +1 -0
- package/dist/esm/predicate/isNumber.js +2 -0
- package/dist/esm/predicate/isNumber.js.map +1 -0
- package/dist/esm/predicate/isPlainObject.js +2 -0
- package/dist/esm/predicate/isPlainObject.js.map +1 -0
- package/dist/esm/predicate/isPrimitive.js +2 -0
- package/dist/esm/predicate/isPrimitive.js.map +1 -0
- package/dist/esm/predicate/isPromise.js +2 -0
- package/dist/esm/predicate/isPromise.js.map +1 -0
- package/dist/esm/predicate/isString.js +2 -0
- package/dist/esm/predicate/isString.js.map +1 -0
- package/dist/esm/promise/attempt.js +2 -0
- package/dist/esm/promise/attempt.js.map +1 -0
- package/dist/esm/promise/delay.js +2 -0
- package/dist/esm/promise/delay.js.map +1 -0
- package/dist/esm/promise/index.js +2 -0
- package/dist/esm/promise/index.js.map +1 -0
- package/dist/esm/promise/invariant.js +2 -0
- package/dist/esm/promise/invariant.js.map +1 -0
- package/dist/esm/promise/retry.js +2 -0
- package/dist/esm/promise/retry.js.map +1 -0
- package/dist/esm/promise/timeout.js +2 -0
- package/dist/esm/promise/timeout.js.map +1 -0
- package/dist/esm/react/hooks/useClickOutside.js +3 -0
- package/dist/esm/react/hooks/useClickOutside.js.map +1 -0
- package/dist/esm/react/hooks/useCopyToClipboard.js +3 -0
- package/dist/esm/react/hooks/useCopyToClipboard.js.map +1 -0
- package/dist/esm/react/hooks/useDebounce.js +3 -0
- package/dist/esm/react/hooks/useDebounce.js.map +1 -0
- package/dist/esm/react/hooks/useIntersectionObserver.js +3 -0
- package/dist/esm/react/hooks/useIntersectionObserver.js.map +1 -0
- package/dist/esm/react/hooks/useIsMounted.js +3 -0
- package/dist/esm/react/hooks/useIsMounted.js.map +1 -0
- package/dist/esm/react/hooks/useLocalStorage.js +3 -0
- package/dist/esm/react/hooks/useLocalStorage.js.map +1 -0
- package/dist/esm/react/hooks/useMediaQuery.js +3 -0
- package/dist/esm/react/hooks/useMediaQuery.js.map +1 -0
- package/dist/esm/react/hooks/useMountEffect.js +3 -0
- package/dist/esm/react/hooks/useMountEffect.js.map +1 -0
- package/dist/esm/react/hooks/usePrevious.js +3 -0
- package/dist/esm/react/hooks/usePrevious.js.map +1 -0
- package/dist/esm/react/hooks/useScreenSize.js +3 -0
- package/dist/esm/react/hooks/useScreenSize.js.map +1 -0
- package/dist/esm/react/hooks/useSessionStorage.js +3 -0
- package/dist/esm/react/hooks/useSessionStorage.js.map +1 -0
- package/dist/esm/react/hooks/useThrottle.js +3 -0
- package/dist/esm/react/hooks/useThrottle.js.map +1 -0
- package/dist/esm/react/hooks/useToggle.js +3 -0
- package/dist/esm/react/hooks/useToggle.js.map +1 -0
- package/dist/esm/react/hooks/useUpdateEffect.js +3 -0
- package/dist/esm/react/hooks/useUpdateEffect.js.map +1 -0
- package/dist/esm/react/index.js +2 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/esm/react/utils/clsx.js +2 -0
- package/dist/esm/react/utils/clsx.js.map +1 -0
- package/dist/esm/react/utils/createContext.js +3 -0
- package/dist/esm/react/utils/createContext.js.map +1 -0
- package/dist/esm/react/utils/displayField.js +2 -0
- package/dist/esm/react/utils/displayField.js.map +1 -0
- package/dist/esm/string/camelCase.js +2 -0
- package/dist/esm/string/camelCase.js.map +1 -0
- package/dist/esm/string/capitalize.js +2 -0
- package/dist/esm/string/capitalize.js.map +1 -0
- package/dist/esm/string/deburr.js +2 -0
- package/dist/esm/string/deburr.js.map +1 -0
- package/dist/esm/string/escapeHtml.js +2 -0
- package/dist/esm/string/escapeHtml.js.map +1 -0
- package/dist/esm/string/escapeRegExp.js +2 -0
- package/dist/esm/string/escapeRegExp.js.map +1 -0
- package/dist/esm/string/formatBytes.js +2 -0
- package/dist/esm/string/formatBytes.js.map +1 -0
- package/dist/esm/string/formatDuration.js +2 -0
- package/dist/esm/string/formatDuration.js.map +1 -0
- package/dist/esm/string/formatNumber.js +2 -0
- package/dist/esm/string/formatNumber.js.map +1 -0
- package/dist/esm/string/htmlToText.js +2 -0
- package/dist/esm/string/htmlToText.js.map +1 -0
- package/dist/esm/string/index.js +2 -0
- package/dist/esm/string/index.js.map +1 -0
- package/dist/esm/string/kebabCase.js +2 -0
- package/dist/esm/string/kebabCase.js.map +1 -0
- package/dist/esm/string/maskString.js +2 -0
- package/dist/esm/string/maskString.js.map +1 -0
- package/dist/esm/string/pascalCase.js +2 -0
- package/dist/esm/string/pascalCase.js.map +1 -0
- package/dist/esm/string/pluralize.js +2 -0
- package/dist/esm/string/pluralize.js.map +1 -0
- package/dist/esm/string/slugify.js +2 -0
- package/dist/esm/string/slugify.js.map +1 -0
- package/dist/esm/string/snakeCase.js +2 -0
- package/dist/esm/string/snakeCase.js.map +1 -0
- package/dist/esm/string/startCase.js +2 -0
- package/dist/esm/string/startCase.js.map +1 -0
- package/dist/esm/string/template.js +2 -0
- package/dist/esm/string/template.js.map +1 -0
- package/dist/esm/string/truncateString.js +2 -0
- package/dist/esm/string/truncateString.js.map +1 -0
- package/dist/esm/string/words.js +2 -0
- package/dist/esm/string/words.js.map +1 -0
- package/dist/esm/validation/index.js +2 -0
- package/dist/esm/validation/index.js.map +1 -0
- package/dist/esm/validation/validateFileSizeByType.js +2 -0
- package/dist/esm/validation/validateFileSizeByType.js.map +1 -0
- package/dist/types/array/checkValueInArray.d.ts +23 -0
- package/dist/types/array/checkValueInArray.d.ts.map +1 -0
- package/dist/types/array/chunk.d.ts +15 -0
- package/dist/types/array/chunk.d.ts.map +1 -0
- package/dist/types/array/collectBy.d.ts +21 -0
- package/dist/types/array/collectBy.d.ts.map +1 -0
- package/dist/types/array/compact.d.ts +19 -0
- package/dist/types/array/compact.d.ts.map +1 -0
- package/dist/types/array/countBy.d.ts +13 -0
- package/dist/types/array/countBy.d.ts.map +1 -0
- package/dist/types/array/difference.d.ts +14 -0
- package/dist/types/array/difference.d.ts.map +1 -0
- package/dist/types/array/drop.d.ts +14 -0
- package/dist/types/array/drop.d.ts.map +1 -0
- package/dist/types/array/dropWhile.d.ts +13 -0
- package/dist/types/array/dropWhile.d.ts.map +1 -0
- package/dist/types/array/first.d.ts +13 -0
- package/dist/types/array/first.d.ts.map +1 -0
- package/dist/types/array/flatten.d.ts +13 -0
- package/dist/types/array/flatten.d.ts.map +1 -0
- package/dist/types/array/groupBy.d.ts +17 -0
- package/dist/types/array/groupBy.d.ts.map +1 -0
- package/dist/types/array/index.d.ts +31 -0
- package/dist/types/array/index.d.ts.map +1 -0
- package/dist/types/array/intersection.d.ts +14 -0
- package/dist/types/array/intersection.d.ts.map +1 -0
- package/dist/types/array/keyBy.d.ts +15 -0
- package/dist/types/array/keyBy.d.ts.map +1 -0
- package/dist/types/array/last.d.ts +13 -0
- package/dist/types/array/last.d.ts.map +1 -0
- package/dist/types/array/maxBy.d.ts +13 -0
- package/dist/types/array/maxBy.d.ts.map +1 -0
- package/dist/types/array/minBy.d.ts +13 -0
- package/dist/types/array/minBy.d.ts.map +1 -0
- package/dist/types/array/partition.d.ts +13 -0
- package/dist/types/array/partition.d.ts.map +1 -0
- package/dist/types/array/sameElementsInArrays.d.ts +15 -0
- package/dist/types/array/sameElementsInArrays.d.ts.map +1 -0
- package/dist/types/array/sample.d.ts +12 -0
- package/dist/types/array/sample.d.ts.map +1 -0
- package/dist/types/array/shuffle.d.ts +12 -0
- package/dist/types/array/shuffle.d.ts.map +1 -0
- package/dist/types/array/sortBy.d.ts +20 -0
- package/dist/types/array/sortBy.d.ts.map +1 -0
- package/dist/types/array/take.d.ts +14 -0
- package/dist/types/array/take.d.ts.map +1 -0
- package/dist/types/array/takeWhile.d.ts +13 -0
- package/dist/types/array/takeWhile.d.ts.map +1 -0
- package/dist/types/array/union.d.ts +13 -0
- package/dist/types/array/union.d.ts.map +1 -0
- package/dist/types/array/uniq.d.ts +12 -0
- package/dist/types/array/uniq.d.ts.map +1 -0
- package/dist/types/array/uniqBy.d.ts +12 -0
- package/dist/types/array/uniqBy.d.ts.map +1 -0
- package/dist/types/array/without.d.ts +13 -0
- package/dist/types/array/without.d.ts.map +1 -0
- package/dist/types/array/xor.d.ts +13 -0
- package/dist/types/array/xor.d.ts.map +1 -0
- package/dist/types/array/zip.d.ts +15 -0
- package/dist/types/array/zip.d.ts.map +1 -0
- package/dist/types/array/zipObject.d.ts +13 -0
- package/dist/types/array/zipObject.d.ts.map +1 -0
- package/dist/types/file/anyToString.d.ts +24 -0
- package/dist/types/file/anyToString.d.ts.map +1 -0
- package/dist/types/file/convertToFormData.d.ts +19 -0
- package/dist/types/file/convertToFormData.d.ts.map +1 -0
- package/dist/types/file/decodeURIValue.d.ts +22 -0
- package/dist/types/file/decodeURIValue.d.ts.map +1 -0
- package/dist/types/file/downloadFile.d.ts +28 -0
- package/dist/types/file/downloadFile.d.ts.map +1 -0
- package/dist/types/file/getBase64.d.ts +20 -0
- package/dist/types/file/getBase64.d.ts.map +1 -0
- package/dist/types/file/index.d.ts +7 -0
- package/dist/types/file/index.d.ts.map +1 -0
- package/dist/types/file/isFileArray.d.ts +13 -0
- package/dist/types/file/isFileArray.d.ts.map +1 -0
- package/dist/types/function/compose.d.ts +24 -0
- package/dist/types/function/compose.d.ts.map +1 -0
- package/dist/types/function/curry.d.ts +39 -0
- package/dist/types/function/curry.d.ts.map +1 -0
- package/dist/types/function/debounce.d.ts +36 -0
- package/dist/types/function/debounce.d.ts.map +1 -0
- package/dist/types/function/hexToRgba.d.ts +19 -0
- package/dist/types/function/hexToRgba.d.ts.map +1 -0
- package/dist/types/function/identity.d.ts +24 -0
- package/dist/types/function/identity.d.ts.map +1 -0
- package/dist/types/function/index.d.ts +16 -0
- package/dist/types/function/index.d.ts.map +1 -0
- package/dist/types/function/memoize.d.ts +20 -0
- package/dist/types/function/memoize.d.ts.map +1 -0
- package/dist/types/function/negate.d.ts +12 -0
- package/dist/types/function/negate.d.ts.map +1 -0
- package/dist/types/function/noop.d.ts +27 -0
- package/dist/types/function/noop.d.ts.map +1 -0
- package/dist/types/function/once.d.ts +22 -0
- package/dist/types/function/once.d.ts.map +1 -0
- package/dist/types/function/partial.d.ts +17 -0
- package/dist/types/function/partial.d.ts.map +1 -0
- package/dist/types/function/pipe.d.ts +24 -0
- package/dist/types/function/pipe.d.ts.map +1 -0
- package/dist/types/function/queryString.d.ts +44 -0
- package/dist/types/function/queryString.d.ts.map +1 -0
- package/dist/types/function/throttle.d.ts +35 -0
- package/dist/types/function/throttle.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/math/clamp.d.ts +15 -0
- package/dist/types/math/clamp.d.ts.map +1 -0
- package/dist/types/math/inRange.d.ts +18 -0
- package/dist/types/math/inRange.d.ts.map +1 -0
- package/dist/types/math/index.d.ts +9 -0
- package/dist/types/math/index.d.ts.map +1 -0
- package/dist/types/math/mean.d.ts +11 -0
- package/dist/types/math/mean.d.ts.map +1 -0
- package/dist/types/math/median.d.ts +15 -0
- package/dist/types/math/median.d.ts.map +1 -0
- package/dist/types/math/random.d.ts +27 -0
- package/dist/types/math/random.d.ts.map +1 -0
- package/dist/types/math/range.d.ts +18 -0
- package/dist/types/math/range.d.ts.map +1 -0
- package/dist/types/math/round.d.ts +16 -0
- package/dist/types/math/round.d.ts.map +1 -0
- package/dist/types/math/sum.d.ts +11 -0
- package/dist/types/math/sum.d.ts.map +1 -0
- package/dist/types/object/cloneDeep.d.ts +18 -0
- package/dist/types/object/cloneDeep.d.ts.map +1 -0
- package/dist/types/object/findKey.d.ts +14 -0
- package/dist/types/object/findKey.d.ts.map +1 -0
- package/dist/types/object/flattenObject.d.ts +16 -0
- package/dist/types/object/flattenObject.d.ts.map +1 -0
- package/dist/types/object/get.d.ts +22 -0
- package/dist/types/object/get.d.ts.map +1 -0
- package/dist/types/object/getTrue.d.ts +12 -0
- package/dist/types/object/getTrue.d.ts.map +1 -0
- package/dist/types/object/has.d.ts +15 -0
- package/dist/types/object/has.d.ts.map +1 -0
- package/dist/types/object/index.d.ts +22 -0
- package/dist/types/object/index.d.ts.map +1 -0
- package/dist/types/object/invert.d.ts +13 -0
- package/dist/types/object/invert.d.ts.map +1 -0
- package/dist/types/object/isEmpty.d.ts +23 -0
- package/dist/types/object/isEmpty.d.ts.map +1 -0
- package/dist/types/object/jsonParse.d.ts +21 -0
- package/dist/types/object/jsonParse.d.ts.map +1 -0
- package/dist/types/object/mapKeys.d.ts +17 -0
- package/dist/types/object/mapKeys.d.ts.map +1 -0
- package/dist/types/object/mapValues.d.ts +17 -0
- package/dist/types/object/mapValues.d.ts.map +1 -0
- package/dist/types/object/mergeDeep.d.ts +20 -0
- package/dist/types/object/mergeDeep.d.ts.map +1 -0
- package/dist/types/object/omit.d.ts +13 -0
- package/dist/types/object/omit.d.ts.map +1 -0
- package/dist/types/object/omitBy.d.ts +17 -0
- package/dist/types/object/omitBy.d.ts.map +1 -0
- package/dist/types/object/path.d.ts +13 -0
- package/dist/types/object/path.d.ts.map +1 -0
- package/dist/types/object/pathOr.d.ts +14 -0
- package/dist/types/object/pathOr.d.ts.map +1 -0
- package/dist/types/object/pick.d.ts +13 -0
- package/dist/types/object/pick.d.ts.map +1 -0
- package/dist/types/object/pickBy.d.ts +17 -0
- package/dist/types/object/pickBy.d.ts.map +1 -0
- package/dist/types/object/prop.d.ts +31 -0
- package/dist/types/object/prop.d.ts.map +1 -0
- package/dist/types/object/propOr.d.ts +39 -0
- package/dist/types/object/propOr.d.ts.map +1 -0
- package/dist/types/object/set.d.ts +16 -0
- package/dist/types/object/set.d.ts.map +1 -0
- package/dist/types/predicate/index.d.ts +16 -0
- package/dist/types/predicate/index.d.ts.map +1 -0
- package/dist/types/predicate/isArray.d.ts +14 -0
- package/dist/types/predicate/isArray.d.ts.map +1 -0
- package/dist/types/predicate/isBoolean.d.ts +14 -0
- package/dist/types/predicate/isBoolean.d.ts.map +1 -0
- package/dist/types/predicate/isDate.d.ts +16 -0
- package/dist/types/predicate/isDate.d.ts.map +1 -0
- package/dist/types/predicate/isEqual.d.ts +18 -0
- package/dist/types/predicate/isEqual.d.ts.map +1 -0
- package/dist/types/predicate/isError.d.ts +14 -0
- package/dist/types/predicate/isError.d.ts.map +1 -0
- package/dist/types/predicate/isFunction.d.ts +14 -0
- package/dist/types/predicate/isFunction.d.ts.map +1 -0
- package/dist/types/predicate/isNil.d.ts +33 -0
- package/dist/types/predicate/isNil.d.ts.map +1 -0
- package/dist/types/predicate/isNumber.d.ts +17 -0
- package/dist/types/predicate/isNumber.d.ts.map +1 -0
- package/dist/types/predicate/isPlainObject.d.ts +18 -0
- package/dist/types/predicate/isPlainObject.d.ts.map +1 -0
- package/dist/types/predicate/isPrimitive.d.ts +18 -0
- package/dist/types/predicate/isPrimitive.d.ts.map +1 -0
- package/dist/types/predicate/isPromise.d.ts +14 -0
- package/dist/types/predicate/isPromise.d.ts.map +1 -0
- package/dist/types/predicate/isString.d.ts +14 -0
- package/dist/types/predicate/isString.d.ts.map +1 -0
- package/dist/types/promise/attempt.d.ts +28 -0
- package/dist/types/promise/attempt.d.ts.map +1 -0
- package/dist/types/promise/delay.d.ts +26 -0
- package/dist/types/promise/delay.d.ts.map +1 -0
- package/dist/types/promise/index.d.ts +10 -0
- package/dist/types/promise/index.d.ts.map +1 -0
- package/dist/types/promise/invariant.d.ts +18 -0
- package/dist/types/promise/invariant.d.ts.map +1 -0
- package/dist/types/promise/retry.d.ts +36 -0
- package/dist/types/promise/retry.d.ts.map +1 -0
- package/dist/types/promise/timeout.d.ts +30 -0
- package/dist/types/promise/timeout.d.ts.map +1 -0
- package/dist/types/react/hooks/index.d.ts +21 -0
- package/dist/types/react/hooks/index.d.ts.map +1 -0
- package/dist/types/react/hooks/useClickOutside.d.ts +116 -0
- package/dist/types/react/hooks/useClickOutside.d.ts.map +1 -0
- package/dist/types/react/hooks/useCopyToClipboard.d.ts +22 -0
- package/dist/types/react/hooks/useCopyToClipboard.d.ts.map +1 -0
- package/dist/types/react/hooks/useDebounce.d.ts +57 -0
- package/dist/types/react/hooks/useDebounce.d.ts.map +1 -0
- package/dist/types/react/hooks/useIntersectionObserver.d.ts +118 -0
- package/dist/types/react/hooks/useIntersectionObserver.d.ts.map +1 -0
- package/dist/types/react/hooks/useIsMounted.d.ts +26 -0
- package/dist/types/react/hooks/useIsMounted.d.ts.map +1 -0
- package/dist/types/react/hooks/useLocalStorage.d.ts +78 -0
- package/dist/types/react/hooks/useLocalStorage.d.ts.map +1 -0
- package/dist/types/react/hooks/useMediaQuery.d.ts +85 -0
- package/dist/types/react/hooks/useMediaQuery.d.ts.map +1 -0
- package/dist/types/react/hooks/useMountEffect.d.ts +107 -0
- package/dist/types/react/hooks/useMountEffect.d.ts.map +1 -0
- package/dist/types/react/hooks/usePrevious.d.ts +88 -0
- package/dist/types/react/hooks/usePrevious.d.ts.map +1 -0
- package/dist/types/react/hooks/useScreenSize.d.ts +37 -0
- package/dist/types/react/hooks/useScreenSize.d.ts.map +1 -0
- package/dist/types/react/hooks/useSessionStorage.d.ts +49 -0
- package/dist/types/react/hooks/useSessionStorage.d.ts.map +1 -0
- package/dist/types/react/hooks/useThrottle.d.ts +62 -0
- package/dist/types/react/hooks/useThrottle.d.ts.map +1 -0
- package/dist/types/react/hooks/useToggle.d.ts +89 -0
- package/dist/types/react/hooks/useToggle.d.ts.map +1 -0
- package/dist/types/react/hooks/useUpdateEffect.d.ts +91 -0
- package/dist/types/react/hooks/useUpdateEffect.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +9 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/utils/clsx.d.ts +31 -0
- package/dist/types/react/utils/clsx.d.ts.map +1 -0
- package/dist/types/react/utils/createContext.d.ts +27 -0
- package/dist/types/react/utils/createContext.d.ts.map +1 -0
- package/dist/types/react/utils/displayField.d.ts +18 -0
- package/dist/types/react/utils/displayField.d.ts.map +1 -0
- package/dist/types/react/utils/index.d.ts +5 -0
- package/dist/types/react/utils/index.d.ts.map +1 -0
- package/dist/types/string/camelCase.d.ts +16 -0
- package/dist/types/string/camelCase.d.ts.map +1 -0
- package/dist/types/string/capitalize.d.ts +11 -0
- package/dist/types/string/capitalize.d.ts.map +1 -0
- package/dist/types/string/deburr.d.ts +14 -0
- package/dist/types/string/deburr.d.ts.map +1 -0
- package/dist/types/string/escapeHtml.d.ts +17 -0
- package/dist/types/string/escapeHtml.d.ts.map +1 -0
- package/dist/types/string/escapeRegExp.d.ts +13 -0
- package/dist/types/string/escapeRegExp.d.ts.map +1 -0
- package/dist/types/string/formatBytes.d.ts +16 -0
- package/dist/types/string/formatBytes.d.ts.map +1 -0
- package/dist/types/string/formatDuration.d.ts +15 -0
- package/dist/types/string/formatDuration.d.ts.map +1 -0
- package/dist/types/string/formatNumber.d.ts +20 -0
- package/dist/types/string/formatNumber.d.ts.map +1 -0
- package/dist/types/string/htmlToText.d.ts +29 -0
- package/dist/types/string/htmlToText.d.ts.map +1 -0
- package/dist/types/string/index.d.ts +20 -0
- package/dist/types/string/index.d.ts.map +1 -0
- package/dist/types/string/kebabCase.d.ts +16 -0
- package/dist/types/string/kebabCase.d.ts.map +1 -0
- package/dist/types/string/maskString.d.ts +18 -0
- package/dist/types/string/maskString.d.ts.map +1 -0
- package/dist/types/string/pascalCase.d.ts +14 -0
- package/dist/types/string/pascalCase.d.ts.map +1 -0
- package/dist/types/string/pluralize.d.ts +17 -0
- package/dist/types/string/pluralize.d.ts.map +1 -0
- package/dist/types/string/slugify.d.ts +15 -0
- package/dist/types/string/slugify.d.ts.map +1 -0
- package/dist/types/string/snakeCase.d.ts +16 -0
- package/dist/types/string/snakeCase.d.ts.map +1 -0
- package/dist/types/string/startCase.d.ts +14 -0
- package/dist/types/string/startCase.d.ts.map +1 -0
- package/dist/types/string/template.d.ts +15 -0
- package/dist/types/string/template.d.ts.map +1 -0
- package/dist/types/string/truncateString.d.ts +13 -0
- package/dist/types/string/truncateString.d.ts.map +1 -0
- package/dist/types/string/words.d.ts +16 -0
- package/dist/types/string/words.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +44 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/validation/index.d.ts +5 -0
- package/dist/types/validation/index.d.ts.map +1 -0
- package/dist/types/validation/validateFileSizeByType.d.ts +32 -0
- package/dist/types/validation/validateFileSizeByType.d.ts.map +1 -0
- package/package.json +109 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ulukbek Dzhunusov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# @mdigitalcn/utils
|
|
2
|
+
|
|
3
|
+
Production-grade TypeScript utilities and React hooks. Zero dependencies (except optional React peer).
|
|
4
|
+
|
|
5
|
+
Tree-shakeable, ESM-only, with full type inference.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @mdigitalcn/utils
|
|
11
|
+
# or
|
|
12
|
+
npm install @mdigitalcn/utils
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// Import everything
|
|
19
|
+
import { pipe, pick, isNil, chunk } from '@mdigitalcn/utils';
|
|
20
|
+
|
|
21
|
+
// Or use subpath imports for smaller bundles
|
|
22
|
+
import { chunk, groupBy, zip } from '@mdigitalcn/utils/array';
|
|
23
|
+
import { pick, omit, set, get } from '@mdigitalcn/utils/object';
|
|
24
|
+
import { pipe, compose, debounce } from '@mdigitalcn/utils/function';
|
|
25
|
+
import { isNil, isEqual, isDate } from '@mdigitalcn/utils/predicate';
|
|
26
|
+
import { clamp, range, sum } from '@mdigitalcn/utils/math';
|
|
27
|
+
import { camelCase, kebabCase, words } from '@mdigitalcn/utils/string';
|
|
28
|
+
import { retry, timeout, delay } from '@mdigitalcn/utils/promise';
|
|
29
|
+
import { useDebounce, useToggle } from '@mdigitalcn/utils/react';
|
|
30
|
+
import { downloadFile, getBase64 } from '@mdigitalcn/utils/file';
|
|
31
|
+
import { validateFileSize } from '@mdigitalcn/utils/validation';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API Overview
|
|
35
|
+
|
|
36
|
+
### Array
|
|
37
|
+
|
|
38
|
+
| Function | Description |
|
|
39
|
+
|----------|-------------|
|
|
40
|
+
| `chunk(arr, size)` | Split array into groups of `size` |
|
|
41
|
+
| `compact(arr)` | Remove falsy values |
|
|
42
|
+
| `difference(a, b)` | Elements in `a` not in `b` |
|
|
43
|
+
| `drop(arr, n)` | Remove first `n` elements |
|
|
44
|
+
| `first(arr)` | First element or `undefined` |
|
|
45
|
+
| `flatten(arr)` | Flatten one level |
|
|
46
|
+
| `groupBy(arr, fn)` | Group by function result |
|
|
47
|
+
| `intersection(a, b)` | Elements in both arrays |
|
|
48
|
+
| `keyBy(arr, fn)` | Index array into object by key |
|
|
49
|
+
| `last(arr)` | Last element or `undefined` |
|
|
50
|
+
| `partition(arr, fn)` | Split into `[pass, fail]` |
|
|
51
|
+
| `shuffle(arr)` | Random order (Fisher-Yates) |
|
|
52
|
+
| `sortBy(arr, fn)` | Sort by function result |
|
|
53
|
+
| `take(arr, n)` | First `n` elements |
|
|
54
|
+
| `uniq(arr)` | Remove duplicates |
|
|
55
|
+
| `uniqBy(arr, fn)` | Remove duplicates by function |
|
|
56
|
+
| `zip(a, b)` | Pair elements into tuples |
|
|
57
|
+
| `collectBy(arr, fn)` | Group into sub-arrays by key |
|
|
58
|
+
| `checkValueInArray(arr, key, val)` | Check if value exists for key |
|
|
59
|
+
| `sameElementsInArrays(...arrs)` | First element common to all |
|
|
60
|
+
|
|
61
|
+
### Object
|
|
62
|
+
|
|
63
|
+
| Function | Description |
|
|
64
|
+
|----------|-------------|
|
|
65
|
+
| `pick(obj, keys)` | Keep only specified keys |
|
|
66
|
+
| `pickBy(obj, fn)` | Keep properties passing predicate |
|
|
67
|
+
| `omit(obj, keys)` | Remove specified keys |
|
|
68
|
+
| `omitBy(obj, fn)` | Remove properties passing predicate |
|
|
69
|
+
| `get(obj, path, default?)` | Safe deep access by string/array path |
|
|
70
|
+
| `set(obj, path, value)` | Immutable deep setter |
|
|
71
|
+
| `has(obj, path)` | Check if deep path exists |
|
|
72
|
+
| `path(obj, pathArr)` | Access by array path |
|
|
73
|
+
| `pathOr(default, obj, pathArr)` | Access with fallback |
|
|
74
|
+
| `prop(key)` / `prop(key, obj)` | Property accessor (curried) |
|
|
75
|
+
| `propOr(default, key)` | Property accessor with fallback |
|
|
76
|
+
| `mergeDeep(a, b)` | Deep merge (b wins) |
|
|
77
|
+
| `cloneDeep(obj)` | Deep clone (handles circular refs) |
|
|
78
|
+
| `invert(obj)` | Swap keys ↔ values |
|
|
79
|
+
| `mapKeys(obj, fn)` | Transform keys |
|
|
80
|
+
| `mapValues(obj, fn)` | Transform values |
|
|
81
|
+
| `isEmpty(value)` | Check if empty (works with obj/arr/string/Map/Set) |
|
|
82
|
+
| `getTrues(obj)` | Keep only truthy values |
|
|
83
|
+
| `jsonParse(str, fallback?)` | Safe JSON.parse |
|
|
84
|
+
|
|
85
|
+
### Function
|
|
86
|
+
|
|
87
|
+
| Function | Description |
|
|
88
|
+
|----------|-------------|
|
|
89
|
+
| `pipe(f1, f2, ...)` | Left-to-right composition (type-safe up to 9 fns) |
|
|
90
|
+
| `compose(f1, f2, ...)` | Right-to-left composition (type-safe up to 9 fns) |
|
|
91
|
+
| `curry2(fn)` / `curry3` / `curry4` | Curry with 2–4 params |
|
|
92
|
+
| `partial(fn, ...args)` | Partial application (type-safe) |
|
|
93
|
+
| `memoize(fn, maxSize?)` | LRU memoization (default 500) |
|
|
94
|
+
| `debounce(fn, wait)` | Debounce with `.cancel()` / `.flush()` |
|
|
95
|
+
| `throttle(fn, interval)` | Throttle with `.cancel()` |
|
|
96
|
+
| `once(fn)` | Execute only once |
|
|
97
|
+
| `identity(x)` | Returns `x` |
|
|
98
|
+
| `noop()` / `asyncNoop()` | No-op functions |
|
|
99
|
+
| `hexToRgba(hex, opacity?)` | HEX → RGBA hex string |
|
|
100
|
+
| `convertToFormData(obj)` | Object → FormData |
|
|
101
|
+
| `createQueryString(params)` | Object → URL query string |
|
|
102
|
+
|
|
103
|
+
### Predicate
|
|
104
|
+
|
|
105
|
+
| Function | Description |
|
|
106
|
+
|----------|-------------|
|
|
107
|
+
| `isNil(v)` | `null \| undefined` guard |
|
|
108
|
+
| `isNotNil(v)` | Exclude `null \| undefined` |
|
|
109
|
+
| `isString(v)` | String primitive guard |
|
|
110
|
+
| `isNumber(v)` | Finite number guard (excludes NaN/Infinity) |
|
|
111
|
+
| `isBoolean(v)` | Boolean guard |
|
|
112
|
+
| `isArray(v)` | Array guard |
|
|
113
|
+
| `isFunction(v)` | Function guard |
|
|
114
|
+
| `isDate(v)` | Valid Date guard (excludes invalid dates) |
|
|
115
|
+
| `isPlainObject(v)` | Plain object guard (excludes arrays, class instances) |
|
|
116
|
+
| `isEqual(a, b)` | Deep equality (handles Date/RegExp/Map/Set) |
|
|
117
|
+
|
|
118
|
+
### Math
|
|
119
|
+
|
|
120
|
+
| Function | Description |
|
|
121
|
+
|----------|-------------|
|
|
122
|
+
| `clamp(min, max, value)` | Clamp number to range |
|
|
123
|
+
| `sum(numbers)` | Sum array |
|
|
124
|
+
| `mean(numbers)` | Arithmetic mean |
|
|
125
|
+
| `median(numbers)` | Median value |
|
|
126
|
+
| `round(value, precision?)` | Round to decimal places |
|
|
127
|
+
| `random(min, max?)` | Random float |
|
|
128
|
+
| `randomInt(min, max?)` | Random integer |
|
|
129
|
+
| `range(start, end?, step?)` | Generate number array |
|
|
130
|
+
| `inRange(value, start, end?)` | Check if in range |
|
|
131
|
+
|
|
132
|
+
### String
|
|
133
|
+
|
|
134
|
+
| Function | Description |
|
|
135
|
+
|----------|-------------|
|
|
136
|
+
| `capitalize(str)` | Capitalize first letter |
|
|
137
|
+
| `camelCase(str)` | Convert to camelCase |
|
|
138
|
+
| `kebabCase(str)` | Convert to kebab-case |
|
|
139
|
+
| `snakeCase(str)` | Convert to snake_case |
|
|
140
|
+
| `words(str)` | Split into word array |
|
|
141
|
+
| `escapeHtml(str)` | Escape HTML entities |
|
|
142
|
+
| `formatNumber(num, locale?)` | Format with thousands separators |
|
|
143
|
+
| `truncateString(str, max)` | Truncate with ellipsis |
|
|
144
|
+
| `htmlToText(html)` | Strip HTML tags |
|
|
145
|
+
|
|
146
|
+
### Promise
|
|
147
|
+
|
|
148
|
+
| Function | Description |
|
|
149
|
+
|----------|-------------|
|
|
150
|
+
| `delay(ms)` | Promise-based delay |
|
|
151
|
+
| `retry(fn, options?)` | Retry with exponential backoff |
|
|
152
|
+
| `timeout(promise, ms, msg?)` | Timeout wrapper |
|
|
153
|
+
|
|
154
|
+
### React Hooks
|
|
155
|
+
|
|
156
|
+
> Requires `react >= 19.0.0` as peer dependency.
|
|
157
|
+
|
|
158
|
+
| Hook | Description |
|
|
159
|
+
|------|-------------|
|
|
160
|
+
| `useDebounce(value, delay)` | Debounce a value |
|
|
161
|
+
| `useThrottle(callback, delay)` | Throttle a callback |
|
|
162
|
+
| `useLocalStorage(key, initial)` | Persistent state in localStorage |
|
|
163
|
+
| `useSessionStorage(key, initial)` | Persistent state in sessionStorage |
|
|
164
|
+
| `useToggle(initial?)` | Boolean toggle `[state, toggle, set]` |
|
|
165
|
+
| `usePrevious(value)` | Previous render's value |
|
|
166
|
+
| `useClickOutside(callback)` | Detect clicks outside element |
|
|
167
|
+
| `useMediaQuery(query)` | CSS media query match |
|
|
168
|
+
| `useIntersectionObserver(opts?)` | Viewport intersection detection |
|
|
169
|
+
| `useMountEffect(effect)` | Run once on mount |
|
|
170
|
+
| `useUpdateEffect(effect, deps)` | Run on updates only (skip mount) |
|
|
171
|
+
| `useScreenSize(threshold?)` | Check if below width threshold |
|
|
172
|
+
| `useIsMounted()` | Check if component is mounted |
|
|
173
|
+
| `useCopyToClipboard(resetDelay?)` | Copy text to clipboard |
|
|
174
|
+
|
|
175
|
+
### React Utilities
|
|
176
|
+
|
|
177
|
+
| Utility | Description |
|
|
178
|
+
|---------|-------------|
|
|
179
|
+
| `clsx(...args)` | Conditional class name builder |
|
|
180
|
+
| `createContext(name)` | Type-safe context + hook factory |
|
|
181
|
+
| `displayField(value, placeholder?)` | Display-safe value with fallback |
|
|
182
|
+
|
|
183
|
+
### File
|
|
184
|
+
|
|
185
|
+
| Function | Description |
|
|
186
|
+
|----------|-------------|
|
|
187
|
+
| `anyToString(value)` | File → object URL, string → string |
|
|
188
|
+
| `downloadFile(getData, name)` | Download blob as file |
|
|
189
|
+
| `getBase64(file)` | File → base64 string |
|
|
190
|
+
| `isFileArray(value)` | Check if array of File/Blob |
|
|
191
|
+
| `decodeURIValue(uri)` | Extract filename from URI |
|
|
192
|
+
|
|
193
|
+
### Validation
|
|
194
|
+
|
|
195
|
+
| Function | Description |
|
|
196
|
+
|----------|-------------|
|
|
197
|
+
| `validateFileSize(file, limits, resolver?)` | Validate file size by category |
|
|
198
|
+
|
|
199
|
+
### Types
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import type {
|
|
203
|
+
Predicate,
|
|
204
|
+
Transformer,
|
|
205
|
+
Comparator,
|
|
206
|
+
Reducer,
|
|
207
|
+
Curried2, Curried3, Curried4,
|
|
208
|
+
DeepReadonly,
|
|
209
|
+
DeepPartial,
|
|
210
|
+
Nullish,
|
|
211
|
+
RequireKeys,
|
|
212
|
+
OptionalKeys,
|
|
213
|
+
} from '@mdigitalcn/utils';
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Convention
|
|
217
|
+
|
|
218
|
+
All functions use **data-first** argument order:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
pick(object, keys) // ✅ data first
|
|
222
|
+
groupBy(array, fn) // ✅ data first
|
|
223
|
+
partition(array, fn) // ✅ data first
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkValueInArray.js","sources":["../../../src/array/checkValueInArray.ts"],"sourcesContent":["/**\n * Checks if a value exists for a given key in any object within an array.\n *\n * Iterates over the array of objects and returns `true` if **any** object\n * has the specified key and its value strictly equals the provided value.\n *\n * @example\n * const users = [\n * { id: '1', name: 'Alice' },\n * { id: '2', name: 'Bob' }\n * ];\n *\n * checkValueInArray(users, 'name', 'Alice') // true\n * checkValueInArray(users, 'id', '3') // false\n *\n * @template T - The type of objects in the array\n * @param {T[]} array - Array of objects to check\n * @param {keyof T} key - Key to check in each object\n * @param {T[keyof T]} value - Value to compare against\n * @returns {boolean} `true` if at least one object has the key with the given value, otherwise `false`\n */\nexport function checkValueInArray<T>(\n array: T[],\n key: keyof T,\n value: T[keyof T]\n): boolean {\n for (const obj of array) {\n if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key] === value) {\n return true;\n }\n }\n return false;\n}\n"],"names":["checkValueInArray","array","key","value","obj","Object","prototype","hasOwnProperty","call"],"mappings":"SAqBgBA,EACdC,EACAC,EACAC,GAEA,IAAK,MAAMC,KAAOH,EAChB,GAAII,OAAOC,UAAUC,eAAeC,KAAKJ,EAAKF,IAAQE,EAAIF,KAASC,EACjE,OAAO,EAGX,OAAO,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.js","sources":["../../../src/array/chunk.ts"],"sourcesContent":["/**\n * Splits an array into groups of the specified size.\n *\n * @example\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk([1, 2, 3], 1) // [[1], [2], [3]]\n * chunk([], 3) // []\n *\n * @param arr - Array to split\n * @param size - Size of each chunk (must be > 0)\n * @returns Array of chunks\n * @throws {Error} If size is less than 1\n */\nexport function chunk<T>(arr: readonly T[], size: number): T[][] {\n if (size < 1) {\n throw new Error('chunk: size must be at least 1');\n }\n\n const result: T[][] = [];\n for (let i = 0; i < arr.length; i += size) {\n result.push(arr.slice(i, i + size));\n }\n return result;\n}\n"],"names":["chunk","arr","size","Error","result","i","length","push","slice"],"mappings":"AAaM,SAAUA,EAASC,EAAmBC,GAC1C,GAAIA,EAAO,EACT,MAAM,IAAIC,MAAM,kCAGlB,MAAMC,EAAgB,GACtB,IAAK,IAAIC,EAAI,EAAGA,EAAIJ,EAAIK,OAAQD,GAAKH,EACnCE,EAAOG,KAAKN,EAAIO,MAAMH,EAAGA,EAAIH,IAE/B,OAAOE,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectBy.js","sources":["../../../src/array/collectBy.ts"],"sourcesContent":["/**\n * Splits a list into sub-lists based on a key returned from each item.\n *\n * @example\n * const result = collectBy(\n * [\n * { type: 'breakfast', item: '☕️' },\n * { type: 'lunch', item: '🌯' },\n * { type: 'dinner', item: '🍝' },\n * { type: 'breakfast', item: '🥐' },\n * { type: 'lunch', item: '🍕' }\n * ],\n * (item) => item.type\n * );\n *\n * @param list Array of items\n * @param fn Function that extracts a key from each item\n * @returns Array of groups, each group containing items with same key\n */\nexport function collectBy<T, K extends string | number | symbol>(\n list: T[],\n fn: (item: T) => K\n): T[][] {\n const groups: Record<K, T[]> = {} as Record<K, T[]>;\n\n for (const item of list) {\n const key = fn(item);\n\n if (!groups[key]) {\n groups[key] = [];\n }\n\n groups[key].push(item);\n }\n\n return Object.values(groups);\n}\n"],"names":["collectBy","list","fn","groups","item","key","push","Object","values"],"mappings":"AAmBM,SAAUA,EACdC,EACAC,GAEA,MAAMC,EAAyB,CAAA,EAE/B,IAAK,MAAMC,KAAQH,EAAM,CACvB,MAAMI,EAAMH,EAAGE,GAEVD,EAAOE,KACVF,EAAOE,GAAO,IAGhBF,EAAOE,GAAKC,KAAKF,EACnB,CAEA,OAAOG,OAAOC,OAAOL,EACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.js","sources":["../../../src/array/compact.ts"],"sourcesContent":["/**\n * Removes all falsy values (false, null, 0, '', undefined, NaN) from an array.\n * Returns a properly narrowed type excluding falsy values.\n *\n * @example\n * compact([0, 1, false, 2, '', 3, null, undefined, NaN])\n * // [1, 2, 3]\n *\n * @example\n * compact(['hello', '', 'world', null])\n * // ['hello', 'world']\n *\n * @param arr - Array to compact\n * @returns New array without falsy values\n */\ntype Falsy = false | null | undefined | 0 | '' | 0n;\n\nexport function compact<T>(arr: readonly (T | Falsy)[]): Exclude<T, Falsy>[] {\n return arr.filter(Boolean) as Exclude<T, Falsy>[];\n}\n"],"names":["compact","arr","filter","Boolean"],"mappings":"AAiBM,SAAUA,EAAWC,GACzB,OAAOA,EAAIC,OAAOC,QACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countBy.js","sources":["../../../src/array/countBy.ts"],"sourcesContent":["/**\n * Counts occurrences of each item based on a transformation function.\n *\n * @example\n * countBy(['a', 'b', 'a', 'c', 'b', 'a'], x => x) // { a: 3, b: 2, c: 1 }\n * countBy([1, 2, 3, 4, 5], x => x % 2 === 0 ? 'even' : 'odd') // { odd: 3, even: 2 }\n *\n * @param arr - Array to count\n * @param fn - Function that returns the group key for each item\n * @returns Object with keys and their counts\n */\nexport function countBy<T>(\n arr: readonly T[],\n fn: (item: T) => string | number\n): Record<string, number> {\n const result: Record<string, number> = {};\n for (const item of arr) {\n const key = String(fn(item));\n result[key] = (result[key] || 0) + 1;\n }\n return result;\n}\n"],"names":["countBy","arr","fn","result","item","key","String"],"mappings":"AAWM,SAAUA,EACdC,EACAC,GAEA,MAAMC,EAAiC,CAAA,EACvC,IAAK,MAAMC,KAAQH,EAAK,CACtB,MAAMI,EAAMC,OAAOJ,EAAGE,IACtBD,EAAOE,IAAQF,EAAOE,IAAQ,GAAK,CACrC,CACA,OAAOF,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"difference.js","sources":["../../../src/array/difference.ts"],"sourcesContent":["/**\n * Returns elements from the first array that are not in the second array.\n *\n * @example\n * difference([1, 2, 3, 4], [2, 4]) // [1, 3]\n * difference(['a', 'b', 'c'], ['b']) // ['a', 'c']\n * difference([1, 2], [1, 2]) // []\n *\n * @param arr1 - Source array\n * @param arr2 - Array of elements to exclude\n * @returns Array of elements only in arr1\n */\nexport function difference<T>(arr1: readonly T[], arr2: readonly T[]): T[] {\n const set = new Set(arr2);\n return arr1.filter((item) => !set.has(item));\n}\n"],"names":["difference","arr1","arr2","set","Set","filter","item","has"],"mappings":"AAYM,SAAUA,EAAcC,EAAoBC,GAChD,MAAMC,EAAM,IAAIC,IAAIF,GACpB,OAAOD,EAAKI,OAAQC,IAAUH,EAAII,IAAID,GACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop.js","sources":["../../../src/array/drop.ts"],"sourcesContent":["/**\n * Returns all but the first n elements of an array.\n *\n * @example\n * drop([1, 2, 3, 4, 5], 2) // [3, 4, 5]\n * drop([1, 2], 5) // []\n * drop([], 3) // []\n *\n * @param arr - Source array\n * @param n - Number of elements to drop\n * @returns New array without the first n elements\n */\nexport function drop<T>(arr: readonly T[], n: number): T[] {\n return arr.slice(Math.max(0, n));\n}\n"],"names":["drop","arr","n","slice","Math","max"],"mappings":"AAYM,SAAUA,EAAQC,EAAmBC,GACzC,OAAOD,EAAIE,MAAMC,KAAKC,IAAI,EAAGH,GAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropWhile.js","sources":["../../../src/array/dropWhile.ts"],"sourcesContent":["/**\n * Drops leading elements while predicate returns true, returns the rest.\n *\n * @example\n * dropWhile([1, 2, 3, 4, 1], x => x < 3) // [3, 4, 1]\n * dropWhile([5, 4, 3], x => x > 3) // [3]\n *\n * @param arr - Source array\n * @param fn - Predicate function\n * @returns New array without leading elements that pass the predicate\n */\nexport function dropWhile<T>(arr: readonly T[], fn: (item: T, index: number) => boolean): T[] {\n const idx = arr.findIndex((item, i) => !fn(item, i));\n return idx === -1 ? [] : arr.slice(idx);\n}\n"],"names":["dropWhile","arr","fn","idx","findIndex","item","i","slice"],"mappings":"AAWM,SAAUA,EAAaC,EAAmBC,GAC9C,MAAMC,EAAMF,EAAIG,UAAU,CAACC,EAAMC,KAAOJ,EAAGG,EAAMC,IACjD,OAAe,IAARH,EAAa,GAAKF,EAAIM,MAAMJ,EACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first.js","sources":["../../../src/array/first.ts"],"sourcesContent":["/**\n * Returns the first element of an array, or undefined if empty.\n *\n * @example\n * first([1, 2, 3]) // 1\n * first([]) // undefined\n * first(['a', 'b']) // 'a'\n *\n * @param arr - Source array\n * @returns First element or undefined\n */\nexport function first<T>(arr: readonly T[]): T | undefined {\n return arr[0];\n}\n"],"names":["first","arr"],"mappings":"AAWM,SAAUA,EAASC,GACvB,OAAOA,EAAI,EACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.js","sources":["../../../src/array/flatten.ts"],"sourcesContent":["/**\n * Flattens a nested array by one level.\n *\n * @example\n * flatten([[1, 2], [3, 4], [5]]) // [1, 2, 3, 4, 5]\n * flatten([[1, [2]], [3]]) // [1, [2], 3]\n * flatten([]) // []\n *\n * @param arr - Nested array to flatten\n * @returns Flattened array (one level)\n */\nexport function flatten<T>(arr: readonly (T | readonly T[])[]): T[] {\n return arr.flat() as T[];\n}\n"],"names":["flatten","arr","flat"],"mappings":"AAWM,SAAUA,EAAWC,GACzB,OAAOA,EAAIC,MACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupBy.js","sources":["../../../src/array/groupBy.ts"],"sourcesContent":["/**\n * Groups array elements by the result of a function.\n *\n * @example\n * groupBy([1, 2, 3, 4], x => x % 2 === 0 ? 'even' : 'odd')\n * // { odd: [1, 3], even: [2, 4] }\n *\n * @example\n * groupBy([{ type: 'a' }, { type: 'b' }, { type: 'a' }], x => x.type)\n * // { a: [{ type: 'a' }, { type: 'a' }], b: [{ type: 'b' }] }\n *\n * @param list - Array to group\n * @param fn - Function to determine group key\n * @returns Object with grouped arrays\n */\nexport function groupBy<T>(\n list: T[],\n fn: (item: T) => string\n): Record<string, T[]> {\n return list.reduce(\n (acc, item) => {\n const key = fn(item);\n if (!acc[key]) {\n acc[key] = [];\n }\n acc[key].push(item);\n return acc;\n },\n {} as Record<string, T[]>\n );\n}\n"],"names":["groupBy","list","fn","reduce","acc","item","key","push"],"mappings":"AAeM,SAAUA,EACdC,EACAC,GAEA,OAAOD,EAAKE,OACV,CAACC,EAAKC,KACJ,MAAMC,EAAMJ,EAAGG,GAKf,OAJKD,EAAIE,KACPF,EAAIE,GAAO,IAEbF,EAAIE,GAAKC,KAAKF,GACPD,GAET,CAAA,EAEJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export{chunk}from"./chunk.js";export{compact}from"./compact.js";export{countBy}from"./countBy.js";export{difference}from"./difference.js";export{drop}from"./drop.js";export{dropWhile}from"./dropWhile.js";export{first}from"./first.js";export{flatten}from"./flatten.js";export{groupBy}from"./groupBy.js";export{intersection}from"./intersection.js";export{keyBy}from"./keyBy.js";export{last}from"./last.js";export{maxBy}from"./maxBy.js";export{minBy}from"./minBy.js";export{partition}from"./partition.js";export{sample}from"./sample.js";export{shuffle}from"./shuffle.js";export{sortBy}from"./sortBy.js";export{take}from"./take.js";export{takeWhile}from"./takeWhile.js";export{union}from"./union.js";export{uniq}from"./uniq.js";export{uniqBy}from"./uniqBy.js";export{without}from"./without.js";export{xor}from"./xor.js";export{zip}from"./zip.js";export{zipObject}from"./zipObject.js";export{collectBy}from"./collectBy.js";export{checkValueInArray}from"./checkValueInArray.js";export{sameElementsInArrays}from"./sameElementsInArrays.js";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersection.js","sources":["../../../src/array/intersection.ts"],"sourcesContent":["/**\n * Returns elements that exist in both arrays.\n *\n * @example\n * intersection([1, 2, 3], [2, 3, 4]) // [2, 3]\n * intersection(['a', 'b'], ['b', 'c']) // ['b']\n * intersection([1, 2], [3, 4]) // []\n *\n * @param arr1 - First array\n * @param arr2 - Second array\n * @returns Array of common elements\n */\nexport function intersection<T>(arr1: readonly T[], arr2: readonly T[]): T[] {\n const set = new Set(arr2);\n return arr1.filter((item) => set.has(item));\n}\n"],"names":["intersection","arr1","arr2","set","Set","filter","item","has"],"mappings":"AAYM,SAAUA,EAAgBC,EAAoBC,GAClD,MAAMC,EAAM,IAAIC,IAAIF,GACpB,OAAOD,EAAKI,OAAQC,GAASH,EAAII,IAAID,GACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyBy.js","sources":["../../../src/array/keyBy.ts"],"sourcesContent":["/**\n * Creates an object composed of keys generated from the results of running\n * each element through the iteratee. The value of each key is the last\n * element responsible for generating the key.\n *\n * @example\n * keyBy([{ id: 'a1', name: 'Alice' }, { id: 'b2', name: 'Bob' }], item => item.id)\n * // { a1: { id: 'a1', name: 'Alice' }, b2: { id: 'b2', name: 'Bob' } }\n *\n * @param arr - Array to index\n * @param fn - Function that returns the key for each element\n * @returns Object indexed by the generated keys\n */\nexport function keyBy<T>(\n arr: readonly T[],\n fn: (item: T) => string | number\n): Record<string | number, T> {\n const result: Record<string | number, T> = {};\n for (const item of arr) {\n result[fn(item)] = item;\n }\n return result;\n}\n"],"names":["keyBy","arr","fn","result","item"],"mappings":"AAaM,SAAUA,EACdC,EACAC,GAEA,MAAMC,EAAqC,CAAA,EAC3C,IAAK,MAAMC,KAAQH,EACjBE,EAAOD,EAAGE,IAASA,EAErB,OAAOD,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"last.js","sources":["../../../src/array/last.ts"],"sourcesContent":["/**\n * Returns the last element of an array, or undefined if empty.\n *\n * @example\n * last([1, 2, 3]) // 3\n * last([]) // undefined\n * last(['a', 'b']) // 'b'\n *\n * @param arr - Source array\n * @returns Last element or undefined\n */\nexport function last<T>(arr: readonly T[]): T | undefined {\n return arr[arr.length - 1];\n}\n"],"names":["last","arr","length"],"mappings":"AAWM,SAAUA,EAAQC,GACtB,OAAOA,EAAIA,EAAIC,OAAS,EAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maxBy.js","sources":["../../../src/array/maxBy.ts"],"sourcesContent":["/**\n * Returns the element with the maximum value as determined by a function.\n *\n * @example\n * maxBy([{ age: 30 }, { age: 20 }, { age: 25 }], x => x.age) // { age: 30 }\n * maxBy([], x => x) // undefined\n *\n * @param arr - Array to search\n * @param fn - Function that returns a numeric value for comparison\n * @returns Element with the maximum value, or undefined if empty\n */\nexport function maxBy<T>(arr: readonly T[], fn: (item: T) => number): T | undefined {\n if (arr.length === 0) return undefined;\n let max = arr[0];\n let maxVal = fn(arr[0]);\n for (let i = 1; i < arr.length; i++) {\n const val = fn(arr[i]);\n if (val > maxVal) {\n max = arr[i];\n maxVal = val;\n }\n }\n return max;\n}\n"],"names":["maxBy","arr","fn","length","max","maxVal","i","val"],"mappings":"AAWM,SAAUA,EAASC,EAAmBC,GAC1C,GAAmB,IAAfD,EAAIE,OAAc,OACtB,IAAIC,EAAMH,EAAI,GACVI,EAASH,EAAGD,EAAI,IACpB,IAAK,IAAIK,EAAI,EAAGA,EAAIL,EAAIE,OAAQG,IAAK,CACnC,MAAMC,EAAML,EAAGD,EAAIK,IACfC,EAAMF,IACRD,EAAMH,EAAIK,GACVD,EAASE,EAEb,CACA,OAAOH,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minBy.js","sources":["../../../src/array/minBy.ts"],"sourcesContent":["/**\n * Returns the element with the minimum value as determined by a function.\n *\n * @example\n * minBy([{ age: 30 }, { age: 20 }, { age: 25 }], x => x.age) // { age: 20 }\n * minBy([], x => x) // undefined\n *\n * @param arr - Array to search\n * @param fn - Function that returns a numeric value for comparison\n * @returns Element with the minimum value, or undefined if empty\n */\nexport function minBy<T>(arr: readonly T[], fn: (item: T) => number): T | undefined {\n if (arr.length === 0) return undefined;\n let min = arr[0];\n let minVal = fn(arr[0]);\n for (let i = 1; i < arr.length; i++) {\n const val = fn(arr[i]);\n if (val < minVal) {\n min = arr[i];\n minVal = val;\n }\n }\n return min;\n}\n"],"names":["minBy","arr","fn","length","min","minVal","i","val"],"mappings":"AAWM,SAAUA,EAASC,EAAmBC,GAC1C,GAAmB,IAAfD,EAAIE,OAAc,OACtB,IAAIC,EAAMH,EAAI,GACVI,EAASH,EAAGD,EAAI,IACpB,IAAK,IAAIK,EAAI,EAAGA,EAAIL,EAAIE,OAAQG,IAAK,CACnC,MAAMC,EAAML,EAAGD,EAAIK,IACfC,EAAMF,IACRD,EAAMH,EAAIK,GACVD,EAASE,EAEb,CACA,OAAOH,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partition.js","sources":["../../../src/array/partition.ts"],"sourcesContent":["import type { Predicate } from '../types/index.js';\n\n/**\n * Partitions an array into two arrays based on a predicate.\n *\n * @example\n * partition([1, 2, 3, 4], x => x > 2) // [[3, 4], [1, 2]]\n *\n * @param list - Array to partition\n * @param predicate - Function to test each element\n * @returns Tuple of [passed, failed] arrays\n */\nexport function partition<T>(list: T[], predicate: Predicate<T>): [T[], T[]] {\n const passed: T[] = [];\n const failed: T[] = [];\n\n for (const item of list) {\n if (predicate(item)) {\n passed.push(item);\n } else {\n failed.push(item);\n }\n }\n\n return [passed, failed];\n}\n"],"names":["partition","list","predicate","passed","failed","item","push"],"mappings":"AAYM,SAAUA,EAAaC,EAAWC,GACtC,MAAMC,EAAc,GACdC,EAAc,GAEpB,IAAK,MAAMC,KAAQJ,EACbC,EAAUG,GACZF,EAAOG,KAAKD,GAEZD,EAAOE,KAAKD,GAIhB,MAAO,CAACF,EAAQC,EAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sameElementsInArrays.js","sources":["../../../src/array/sameElementsInArrays.ts"],"sourcesContent":["/**\n * Finds the first element that exists in all provided arrays.\n *\n * Works with any type (numbers, strings, booleans, etc.).\n *\n * @example\n * sameElementInMultipleArrays([1, 2, 3], [3, 4, 5], [3, 6]) // 3\n * sameElementInMultipleArrays(['a', 'b'], ['b', 'c'], ['b', 'd']) // 'b'\n * sameElementInMultipleArrays([1, 2], [3, 4]) // null\n *\n * @param {...T[][]} arrays - Two or more arrays to check\n * @returns {T | null} The first element found in all arrays, or `null` if none found\n */\nexport const sameElementsInArrays = <T>(...arrays: T[][]): T | null => {\n if (arrays.length === 0) return null;\n const [first, ...rest] = arrays;\n\n return first.find((item) => rest.every((arr) => arr.includes(item))) || null;\n};\n"],"names":["sameElementsInArrays","arrays","length","first","rest","find","item","every","arr","includes"],"mappings":"MAaaA,EAAuB,IAAOC,KACzC,GAAsB,IAAlBA,EAAOC,OAAc,OAAO,KAChC,MAAOC,KAAUC,GAAQH,EAEzB,OAAOE,EAAME,KAAMC,GAASF,EAAKG,MAAOC,GAAQA,EAAIC,SAASH,MAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample.js","sources":["../../../src/array/sample.ts"],"sourcesContent":["/**\n * Returns a random element from an array.\n *\n * @example\n * sample([1, 2, 3, 4, 5]) // random element\n * sample(['a', 'b', 'c']) // random element\n *\n * @param arr - Source array\n * @returns Random element, or undefined if empty\n */\nexport function sample<T>(arr: readonly T[]): T | undefined {\n if (arr.length === 0) return undefined;\n return arr[Math.floor(Math.random() * arr.length)];\n}\n"],"names":["sample","arr","length","Math","floor","random"],"mappings":"AAUM,SAAUA,EAAUC,GACxB,GAAmB,IAAfA,EAAIC,OACR,OAAOD,EAAIE,KAAKC,MAAMD,KAAKE,SAAWJ,EAAIC,QAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shuffle.js","sources":["../../../src/array/shuffle.ts"],"sourcesContent":["/**\n * Returns a new array with elements in random order using Fisher-Yates algorithm.\n * Does not mutate the original array.\n *\n * @example\n * shuffle([1, 2, 3, 4, 5]) // [3, 1, 5, 2, 4] (random)\n *\n * @param arr - Array to shuffle\n * @returns New shuffled array\n */\nexport function shuffle<T>(arr: readonly T[]): T[] {\n const result = [...arr];\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [result[i], result[j]] = [result[j], result[i]];\n }\n return result;\n}\n"],"names":["shuffle","arr","result","i","length","j","Math","floor","random"],"mappings":"AAUM,SAAUA,EAAWC,GACzB,MAAMC,EAAS,IAAID,GACnB,IAAK,IAAIE,EAAID,EAAOE,OAAS,EAAGD,EAAI,EAAGA,IAAK,CAC1C,MAAME,EAAIC,KAAKC,MAAMD,KAAKE,UAAYL,EAAI,KACzCD,EAAOC,GAAID,EAAOG,IAAM,CAACH,EAAOG,GAAIH,EAAOC,GAC9C,CACA,OAAOD,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortBy.js","sources":["../../../src/array/sortBy.ts"],"sourcesContent":["/**\n * Returns a new array sorted by the result of a function applied to each element.\n * Supports multiple sort keys with optional direction.\n * Does not mutate the original array.\n *\n * @example\n * sortBy([{ age: 30 }, { age: 20 }, { age: 25 }], item => item.age)\n * // [{ age: 20 }, { age: 25 }, { age: 30 }]\n *\n * @example\n * // Descending order\n * sortBy([3, 1, 2], x => -x)\n * // [3, 2, 1]\n *\n * @param arr - Array to sort\n * @param fn - Function that returns the value to sort by\n * @returns New sorted array\n */\nexport function sortBy<T>(\n arr: readonly T[],\n fn: (item: T) => number | string\n): T[] {\n return [...arr].sort((a, b) => {\n const va = fn(a);\n const vb = fn(b);\n if (va < vb) return -1;\n if (va > vb) return 1;\n return 0;\n });\n}\n"],"names":["sortBy","arr","fn","sort","a","b","va","vb"],"mappings":"AAkBM,SAAUA,EACdC,EACAC,GAEA,MAAO,IAAID,GAAKE,KAAK,CAACC,EAAGC,KACvB,MAAMC,EAAKJ,EAAGE,GACRG,EAAKL,EAAGG,GACd,OAAIC,EAAKC,GAAW,EAChBD,EAAKC,EAAW,EACb,GAEX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take.js","sources":["../../../src/array/take.ts"],"sourcesContent":["/**\n * Returns the first n elements of an array.\n *\n * @example\n * take([1, 2, 3, 4, 5], 3) // [1, 2, 3]\n * take([1, 2], 5) // [1, 2]\n * take([], 3) // []\n *\n * @param arr - Source array\n * @param n - Number of elements to take\n * @returns New array with first n elements\n */\nexport function take<T>(arr: readonly T[], n: number): T[] {\n return arr.slice(0, Math.max(0, n));\n}\n"],"names":["take","arr","n","slice","Math","max"],"mappings":"AAYM,SAAUA,EAAQC,EAAmBC,GACzC,OAAOD,EAAIE,MAAM,EAAGC,KAAKC,IAAI,EAAGH,GAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"takeWhile.js","sources":["../../../src/array/takeWhile.ts"],"sourcesContent":["/**\n * Returns leading elements while predicate returns true.\n *\n * @example\n * takeWhile([1, 2, 3, 4, 1], x => x < 3) // [1, 2]\n * takeWhile([5, 4, 3], x => x > 3) // [5, 4]\n *\n * @param arr - Source array\n * @param fn - Predicate function\n * @returns New array of leading elements passing the predicate\n */\nexport function takeWhile<T>(arr: readonly T[], fn: (item: T, index: number) => boolean): T[] {\n const result: T[] = [];\n for (let i = 0; i < arr.length; i++) {\n if (!fn(arr[i], i)) break;\n result.push(arr[i]);\n }\n return result;\n}\n"],"names":["takeWhile","arr","fn","result","i","length","push"],"mappings":"AAWM,SAAUA,EAAaC,EAAmBC,GAC9C,MAAMC,EAAc,GACpB,IAAK,IAAIC,EAAI,EAAGA,EAAIH,EAAII,QACjBH,EAAGD,EAAIG,GAAIA,GADcA,IAE9BD,EAAOG,KAAKL,EAAIG,IAElB,OAAOD,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.js","sources":["../../../src/array/union.ts"],"sourcesContent":["/**\n * Creates an array of unique values from two arrays.\n *\n * @example\n * union([1, 2, 3], [3, 4, 5]) // [1, 2, 3, 4, 5]\n * union(['a'], ['a', 'b']) // ['a', 'b']\n *\n * @param arr1 - First array\n * @param arr2 - Second array\n * @returns Array of unique values from both\n */\nexport function union<T>(arr1: readonly T[], arr2: readonly T[]): T[] {\n return [...new Set([...arr1, ...arr2])];\n}\n"],"names":["union","arr1","arr2","Set"],"mappings":"AAWM,SAAUA,EAASC,EAAoBC,GAC3C,MAAO,IAAI,IAAIC,IAAI,IAAIF,KAASC,IAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.js","sources":["../../../src/array/uniq.ts"],"sourcesContent":["/**\n * Returns a new array with duplicate values removed.\n * Optimized: Uses spread operator instead of Array.from to avoid extra iteration.\n *\n * @example\n * uniq([1, 2, 2, 3, 3, 4]) // [1, 2, 3, 4]\n *\n * @param list - Array to deduplicate\n * @returns New array with unique values\n */\nexport function uniq<T>(list: T[]): T[] {\n return [...new Set(list)];\n}\n"],"names":["uniq","list","Set"],"mappings":"AAUM,SAAUA,EAAQC,GACtB,MAAO,IAAI,IAAIC,IAAID,GACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniqBy.js","sources":["../../../src/array/uniqBy.ts"],"sourcesContent":["/**\n * Returns a new array with duplicate values removed based on a function.\n *\n * @example\n * uniqBy([{id: 1}, {id: 1}, {id: 2}], x => x.id) // [{id: 1}, {id: 2}]\n *\n * @param list - Array to deduplicate\n * @param fn - Function to determine uniqueness\n * @returns New array with unique values\n */\nexport function uniqBy<T>(list: T[], fn: (item: T) => unknown): T[] {\n const seen = new Set();\n return list.filter((item) => {\n const key = fn(item);\n if (seen.has(key)) {\n return false;\n }\n seen.add(key);\n return true;\n });\n}\n"],"names":["uniqBy","list","fn","seen","Set","filter","item","key","has","add"],"mappings":"AAUM,SAAUA,EAAUC,EAAWC,GACnC,MAAMC,EAAO,IAAIC,IACjB,OAAOH,EAAKI,OAAQC,IAClB,MAAMC,EAAML,EAAGI,GACf,OAAIH,EAAKK,IAAID,KAGbJ,EAAKM,IAAIF,IACF,IAEX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"without.js","sources":["../../../src/array/without.ts"],"sourcesContent":["/**\n * Returns a new array with specified values removed.\n *\n * @example\n * without([1, 2, 3, 4, 5], 2, 4) // [1, 3, 5]\n * without(['a', 'b', 'c'], 'b') // ['a', 'c']\n *\n * @param arr - Source array\n * @param values - Values to exclude\n * @returns New array without the specified values\n */\nexport function without<T>(arr: readonly T[], ...values: T[]): T[] {\n const set = new Set(values);\n return arr.filter(x => !set.has(x));\n}\n"],"names":["without","arr","values","set","Set","filter","x","has"],"mappings":"SAWgBA,EAAWC,KAAsBC,GAC/C,MAAMC,EAAM,IAAIC,IAAIF,GACpB,OAAOD,EAAII,OAAOC,IAAMH,EAAII,IAAID,GAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xor.js","sources":["../../../src/array/xor.ts"],"sourcesContent":["/**\n * Computes the symmetric difference — elements in either array but not both.\n *\n * @example\n * xor([1, 2, 3, 4], [3, 4, 5, 6]) // [1, 2, 5, 6]\n * xor(['a', 'b'], ['b', 'c']) // ['a', 'c']\n *\n * @param arr1 - First array\n * @param arr2 - Second array\n * @returns Elements present in one array but not both\n */\nexport function xor<T>(arr1: readonly T[], arr2: readonly T[]): T[] {\n const set1 = new Set(arr1);\n const set2 = new Set(arr2);\n return [\n ...arr1.filter(x => !set2.has(x)),\n ...arr2.filter(x => !set1.has(x)),\n ];\n}\n"],"names":["xor","arr1","arr2","set1","Set","set2","filter","x","has"],"mappings":"AAWM,SAAUA,EAAOC,EAAoBC,GACzC,MAAMC,EAAO,IAAIC,IAAIH,GACfI,EAAO,IAAID,IAAIF,GACrB,MAAO,IACFD,EAAKK,OAAOC,IAAMF,EAAKG,IAAID,OAC3BL,EAAKI,OAAOC,IAAMJ,EAAKK,IAAID,IAElC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.js","sources":["../../../src/array/zip.ts"],"sourcesContent":["/**\n * Combines two arrays into an array of tuples, pairing elements by index.\n * The result length is the shorter of the two arrays.\n *\n * @example\n * zip([1, 2, 3], ['a', 'b', 'c']) // [[1, 'a'], [2, 'b'], [3, 'c']]\n * zip([1, 2], ['a']) // [[1, 'a']]\n * zip([], [1, 2]) // []\n *\n * @param a - First array\n * @param b - Second array\n * @returns Array of tuples\n */\nexport function zip<A, B>(a: readonly A[], b: readonly B[]): [A, B][] {\n const length = Math.min(a.length, b.length);\n const result: [A, B][] = [];\n for (let i = 0; i < length; i++) {\n result.push([a[i], b[i]]);\n }\n return result;\n}\n"],"names":["zip","a","b","length","Math","min","result","i","push"],"mappings":"AAaM,SAAUA,EAAUC,EAAiBC,GACzC,MAAMC,EAASC,KAAKC,IAAIJ,EAAEE,OAAQD,EAAEC,QAC9BG,EAAmB,GACzB,IAAK,IAAIC,EAAI,EAAGA,EAAIJ,EAAQI,IAC1BD,EAAOE,KAAK,CAACP,EAAEM,GAAIL,EAAEK,KAEvB,OAAOD,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zipObject.js","sources":["../../../src/array/zipObject.ts"],"sourcesContent":["/**\n * Creates an object from arrays of keys and values.\n *\n * @example\n * zipObject(['a', 'b', 'c'], [1, 2, 3]) // { a: 1, b: 2, c: 3 }\n * zipObject(['x', 'y'], [10]) // { x: 10, y: undefined }\n *\n * @param keys - Array of keys\n * @param values - Array of values\n * @returns Object with keys mapped to values\n */\nexport function zipObject<K extends string | number, V>(\n keys: readonly K[],\n values: readonly V[]\n): Record<K, V | undefined> {\n const result = {} as Record<K, V | undefined>;\n for (let i = 0; i < keys.length; i++) {\n result[keys[i]] = values[i];\n }\n return result;\n}\n"],"names":["zipObject","keys","values","result","i","length"],"mappings":"AAWM,SAAUA,EACdC,EACAC,GAEA,MAAMC,EAAS,CAAA,EACf,IAAK,IAAIC,EAAI,EAAGA,EAAIH,EAAKI,OAAQD,IAC/BD,EAAOF,EAAKG,IAAMF,EAAOE,GAE3B,OAAOD,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anyToString.js","sources":["../../../src/file/anyToString.ts"],"sourcesContent":["/**\n * Converts a File or string value to a string suitable for usage in `src` or `href`.\n *\n * - If a `File` object is passed, it creates a temporary object URL using `URL.createObjectURL`.\n * - If a string is passed, it returns the value as-is.\n *\n * @example\n * // With a File object\n * const file = new File([\"Hello\"], \"hello.txt\");\n * const url = anyToString(file);\n * console.log(url);\n * // -> \"blob:http://localhost/...\" (temporary URL)\n *\n * @example\n * // With a string URL\n * const imageUrl = \"https://example.com/image.png\";\n * console.log(anyToString(imageUrl));\n * // -> \"https://example.com/image.png\"\n *\n * @param {File | string} value - The File or string to convert\n * @returns {string} A string representation or object URL for the file\n */\nexport const anyToString = (value: File | string): string => {\n if (value instanceof File) {\n return URL.createObjectURL(value);\n }\n return value;\n};\n"],"names":["anyToString","value","File","URL","createObjectURL"],"mappings":"AAsBO,MAAMA,EAAeC,GACtBA,aAAiBC,KACZC,IAAIC,gBAAgBH,GAEtBA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToFormData.js","sources":["../../../src/file/convertToFormData.ts"],"sourcesContent":["import { isFileArray } from './isFileArray.js';\n\n/**\n * Converts a plain object to FormData.\n * Supports string, number, boolean, File, Blob, or arrays of File/Blob.\n *\n * NOTE: Browser-only — requires FormData, File, Blob APIs.\n *\n * @example\n * const data = {\n * name: \"John\",\n * avatar: file, // single File\n * gallery: [file1, file2] // array of Files\n * };\n * const formData = convertToFormData(data);\n *\n * @param {Record<string, any>} data - The object to convert\n * @returns {FormData} FormData object ready for submission\n */\nexport const convertToFormData = <T extends Record<string, any>>(\n data: T\n): FormData => {\n const formData = new FormData();\n\n for (const key in data) {\n const value = data[key];\n\n if (value !== undefined && value !== null) {\n if (isFileArray(value)) {\n value.forEach((file: File | Blob) => {\n formData.append(key, file);\n });\n } else {\n formData.append(key, value as string | Blob);\n }\n }\n }\n\n return formData;\n};\n"],"names":["convertToFormData","data","formData","FormData","key","value","isFileArray","forEach","file","append"],"mappings":"+CAmBO,MAAMA,EACXC,IAEA,MAAMC,EAAW,IAAIC,SAErB,IAAK,MAAMC,KAAOH,EAAM,CACtB,MAAMI,EAAQJ,EAAKG,GAEfC,UACEC,EAAYD,GACdA,EAAME,QAASC,IACbN,EAASO,OAAOL,EAAKI,KAGvBN,EAASO,OAAOL,EAAKC,GAG3B,CAEA,OAAOH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeURIValue.js","sources":["../../../src/file/decodeURIValue.ts"],"sourcesContent":["/**\n * Extracts the file name from a URI or URL string.\n * Decodes the URI first, so escape sequences like `%20` become normal characters.\n * Returns an empty string if decoding fails or the path is invalid.\n *\n * @example\n * decodeURIValue('https://example.com/files/%D0%BF%D1%80%D0%B8%D0%BC%D0%B5%D1%80.pdf')\n * // → 'пример.pdf'\n *\n * @example\n * decodeURIValue('file:///C:/Users/John/Documents/file.txt')\n * // → 'file.txt'\n *\n * @example\n * decodeURIValue('invalid%URI')\n * // → ''\n *\n * @param {string} file - The URI or URL string to decode and extract the file name from\n * @returns {string} The decoded file name, or an empty string if decoding fails\n */\nexport const decodeURIValue = (file: string): string => {\n try {\n return decodeURI(file).split(\"/\").pop() || \"\";\n } catch {\n return \"\";\n }\n};\n"],"names":["decodeURIValue","file","decodeURI","split","pop"],"mappings":"AAoBO,MAAMA,EAAkBC,IAC7B,IACE,OAAOC,UAAUD,GAAME,MAAM,KAAKC,OAAS,EAC7C,CAAE,MACA,MAAO,EACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=async(e,o)=>{try{const c=await e(),n=document.createElement("a"),l=window.URL.createObjectURL(c);n.href=l,n.download=o,n.click(),window.URL.revokeObjectURL(l),console.log("File downloaded successfully!")}catch(e){console.error("Error downloading file!",e)}};export{e as downloadFile};
|
|
2
|
+
//# sourceMappingURL=downloadFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downloadFile.js","sources":["../../../src/file/downloadFile.ts"],"sourcesContent":["/**\n * Asynchronous utility to download a file in the browser.\n *\n * @param getData A function that returns a Promise resolving to a Blob object.\n * For example, this can be an API call using fetch or RTK Query.\n * @param fileName The name of the file that will be suggested to the user when downloading.\n *\n * @example\n * // Downloading a file from a server\n * downloadFile(() => fetch('/api/report').then(res => res.blob()), 'report.xlsx');\n *\n * @example\n * // Using with RTK Query\n * downloadFile(() => api.endpoints.getReport.initiate(params).unwrap(), 'report.xlsx');\n *\n * @example\n * // Generating a text file on the fly\n * downloadFile(\n * () => Promise.resolve(new Blob(['Hello World!'], { type: 'text/plain' })),\n * 'hello.txt'\n * );\n *\n * @remarks\n * The object URL is automatically revoked after downloading.\n * In case of an error, an error message is logged to the console.\n */\n\nexport const downloadFile = async (\n getData: () => Promise<Blob>,\n fileName: string\n) => {\n try {\n const blob = await getData();\n\n const anchor = document.createElement(\"a\");\n const objectUrl = window.URL.createObjectURL(blob);\n\n anchor.href = objectUrl;\n anchor.download = fileName;\n anchor.click();\n\n window.URL.revokeObjectURL(objectUrl);\n console.log(\"File downloaded successfully!\");\n } catch (err) {\n console.error(\"Error downloading file!\", err);\n }\n};\n"],"names":["downloadFile","async","getData","fileName","blob","anchor","document","createElement","objectUrl","window","URL","createObjectURL","href","download","click","revokeObjectURL","console","log","err","error"],"mappings":"AA2BO,MAAMA,EAAeC,MAC1BC,EACAC,KAEA,IACE,MAAMC,QAAaF,IAEbG,EAASC,SAASC,cAAc,KAChCC,EAAYC,OAAOC,IAAIC,gBAAgBP,GAE7CC,EAAOO,KAAOJ,EACdH,EAAOQ,SAAWV,EAClBE,EAAOS,QAEPL,OAAOC,IAAIK,gBAAgBP,GAC3BQ,QAAQC,IAAI,gCACd,CAAE,MAAOC,GACPF,QAAQG,MAAM,0BAA2BD,EAC3C"}
|