Skip to content

dotherightthing/dtrt-type-validate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dtrt-type-validate

Validate that a variable is of a certain data type.

Dependencies

Usage

npm install dotherightthing/dtrt-type-validate

CommonJS (via Conditional Export)

// script.cjs

const dtrtValidate = require('dtrt-type-validate');

ESM (via Conditional Export)

// script.mjs

import dtrtValidate from 'dtrt-type-validate';

ESM + Browser

<!-- page.html -->

<!-- use import-maps to aid module resolution of bare import specifiers -->
<script type="importmap">
  {
    "imports": {
      "dtrt-string-utils": "./node_modules/dtrt-string-utils/dist/dtrt-string-utils.mjs",
      "dtrt-type-validate": "./node_modules/dtrt-type-validate/dist/dtrt-type-validate.mjs"
    }
  }
</script>
<script src="/script.mjs" type="module"></script>

Methods

// script.cjs/.mjs

const foo = (param) => {
  const validObject = dtrtValidate.validate(param, 'object', 'myFunc');
  
  // do something with validObject
};

const bar = (param) => {
  if (dtrtValidate.isArray(param)) {
    // do something with param which is an array
  }
};

Tests

npm run lint
npm run test

References

About

Validate that a variable is of a certain data type.

Resources

License

Stars

Watchers

Forks