# @hyurl/utils

> Utility functions of HyURL collection.

Latest version **0.3.15** (published 2024-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hyurl/utils
pnpm add @hyurl/utils
yarn add @hyurl/utils
bun add @hyurl/utils
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.15 |
| Published | 2024-02-27 |
| First published | 2020-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 2 |
| Unpacked size | 282.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | A-yon Lee |
| Maintainers | ayonli |
| Keywords | count, define, diff, ensureType, flatObject, getGlobal, isEmpty, isVoid, keysOf, omit, omitVoid, patch, pick, sort, split, timestamp, trim, typeOf |

## Links

- npm: https://www.npmjs.com/package/@hyurl/utils
- Repository: https://github.com/hyurl/utils
- Homepage: https://github.com/hyurl/utils#readme
- Issues: https://github.com/hyurl/utils/issues
- npm.io page: https://npm.io/package/@hyurl/utils

## Dependencies (2)

- [is-like](https://npm.io/package/is-like.md) ^0.1.13
- [@ayonli/jsext](https://npm.io/package/@ayonli/jsext.md) ^0.7.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.15 (latest) — 2024-02-27
- 0.3.14 — 2024-02-26
- 0.3.13 — 2024-01-18
- 0.3.12 — 2024-01-08
- 0.3.11 — 2023-10-03
- 0.3.10 — 2023-10-03
- 0.3.6 — 2023-09-27
- 0.3.5 — 2023-09-26
- 0.3.4 — 2023-09-22
- 0.3.3 — 2023-09-18
- 0.3.2 — 2023-09-18
- 0.3.1 — 2023-09-17
- 0.3.0 — 2023-09-17
- 0.2.26 — 2022-11-28
- 0.2.25 — 2022-05-18
- … 56 more at https://npm.io/package/@hyurl/utils/versions

## README

# HyURL Utilities

**Utility functions of HyURL collection.**

This package currently contains the following functions, more functions may be
included in the future. Each function is stored in a separated file.

- `count` [.ts](./count.ts)
- `define` [.ts](./define.ts)
- `diff` [.ts](./diff.ts)
- `ensureType` [.ts](./ensureType.ts)
- `flatObject` [.ts](./flatObject.ts)
- `getGlobal` [.ts](./getGlobal.ts)
- `isEmpty` [.ts](./isEmpty.ts)
- `keysOf` [.ts](./keysOf.ts)
- `omitInvalid` [.ts](./omitInvalid.ts)
- `patch` [.ts](./patch.ts)
- `sort` [.ts](./sort.ts)
- `split` [.ts](./split.ts)
- `timestamp` [.ts](./timestamp.ts)
- `trim` [.ts](./trim.ts)
- `typeOf` [.ts](./typeOf.ts)

**Deprecated**

Since v0.3.0, the following functions have been merged to [@ayonli/jsext](https://github.com/ayonli/jsext).
The two packages serve different purposes, while **@ayonli/jsext** provides basic and semantic APIs
for the JavaScript language, **@hyurl/utils** provides higher level functions that deal with objects.

This package still keeps a link to these functions, but they have been marked __deprecated__ and
will be removed in v0.4.0.

- `isFloat` use `isFloat` from `@ayonli/jsext/number` instead.
- `isInteger` use `Number.isInteger` instead.
- `isNumeric` use `isNumeric` from `@ayonli/jsext/number` instead.
- `isBetween` use `isBetween` from `@ayonli/jsext/number` instead.
- `isOwnKey` use `hasOwn` from `@ayonli/jsext/object` instead.
- `isOwnMethod` use `hasOwnMethod` from `@ayonli/jsext/object` instead.
- `isSubClassOf` use `jsext.isSubclassOf` from `@ayonli/jsext` instead.
- `isVoid` use `!isValid` from `@ayonli/jsext/object` instead.
- `omit` use `omit` from `@ayonli/jsext/object` instead.
- `pick` use `pick` from `@ayonli/jsext/object` instead.
- `omitVoid` use `omitInvalid` instead.
- `rand` use `random` from `@ayonli/jsext/number` instead.
- `randStr` use `random` from `@ayonli/jsext/string` instead.
- `sleep` use `sleep` from `@ayonli/jsext/promise` instead.
- `typeAs` use `as` from `@ayonli/jsext/object` instead.
- `until` use `until` from `@ayonli/jsext/promise` instead.
- `useThrottle` use `jsext.throttle` from `@ayonli/jsext` instead.
- `wrap` use `jsext.wrap` from `@ayonli/jsext` instead.

## Import

There are many ways to import these functions.

### All At Once

This method will load all functions into memory, even if you don't need some of
them.

```js
// Node.js
import * as utils from "@hyurl/utils";

// Deno
import * as utils from "https://lib.deno.dev/x/hyurl_utils@latest/index.ts";

// Browser
import * as utils from "https://lib.deno.dev/x/hyurl_utils@latest/esm/index.js";
```

### Only Needed

This method will only load needed functions, which is recommended.

```js
// Node.js
import count from "@hyurl/utils/count";
import ensureType from "@hyurl/utils/ensureType";

// Deno
import count from "https://lib.deno.dev/x/hyurl_utils@latest/count.ts";
import ensureType from "https://lib.deno.dev/x/hyurl_utils@latest/ensureType.ts";

// Browser
import count from "https://lib.deno.dev/x/hyurl_utils@latest/esm/count.js";
import ensureType from "https://lib.deno.dev/x/hyurl_utils@latest/esm/ensureType.js";
```

**NOTE:** Configure `tsconfig.json` to set `compilerOptions.module` as `NodeNext` or `ESNext`
instead of `CommonJS` for this to work with Node.js+TypeScript.

### Load Bundle (browser only)

```html
<script src="https://lib.deno.dev/x/hyurl_utils@latest/bundle/index.js"></script>
<script>
    const utils = window["@hyurl/utils"];
<script>
```

## Utilities Types

Other than utility functions, this package also provides some utility types for
TypeScript, they are located in the following file and exposed to the global
namespace.

- [types.ts](./types.ts)

```ts
import "@hyurl/utils/types";
```

---
_Source: https://npm.io/package/@hyurl/utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
