# @doubter/plugin-string-format

> String format validation plugin for Doubter.

Latest version **3.1.0** (published 2024-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @doubter/plugin-string-format
pnpm add @doubter/plugin-string-format
yarn add @doubter/plugin-string-format
bun add @doubter/plugin-string-format
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2024-10-25 |
| First published | 2023-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Savva Mikhalevski |
| Maintainers | smikhalevski |
| Keywords | doubter, plugin, string, format, bic, email, fqdn, imei, ip, isin, luhn, mime, uuid |

## Links

- npm: https://www.npmjs.com/package/@doubter/plugin-string-format
- Repository: https://github.com/smikhalevski/doubter-plugin-string-format
- Homepage: https://github.com/smikhalevski/doubter-plugin-string-format#readme
- Issues: https://github.com/smikhalevski/doubter-plugin-string-format/issues
- npm.io page: https://npm.io/package/@doubter/plugin-string-format

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2024-10-25
- 3.0.0 — 2024-06-11
- 2.0.0 — 2023-11-26
- 1.0.1 — 2023-09-19
- 1.0.0 — 2023-07-31

## README

# @doubter/plugin-string-format

String format validation [plugin for Doubter](https://github.com/smikhalevski/doubter).

- ASCII
- BIC
- Email
- Fully qualified domain name
- IMEI number
- IP
- ISIN
- Luhn algorithm
- MIME type
- UUID

```shell
npm install --save-prod doubter @doubter/plugin-string-format
```

🔎 [Check out the API Docs](https://smikhalevski.github.io/doubter-plugin-string-format)

# How to use?

Import and enable the plugin:

```ts
import * as d from 'doubter';
import '@doubter/plugin-string-format';

const emailShape = d.string().email();

emailShape.parse('foo@bar.com');
// ⮕ 'foo@bar.com'

emailShape.parse('foo');
// ❌ ValidationError: string.format.email at /: Must be an email
```

Or cherry-pick separate format checkers:

```ts
import * as d from 'doubter';
// 🟡 Import a single format module
import '@doubter/plugin-string-format/bic';

const bicShape = d.string().bic();

bicShape.parse('BOFAUS3N');
// ⮕ 'BOFAUS3N'

bicShape.parse('QUX');
// ❌ ValidationError: string.format.bic at /: Must be a BIC or SWIFT code
```

# Validation issues

Format checks raise issues with [`"string.format.*"`](./src/main/constants.ts) code.

```ts
d.string().email().try('foo');
```

The code above would return an `Err` result:

```json5
{
  ok: false,
  issues: [
    {
      code: 'string.format.email',
      input: 'foo',
      message: 'Must be an email',
      param: {
        allowDisplayName: false,
        allowIPDomain: false,
        allowUTF8LocalPart: true,
        blacklistedChars: '',
        hostBlacklist: [],
        hostWhitelist: [],
        ignoreMaxLength: false,
        requireDisplayName: false,
        requireTLD: true
      }
    }
  ]
}
```

# Localization

Provide [`messages`](https://smikhalevski.github.io/doubter/latest/interfaces/core.ParseOptions.html#messages) option
to parsing methods:

```ts
const emailShape = d.string().email();

emailShape.parse('foo', {
  messages: {
    'string.format.email': 'Invalid email'
  }
});
// ❌ ValidationError: string.format.email at /: Invalid email
```

Or pass a message directly to a plugin method:

```ts
d.string().email('Not an email').parse('foo');
// ❌ ValidationError: string.format.email at /: Not an email
```

More details in the [Localization](https://github.com/smikhalevski/doubter?tab=readme-ov-file#localization) section of
Doubter docs.

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