1.0.0 • Published 4 months ago

@validatem/is-ms v1.0.0

Weekly downloads
-
License
WTFPL OR CC0-1.0
Repository
-
Last release
4 months ago

@validatem/is-ms

This validator is designed to be used with Validatem, the universal and composable validation library.

Validates that a given input is a valid input to the ms library.

If you also wish to support number input directly, you can combine it with validators like @validatem/is-number and @validatem/is-integer using the @validatem/either combinator.

License, donations, and other boilerplate

Licensed under either the WTFPL or CC0, at your choice. In practice, that means it's more or less public domain, and you can do whatever you want with it. Giving credit is not required, but still very much appreciated! I'd love to hear from you if this module was useful to you.

Creating and maintaining open-source modules is a lot of work. A donation is also not required, but much appreciated! You can donate here.

Example

A runnable version of this example is included in the repository, as example.js.

"use strict";

const { validateValue } = require("@validatem/core");
const isMS = require("@validatem/is-ms");

console.log(validateValue("1m", isMS)); // 60
console.log(validateValue("nonsense", isMS)); // [validatem.is-ms.ms] Error: Must be a valid `ms`-compatible input (eg. '10m', '4h')
console.log(validateValue("", isMS)); // [validatem.is-ms.empty] Error: Must be a non-empty string
console.log(validateValue(false, isMS)); // [validatem.is-string] Error: Must be a string

API

If you are new to Validatem, please read the documentation on the Validatem website first - it will explain how the general API works, and how you should use validator modules with it.

isMS

Not callable. Validates that the input is a valid ms input. Returns the parsed time quantity (in milliseconds) as an integer Number.

Possible error codes:

  • validatem.is-ms.ms: The input was not a valid input to ms.
  • validatem.is-ms.empty: The input was an empty string.
  • validatem.is-string: The input was not a string at all.

Changelog

1.0.0 (February 9, 2025)

Initial release.

1.0.0

4 months ago