Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-types

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-types

AngularJS introspection utilities

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

angular-types

AngularJS introspection utilities

Overview

AngularJS ships with various functions to check types, such as angular.isNumber(), angular.isUndefined(), and angular.isElement(). This extension adds many functions to AngularJS' builtins, including a general-purpose type-checking function and a cloning function.

This is particularly useful if you want the type-checking functionality of Lo-Dash or Underscore, but without the libraries themselves. Many of these functions were derived from Lo-Dash implementations.

Type-Checking Functions

Each of these functions accept a value and return a boolean.

  • isNull() / isNotNull()
  • isBoolean() / isNotBoolean()
  • isNaN() / isNotNaN()
  • isFinite() / isNotFinite()
  • isInfinite() / isNotInfinite()
  • isArguments() / isNotArguments()
  • isRegExp() / isNotRegExp()
  • isEmpty() / isNotEmpty()
  • isInteger() / isNotInteger()
  • isFloat() / isNotFloat()
  • isObjectish() / isNotObjectish() (returns true if the value is not null and may contain properties)

In addition, the negation of the AngularJS built-ins are provided:

  • isNotUndefined()
  • isNotArray()
  • isNotDate()
  • isNotElement()
  • isNotObject()
  • isNotString()
  • isNotFunction()
  • isNotNumber()

type()

The type() function will accept a value and return one of the following strings:

null, string, array, date, regexp, arguments, boolean, number, undefined, function, element, object

An element is considered to be a DOM node, jqLite object, or jQuery object.

clone()

The clone() function will return a deep clone of some value. This differs from angular.copy() in the following ways:

  • Simply returns the cloned value; does not accept a destination parameter.
  • Works on DOM nodes, jqLite elements or jQuery objects.
  • If a nested value implements a clone() function, that function will be called. This is useful for complex nested objects.
  • Calls angular.copy() internally so your $$hashKeys are not befouled.
  • Accepts an optional second Object parameter, extra, which can be extended onto the clone. This is useful, for example, if you have a unique identifier in an object, and wish to re-generate it.

Usage (Browser)

In the browser, if not using AMD, the functions are attached to the angular object as to not further pollute the global scope.

var foo = {
  bar: 1,
  baz: function() {
    return this.bar + 1;
  }
};

angular.isInteger(foo.bar);           // true
angular.type(foo.bar);                // 'number'
angular.isNotFunction(foo.baz);       // false
angular.type(foo.baz);                // 'function'

// example of using second parameter
angular.clone(foo, {bar: 2}).baz();   // 3

Usage (CommonJS/NodeJS)

In a NodeJS context, require() the angular-types module.

var types = require('angular-types'),
  quux = 1;

types.isInteger(quux);

Usage (AMD/RequireJS)

Using RequireJS, just require types.

define(['/path/to/types'], function(types) {
  var quux = 1;
  types.isInteger(quux);
});

Installation

If using in NodeJS (a la Browserify):

npm install angular-types

Otherwise, use Bower:

bower install angular-types

Author

Christopher Hiller

License

Copyright © 2014 Decipher, Inc. Licensed MIT

Keywords

FAQs

Package last updated on 11 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc