Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@angular-package/type

angular-package321MIT5.0.0-rc.0TypeScript support: included

Common types, type guards and type checkers.

array, bigint, boolean, check, class, date, defined, determine, false, function, guard, instance, key, propertyKey, null, number, number between, number object, number type, object, primitive, RegExp, string, string length, string object, string type, symbol, undefined, true, type, types, type guards, typescript, angular-package, @angular-package, @angular-package/type

readme

angular-package

The angular-package supports the development process of angular-based applications in varied ways through the thoughtful, reusable, easy-to-use small pieces of code called packages.

docs.angular-package.dev


Packages

Package Description Status
callback Manages the callback function. npm version
change-detection Improves application performance. npm version
component-loader Handles dynamic loading components. npm version
core Core features. npm version
error Manages an Error. npm version
name The name with prefix and suffix. npm version
preferences Preferences, settings, options, configuration and setup in steps. npm version
prism Prism highlighter module. npm version
property Handles object properties. npm version
range The range between a minimum and maximum. npm version
reactive Automatize the process of creating some rxjs features. npm version
storage The storage of data under allowed names. npm version
tag Any tag with optional attributes. npm version
testing Support for testing other packages. npm version
text Text on the template with replaceable tags. npm version
type Common types, type guards, and type checkers. npm version
ui User interface. In Progress
wrapper Wrap the text with the opening and closing chars. npm version

Click on the package name to visit its GitHub page.


angular-package/type

Common types, type guards and type checkers.

Gitter Discord Twitter

npm version

GitHub issues GitHub forks GitHub stars GitHub license

GitHub sponsors Support me on Patreon


Documentation

For the detailed documentation go to https://type.angular-package.dev/

Table of contents


Basic concepts

Checks

It's to check the provided value to be the same as expected.

Type guard (constrain)

Constrains the parameter type to not let input unexpected value in the code editor.

Guards

It's a combination of both above, constrains the type of the parameter in the code editor, and checks its provided argument.

Defines

Returns defined value from a method of an object.
Defines new value in an object and returns a defined value.

Gets

Returns a value from an object.

Sets

Adds or updates an element with a specified key and a value to an object and returns an object.


Skeleton

This package was generated by the library skeleton with Angular CLI version 13.0.0.

Copy this package to the packages/type folder of the library skeleton then run the commands below.


Code scaffolding

Run ng generate component component-name --project type to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module --project type.

Note: Don't forget to add --project type or else it will be added to the default project in your angular.json file.

Build

Run ng build type to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library with ng build type, go to the dist folder cd dist/type and run npm publish.

Running unit tests

Install @angular-package/type with command:

npm i @angular-package/testing --no-save

Run ng test type to execute the unit tests via Karma.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI Overview and Command Reference page.


Installation

Install @angular-package/type package with command:

npm i @angular-package/type --save

Api

