New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@doubter/plugin-string-format

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@doubter/plugin-string-format

String format validation plugin for Doubter.

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@doubter/plugin-string-format

String format validation plugin for Doubter.

  • ASCII
  • BIC
  • Email
  • Fully qualified domain name
  • IMEI number
  • IP
  • ISIN
  • Luhn algorithm
  • MIME type
  • UUID
npm install --save-prod doubter @doubter/plugin-string-format

🔎 Check out the API Docs

How to use?

Import and enable the plugin:

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:

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.*" code.

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

The code above would return an Err result:

{
  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 option to parsing methods:

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:

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

More details in the Localization section of Doubter docs.

Keywords

FAQs

Package last updated on 25 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc