# @aamirtech/utils

> Library packed with your basic code utils.

Latest version **0.1.7** (published 2025-10-08) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.7 |
| Published | 2025-10-08 |
| First published | 2024-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Aamir Khan |
| Maintainers | aamirkhan |
| Keywords | utils, id, generator, snowflake, email, validation, string, typescript |

## Links

- npm: https://www.npmjs.com/package/@aamirtech/utils
- Repository: https://github.com/aamirtech/utils
- Homepage: https://aamir.tech/utils
- Issues: https://github.com/aamirtech/utils/issues
- npm.io page: https://npm.io/package/@aamirtech/utils

## 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.1.7 (latest) — 2025-10-08
- 0.1.6 — 2024-12-03
- 0.1.5 — 2024-10-16

## README

[![aamirtech](https://aamir.tech/favicon.ico)](https://aamir.tech)

# @aamirtech/utils

[![GitHub license](https://img.shields.io/npm/l/%40aamirtech%2Futils)](https://github.com/aamirtech/utils/blob/main/LICENSE)
[![Maintainer](https://img.shields.io/badge/maintainer-aamirv1-green)](https://github.com/aamirv1)
[![Downloads](https://img.shields.io/npm/dm/%40aamirtech%2Futils)](https://www.npmjs.com/package/@aamirtech/utils)
[![Npm package version](https://img.shields.io/npm/v/%40aamirtech%2Futils)](https://npmjs.com/@aamirtech/utils)

Library packed with your basic code utils.

## Documentation

The documentation is available at [aamir.tech](https://aamir.tech/docs/utils).

## Installation

Install with npm

```bash
  npm install @aamirtech/utils
```

Install with yarn

```bash
  yarn add @aamirtech/utils
```

Install with bun

```bash
  bun add @aamirtech/utils
```

## Usage

#### All utility functions use snake_case naming:

```javascript
import {
  snowflake,           // lowercase object name (with backward compatibility)
  Snowflake,           // alias for backward compatibility
  get_public_id,
  get_initials,
  is_email,
  get_sanitized_email,
  get_base_email,
  to_title_case,
  to_camel_case,
  to_pascal_case,
  to_snake_case,
  to_kebab_case
} from "@aamirtech/utils";
```

#### Snowflake ID Generation

```javascript
// Preferred lowercase naming
console.log(snowflake.generate());
// 7167216930510602240

console.log(snowflake.generate(1));
// 7167216930510602241

// Parse snowflake components
const id = snowflake.generate(1);
const parsed = snowflake.parse(id);
console.log(parsed.nodeId); // 1

// Backward compatibility also supported
console.log(Snowflake.generate()); // Still works
```

#### Public ID Generation

```javascript
// Generate 6-character alphanumeric ID (default)
get_public_id(); // "A3B9C2"

// Generate 10-character numeric ID
get_public_id(10, { numeric: true, alphabetic: false }); // "1234567890"

// Generate 8-character alphabetic ID
get_public_id(8, { numeric: false, alphabetic: true }); // "ABCDEFGH"
```

#### Email Validation

```javascript
// Standard email addresses
is_email("user@example.com"); // true
is_email("test.email@domain.org"); // true

// Plus addressing (email filtering/sub-addressing)
is_email("user+newsletter@example.com"); // true
is_email("user+tag123@domain.co.uk"); // true
is_email("test.user+promo@sub.domain.com"); // true
is_email("email+123456789@company.org"); // true

// Invalid emails
is_email("invalid-email"); // false
is_email("user@"); // false
is_email("@example.com"); // false
is_email("+tag@example.com"); // false (plus at start)
is_email("user+@example.com"); // false (plus at end)
```

#### Email Sanitization

```javascript
// Remove plus addressing and normalize email
get_sanitized_email("user+123456789@company.org"); // "user@company.org"
get_sanitized_email("test.user+newsletter@DOMAIN.COM"); // "test.user@domain.com"

// Handle multiple plus signs and dots
get_sanitized_email("user+tag1+tag2@sub.domain.com"); // "user@sub.domain.com"
get_sanitized_email("user..name@domain.com"); // "user.name@domain.com"
get_sanitized_email(".user.name.@domain.com"); // "user.name@domain.com"

// Remove subdomains (optional)
get_sanitized_email("user@sub.domain.com", { keepSubdomains: false }); // "user@domain.com"

// Simple alias for common use case
get_base_email("user+123456789@company.org"); // "user@company.org"
```

#### Initials Extraction

```javascript
get_initials("John Doe"); // "JD"
get_initials("Alice Mary Smith"); // "AS"
get_initials("Bob"); // "B"
get_initials("Mary-Jane Watson"); // "MW"
```

#### String Case Conversion

```javascript
to_title_case("hello_world"); // "Hello World"
to_camel_case("hello_world"); // "helloWorld"
to_pascal_case("hello_world"); // "HelloWorld"
to_snake_case("Hello World"); // "hello_world"
to_kebab_case("Hello World"); // "hello-world"
```

## Tests

Tests are written in Bun Test. To run tests, run the following command:

```bash
  bun test
```

To run tests with coverage, run the following command:

```bash
  bun test:coverage
```

## License

[MIT](https://choosealicense.com/licenses/mit/)

The project contains part based on a fork off of (snowflake-generator)[https://github.com/FatAussieFatBoy/snowflake-generator].

```

```

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