// Main.
import {
  recognizeValue, // From the `5.0.0` version
  typeOf,
} from '@angular-package/type';
// `are` prefix functions.
import {
  // Function.
  areBigInt, // From the `5.0.0` version
  areBoolean, // From the `5.0.0` version
  areDate, // From the `5.0.0` version
  areDefined, // From the `5.0.0` version
  areFalse, // From the `5.0.0` version
  areNull, // From the `5.0.0` version
  areNumber, // From the `5.0.0` version
  areRegExp, // From the `5.0.0` version
  areString,
  areSymbol, // From the `5.0.0` version
  areTrue, // From the `5.0.0` version
  areUndefined, // From the `5.0.0` version
} from '@angular-package/type';
// `guard` prefix functions.
import { 
  guardArray,
  guardBigInt,
  guardBoolean,
  guardClass,
  guardDate, // From the 5.0.0 version
  guardDefined,
  guardFalse, // From the 5.0.0 version
  guardFunction,
  guardInstance,
  guardKey,
  guardNull,
  guardNumber,
  guardNumberBetween, // From the 5.0.0 version
  guardObject,
  guardObjectKey,
  guardObjectKeyIn, // From the 5.0.0 version
  guardObjectKeys,
  guardObjectKeysIn, // From the 5.0.0 version
  guardObjectSomeKeys, // From the 5.0.0 version
  guardPrimitive,
  guardRegExp, // From the 5.0.0 version
  guardString,
  guardStringIncludes, // From the 5.0.0 version
  guardStringIncludesSome, // From the 5.0.0 version
  guardStringLength, // From the 5.0.0 version
  guardStringLengthBetween, // From the 5.0.0 version
  guardSymbol,
  guardTrue, // From the 5.0.0 version
  guardType,
  guardUndefined,
} from '@angular-package/type'; 
// `is` prefix functions.
import {
  isArray,
  isBigInt,
  isBoolean,
  isBooleanObject,
  isBooleanType,
  isClass,
  isDate, // From the 4.2.0 version.
  isDefined,
  isFalse, // From the 4.2.0 version.
  isFunction,
  isInstance,
  isKey,
  isNull,
  isNumber,
  isNumberBetween, // From the 4.2.0 version.
  isNumberObject,
  isNumberType,
  isObject,
  isObjectKey,
  isObjectKeyIn,
  isObjectKeys,
  isObjectKeysIn, // From the 5.0.0 version
  isObjectSomeKeys, // From the 5.0.0 version
  isParam,
  isPrimitive,
  isRegExp, // From the 4.2.0 version.
  isString,
  isStringIncludes, // From the 5.0.0 version
  isStringIncludesSome, // From the 5.0.0 version
  isStringLength, // From the 4.2.0 version.
  isStringLengthBetween, // From the 5.0.0 version
  isStringObject,
  isStringType,
  isSymbol,
  isTrue, // From the 4.2.0 version.
  isType,
  isUndefined,
} from '@angular-package/type';
// `isNot` prefix functions.
import {
  isNotBoolean,
  isNotDefined,
  isNotFunction,
  isNotNull,
  isNotNumber,
  isNotString,
  isNotUndefined
} from '@angular-package/type';
// Objects.
import { are, guard, is, isNot, type } from '@angular-package/type';
// Interfaces.
import {
  MinMax
} from '@angular-package/type';
// Types.
import {
  AnyBoolean,
  AnyNumber,
  AnyString,
  CallbackPayload, // From the `5.0.0` version.
  Constructor,
  Defined,
  ForEachCallback,  // From the `5.0.0` version.
  Never,
  NotUndefined,
  NumberBetween, // From the `4.2.0` version.
  Primitive,
  Primitives,
  ResultCallback, // From the `4.2.0` version
  StringOfLength, // From the `4.2.0` version.
  Type,
  Types,
  Undefined
} from '@angular-package/type';

Changelog

The changelog of this package is based on keep a changelog. To read it, click on the CHANGELOG.md link.

A changelog is a file which contains a curated, chronologically ordered list of notable changes for each version of a project. - keep a changelog


GIT

Commit

Versioning

Semantic Versioning 2.0.0

Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

FAQ How should I deal with revisions in the 0.y.z initial development phase?

The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.

How do I know when to release 1.0.0?

If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.

License

MIT © angular-package (license)

changelog

Change Log

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.

[5.0.0] - 2022-01-30

