Detalhes do pacote

type-enforcer

DarrenPaulWright801MIT1.2.7

A type enforcement library for javascript

type, enforce, method, assert

readme (leia-me)

Type Enforcer

A type enforcement library for javascript

npm build coverage deps size vulnerabilities license


Installation

npm install type-enforcer

Requires Babel 7.2+


Objects

assert : object

An assertion library for testing. Assertions do nothing if the test passes, and throw an AssertionError if they fail.

is : object

Utility functions for checking if a value is a particular data type.

enforce : object

Utility functions for enforcing data types.

method : object

Enforce data types and remove common boilerplate code on class methods.


Classes

Enum

Freezes an enumerable object and adds a few helper methods

Queue

A simple queue for callbacks that allows for adding, removing, and triggering all or specific callbacks

Removable

A mixin that adds methods to a class to facilitate clean-up

PrivateVars

A thin wrapper over WeakMap for storing private variables


Functions

abstractEquality(a, b)boolean

Performs an abstract equality check (==) between two values.

sameValue(a, b)boolean

Performs a SameValue equality check (Object.is) between two values.

sameValueZero(a, b)boolean

Performs a SameValueZero equality check between two values.

strictEquality(a, b)boolean

Performs a strict equality check (===) between two values.

applySettings(target, settings, [priority], [deferred])

Iterates over the provided settings and calls any methods of the same name, passing the value in as the argument.

castArray(value)Array

Casts a value to an array.

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning

[1.2.0] - 2020-07-14

Added

  • Queue can discard a callback by reference to the callback

Changed

  • Queue will stop calling further callbacks ona trigger if true is returned from a callback.

1.1.0 - 2020-02-14

Added

  • isPromise, enforcePromise, methodPromise
  • assert

1.0.6 - 2020-01-15

Security

  • Updated dependencies

1.0.5 - 2019-12-26

Security

  • Updated dependencies

1.0.4 - 2019-12-08

Security

  • Updated dependencies

1.0.3 - 2019-12-08

Security

  • Updated dependencies

1.0.2 - 2019-12-06

Security

  • Updated dependencies

1.0.0 - 2019-12-04

Added

  • isSymbol, enforceSymbol, methodSymbol
  • isMap, enforceMap, methodMap
  • isWeakMap, enforceWeakMap, methodWeakMap
  • isSet, enforceSet, methodSet
  • isWeakSet, enforceWeakSet, methodWeakSet

Changed

  • enforceInstance is now enforceInstanceOf and methodInstance is methodInstanceOf
  • Various performance improvements

Removed

  • privateProp
  • Moved CssSize, DockPoint, Thickness, and Element classes and functions to new type-enforcer-ui
  • Moved Point and Vector classes and functions to new type-enforcer-math
  • Queue no longer stores extra data with a callback

0.6.4 - 2019-10-22

Security

  • Updated dependencies

0.6.3 - 2019-10-21

Security

  • Updated dependencies

0.6.2 - 2019-10-09

Changed

  • Don't use .apply in Queue.trigger if no context is provided

0.6.1 - 2019-10-09

Fixed

  • methodFunction won't throw if attempting to set to something other than a function

0.6.0 - 2019-10-08

Changed

  • preferring .bind over .call and .apply. Methods should be much faster now.
  • Added bindTo method to Queue for setting a context to bind all callbacks to
  • methodFunction and methodQueue now bind callbacks to "this"
    • option "bind" can turn this off, defaults to true

0.5.8 - 2019-10-01

Changed

  • methods now store values in a WeakMap

0.5.7 - 2019-08-28

Security

  • Updated dependencies

0.5.6 - 2019-08-15

Fixed

  • enforceArray and enforceObject now coerce values properly

0.5.5 - 2019-07-29

Security

  • Updated dependencies

0.5.4 - 2019-07-27

Added

0.5.3 - 2019-07-19

Fixed

  • methodQueue shouldn't throw an error if called after .remove() is called

0.5.2 - 2019-07-16

  • Fixing build config

0.5.1 - 2019-07-13

Added

Changed

  • methods use privateProp to store values

0.5.0 - 2019-07-04

Added

0.4.4 - 2019-06-06

Security

  • Updated dependencies

0.4.3 - 2019-03-27

Added

  • DockPoint added read-only property 'opposite'

0.4.2 - 2019-03-27

Changed

  • castArray returns an empty array when given undefined, and converts array-like objects into arrays.
  • isNumber returns false for NaN

0.4.1 - 2019-03-11

Changed

  • Fixed bug in methods where the init value could get modified.

0.4.0 - 2019-03-11

Added

  • Float type (check, enforcer, and method)

Changed

  • Integer coercion is now more strict
  • Switching dependencies back to object-agent

0.3.3 - 2019-02-15

Changed

  • Switching dependencies to deep-equal instead of object-agent

0.3.2 - 2019-02-14

Changed

  • Replaced dependencies on clone and deepEqual with object-agent
  • Added id and callback args to the methodQueue set option

0.3.1 - 2019-02-10

Added

0.3.0 - 2019-02-03

Changed

  • Removed Dependency on Lodash

0.2.4 - 2019-01-31

Added

0.2.3 - 2019-01-30

Changed

  • Exporting the check functions as an object
  • Exporting individual enforcers and methods

0.2.2 - 2019-01-24

Changed

  • Removed dependencies on babel plugin proposals.
  • Improved docs.

0.2.1 - 2019-01-24

Changed

  • Changed isBool to isBoolean, enforce.bool to enforce.boolean, and method.bool to method.boolean
  • Changed isFunc to isFunction, enforce.func to enforce.function, and method.func to method.function
  • Changed isInt to isInteger, enforce.int to enforce.integer, and method.int to method.integer

0.2.0 - 2019-01-18

Added

  • 99.9% test-coverage
    • testing in chrome and firefox
  • This CHANGELOG
  • checks
    • moved all type checks into new functions (isArray, isBool, etc.)
    • most checks can also check if a value can be coerced
    • isInstanceOf fixes issues with primitives and instanceof
    • isJson function to check if a value can be parsed as JSON
  • enforce
    • most enforce functions can now coerce values
    • added enforce.regExp
  • method
    • added method.regExp
    • added "deep" option to method.object and method.array
    • added "coerce" option to methods of types that can be coerced

Changed

  • Date functions only accept native Dates now. Removes dependency on Moment.js.
  • DockPoint
    • default value is now DockPoint.POINTS.NONE
    • added methods "isSame" and "toString"
    • bug fix: setting primary or secondary now updates the value
  • Enum
    • added method "key"
  • Queue
    • method "getTotalCallbacks" is now read only property "length"
    • method "isBusy" is now read only property "isBusy"
  • enforce
    • Custom type functions no longer coerce values by default

Removed

  • Removed static method "isInstance" from custom data types in favor of new checks function.
  • Queue
    • removed method "getCallbacks"

0.1.6 - 2019-01-02

Added

  • Snyk.io badge for security checks
  • enforce.instance
  • Enum.each

Changed

  • Changed CallbackQueue to Queue.

0.1.5 - 2018-12-30

Changed

  • .babelrc became babel.config.js so the babel plugins are handled properly when using this library as an npm package

0.1.4 - 2018-12-30

Changed

  • Moved necessary Babel plugins to dependencies in package.json

0.1.3 - 2018-12-29

Changed

  • Documentation

0.1.2 - 2018-12-29

Changed

  • Documentation

0.1.1 - 2018-12-29

Changed

  • Documentation

0.1.0 - 2018-12-29

Added

  • Initial enforcers, methods, and documentation