angular.element

Angular comes with jqLite, a tiny, API-compatible subset of jQuery. However, its
functionality is very limited and MacGyver extends jqLite to make sure MacGyver
components work properly.

Real jQuery will continue to take precedence over jqLite and all functions MacGyver extends.

MacGyver adds the following methods:

Character code enum

MacGyver comes with character code enum for easy reference and increase readability. With dependency injection, just inject "keys" to gain access.

  • {{item.key}} - {{item.code}}

pluralize

util.pluralize("apple", 5)
=> "apples"
util.pluralize("apple", 10, true)
=> "10 apples"

capitalize

Converts first leter of the string to uppercase (Underscore string proxy)

util.capitalize("lowercase")
=> "Lowercase"

uncapitalize

util.uncapitalize("UPPERCASE")
=> "uPPERCASE"

toCamelCase

util.toCamelCase("a-string-with-dashes")
=> "aStringWithDashes"

toSnakeCase

util.toSnakeCase("just another string")
=> "just_another_string"

convertKeysToCamelCase

Convert all the keys in an object to camel case

util.toSnakeCase({'hello-world': 'test'})
=> {'helloWorld': 'test'}

convertKeysToSnakeCase

Convert all the keys in an object to snake case

util.toSnakeCase({'helloWorld': 'test'})
=> {'hello_world': 'test'}

Pythagoras

util.pyth(3, 4)
=> 5

Radian to Degrees

util.degrees(Math.PI)
=> 180

Degrees to Radian

util.radian(180)
=> Math.PI

HEX to RGB

Convert HEX color into RGB values

util.hex2rgb("#5331DE")
=> {r: 83, g: 49, b: 222}

validateUrl

Parse url and break it into different components

util.validateUrl("http://www.example.com/macgyver/episodes")
=> {domain: "com"
    name: "example"
    path: "/macgyver/episodes"
    port: undefined
    protocol: "http://"
    subdomain: "www"
    url: "http://www.example.com/macgyver/episodes"}
    

validateEmail

util.validateEmail("user@example.com")
=> true

getQueryString

util.getQueryString("http://www.example.com/macgyver?season=1&episode=3&time=12:23", "episode")
=> 3

parseUrlPath

util.parseUrlPath("http://www.example.com/macgyver?season=1&episode=3&time=12:23")
=> {fullPath: "http://www.example.com/macgyver?season=1&episode=3&time=12:23",
    path: "http://www.example.com",
    pathComponents: [
      "http:",
      "",
      "www.example.com",
      "macgyver"
    ],
    verb: "macgyver",
    queries: {
      season: "1",
      episode: "3",
      time: "12:23"
    }
}