Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Apr 23, 2024 via pnpm

type 2.7.2

Runtime validation and processing of JavaScript types
Package summary
Share
0
issues
1
license
1
ISC
Package created
9 Jun 2011
Version published
5 Aug 2022
Maintainers
1
Total deps
1
Direct deps
0
License
ISC

Issues

0
This package has no issues

Licenses

ISC License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
type@2.7.2
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of type 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does type do?

The "type" package is a highly valuable tool used for the runtime validation and processing of JavaScript types. The package caters to the requirements of the JavaScript language, acknowledging its quirks and ensuring strict adherence to type consistency. The type package does not enforce transpilation, making it compatible with ECMAScript 3 and later editions. A notable feature of this package is that it enables restrained type coercion, rejecting any invalid inputs while normalizing minor type deviations that are acceptable. One of the primary uses of "type" is to validate arguments input in public API endpoints.

How do you use type?

The "type" package can be used seamlessly by installing it using npm with the command npm install type and then by importing it within your JavaScript file. Here is an example of how to use the type package:

const ensureString        = require('type/string/ensure')
    , ensureDate          = require('type/date/ensure')
    , ensureNaturalNumber = require('type/natural-number/ensure')
    , isObject            = require('type/object/is');

module.exports = (path, options = { min: 0 }) {
  path = ensureString(path, { errorMessage: "%v is not a path" });
  if (!isObject(options)) options = {};
  const min = ensureNaturalNumber(options.min, { default: 0 })
      , max = ensureNaturalNumber(options.max, { isOptional: true })
      , startTime = ensureDate(options.startTime, { isOptional: true });

  // ...logic
};

In the example above, the ensureString function is used to confirm that the 'path' variable is indeed a string, displaying an error message if it is not. ensureDate validates that the 'startTime' is a legitimate Date object and if the 'options' variable is not an object, it is set to an empty object.

Where are the type docs?

For in-depth usage instructions, documentation on utilities and extensive examples, you can refer to the documentation on GitHub. This includes general utilities like ensure, is and coerce, type-specific utilities for values like String, Number, BigInt, Array, Map, Date, Function, Error, Prototype, and others. Each of these utilities includes specific usage instructions and examples for a more comprehensive understanding.