[5.0.0] Added

  • Added Undefined generic type.
  • Added guard function guardStringLengthBetween(). 53e02d8
  • Added check function isStringLengthBetween(). 5d044f9
  • Added generic type GenericObject. fd14947
  • Added guardStringIncludes() and guardStringIncludesSome() functions with tests. 691f07e
  • Added guardObjectKeysIn() function to guard the value to be an object with specified keys in it(or its prototype chain). 21e523b
  • Added are prefixed functions to check the values of a rest parameter. areBigInt() areBoolean() areDate() areDefined() areFalse() areNull() areNumber() areRegExp() areSymbol() areTrue() areUndefined(). 823dac3
  • Added a generic type MinMax that takes generic type variable Min and Max that represents the range between minimum and maximum. e503d38
  • Added new guard functions guardDate(), guardFalse(), guardNumberBetween(), guardObjectKeyIn(), guardObjectSomeKeys(), guardRegExp(), guardStringLength(), guardTrue(). c374612
  • Added isObjectKeysIn(), isObjectSomeKeys(), isStringIncludes() and isStringIncludesSome() and to the is object and to the Is interface. 55635fa 1e48fb1 a4cb61d f809f32 5c85a03 d440e38 0efe8ae
  • Added CallbackPayload and ForEachCallback types. 98a2722
  • Added the type object consists of are, is and guard objects. dfb3df9
  • Added an object to handle executing the tests. 8dd8099 230063b
  • Added recognizeValue() to recognize type of any value. d2f756e

[5.0.0] Changed

  • Updated the way of checking values in some of the is and isNot prefixed functions.
  • Updated isPrimitive() and isType() function does not use switch on the type argument.
  • Updated guard, is, isNot prefixed functions to use updated generic type ResultCallback with payload parameter of generic type variable Payload.
  • Updated isStringLength() function to check the specific length. 061ab52
  • Updated guardStringLength() function to check the specific length. 0e48591
  • Updated is {} object by adding stringLengthBetween method. 083ffd0
  • Updated guardIs object by adding objectKeysIn, stringIncludes, stringLengthBetween and stringIncludesSome methods. 8679b4c 1d44d2e
  • Updated GuardIs interface by adding stringLengthBetween. 7387e23
  • Updated areString() function that works by using the returned methods. 68c9365
  • Freeze the guard, guardIs, isNot and is object. 00e8841 09fb70f c4e6f8f 0efe8ae
  • Updated isObject() function by adding the ability to check any kind of object, not only the Object. de6aa12
  • Updated NumberBetween interface by adding MinMax interface and a generic type variable Type. 1263a2e
  • Updated StringOfLength interface by adding MinMax interface and a generic type variable Type. 24621f7
  • Updated isInstance() function can now check any kind of instance. 7d288c2
  • Updated Is interface by adding stringLengthBetween. 26d7a9d 8ddb720
  • Updated Is interface and isNot by changing the function types to the typeof operator. 8ddb720 8ddb720
  • Updated the type of callback function ResultCallback to provide the type of value and the shape of payload. 8ddb720 34a1b1f
  • Updated functions by adding a generic type variable Payload constrained by the object type that is by default equal to the object. 5c9486f
  • Updated functions by adding a payload parameter of generic type CallbackPayload that takes generic type variable Payload to assign to callback function payload parameter. 6d190f5
  • Updated functions by removing typeOf() function if it's not necessary to use it. 8ddb720
  • Updated the Defined to not use of Never type cause of some compile issues. e09a84f
  • Updated the guard object by removing is property. aa80250
  • Updated the isParam() function by removing the Func generic type in favor of Function. 42065c9
  • Updated isObjectKey(), isObjectKeyIn to check only one key instead of multiple keys. b7092a9
  • Updated isObjectKeys() works differently, now it searches for every key. The previous functionality provides isObjectSomeKeys(). b7092a9

[5.0.0] Removed

  • Removed guard prefixed function types. a8e8566
  • Removed Func type in favor of build-in Function type. 8ddb720 5148f05
  • Removed Key type in favor of build-in PropertyKey type. 562ec13
  • Removed CycleHook type. 4d53a55

[4.2.0] - 2021-06-25

Added

  • a6b567f
    New NumberBetween and StringOfLength type.

  • 21f3f48
    New functions isDate(), isFalse(), isNumberBetween(), isRegExp(), isStringLength(), isTrue() with tests and types.

  • 7d4cda7
    This CHANGELOG.md.

Changed

  • e70b034
    All types description in the README.md.

  • 61e9376
    Add possibility to use is prefixed functions directly from the guard eg. guard.array().