common | UI-Router
Options
All
  • Public
  • Public/Protected
  • All
Menu

External module common

Random utility functions used in the UI-Router code

Index

Type aliases

IInjectable: Function | Array<any>
Mapper: function

Type declaration

    • (x: X, key?: string | number): T
    • Parameters

      • x: X
      • key Optional: string | number

      Returns T

PickOmitPredicate: function

Type declaration

    • (keys: string[], key: any): boolean
    • Parameters

      • keys: string[]
      • key: any

      Returns boolean

Predicate: function

Type declaration

    • (X: any): boolean
    • Parameters

      • X: any

      Returns boolean

Variables

abstractKey: string
angular: any
copy: any
equals: any
extend: any
forEach: any
fromJson: any
mapObj: function

Given an object, returns a new object, where each property is transformed by the callback function

Given an object, returns a new object, where each property is transformed by the callback function

Type declaration

    • <T, U>(collection: object, callback: Mapper): object
    • Type parameters

      • T

      • U

      Parameters

      • collection: object
        • [key: string]: T
      • callback: Mapper

      Returns object

      • [key: string]: U
removeFrom: Function

Given an array, and an item, if the item is found in the array, it removes it (in-place). The same array is returned

Given an array, and an item, if the item is found in the array, it removes it (in-place). The same array is returned

toJson: any
w: any

Functions

  • _arraysEq(a1: any, a2: any): any
  • _copy(src: any, dest: any): any
  • shallow copy from src to dest

  • shallow copy from src to dest

    note: This is a shallow copy, while angular.copy is a deep copy. ui-router uses copy only to make copies of state parameters.

    Parameters

    • src: any
    • dest: any

    Returns any


  • _copyProps(to: any, from: any): any
  • _equals(o1: any, o2: any): any
  • _extend(toObj: any, fromObj: any): any
  • _extend(toObj: any, ...fromObj: Array<any>): any
  • _forEach(obj: any, cb: any, _this: any): any
  • allTrueR(memo: boolean, elem: any): any
  • Reduce function that returns true if all of the values are truthy.

  • Reduce function that returns true if all of the values are truthy.

    Parameters

    • memo: boolean
    • elem: any

    Returns any


  • ancestors(first: any, second: any): Array<any>
  • Finds the common ancestor path between two states.

  • Finds the common ancestor path between two states.

    Parameters

    • first: any
      :

      The first state.

    • second: any
      :

      The second state.

    Returns Array<any>

    :

    Returns an array of state names in descending order, not including the root.


  • anyTrueR(memo: boolean, elem: any): any
  • Reduce function that returns true if any of the values are truthy.

  • Reduce function that returns true if any of the values are truthy.

    • @example ```

    let vals = [ 0, null, undefined ]; vals.reduce(anyTrueR, true); // false

    vals.push("hello world"); vals.reduce(anyTrueR, true); // true ```

    Parameters

    • memo: boolean
    • elem: any

    Returns any


  • applyPairs(memo: TypedMap<any>, keyValTuple: any[]): TypedMap<any>
  • Reduce function which builds an object from an array of [key, value] pairs.

  • Reduce function which builds an object from an array of [key, value] pairs.

    Each iteration sets the key/val pair on the memo object, then returns the memo for the next iteration.

    Each keyValueTuple should be an array with values [ key: string, value: any ]

    example
    
    var pairs = [ ["fookey", "fooval"], ["barkey", "barval"] ]
    
    var pairsToObj = pairs.reduce((memo, pair) => applyPairs(memo, pair), {})
    // pairsToObj == { fookey: "fooval", barkey: "barval" }
    
    // Or, more simply:
    var pairsToObj = pairs.reduce(applyPairs, {})
    // pairsToObj == { fookey: "fooval", barkey: "barval" }
    

    Parameters

    • memo: TypedMap<any>
    • keyValTuple: any[]

    Returns TypedMap<any>


  • arrayTuples(...arrayArgs: any[]): any[]
  • Given two or more parallel arrays, returns an array of tuples where each tuple is composed of [ a[i], b[i], ... z[i] ]

  • Given two or more parallel arrays, returns an array of tuples where each tuple is composed of [ a[i], b[i], ... z[i] ]

    example
    
    let foo = [ 0, 2, 4, 6 ];
    let bar = [ 1, 3, 5, 7 ];
    let baz = [ 10, 30, 50, 70 ];
    arrayTuples(foo, bar);       // [ [0, 1], [2, 3], [4, 5], [6, 7] ]
    arrayTuples(foo, bar, baz);  // [ [0, 1, 10], [2, 3, 30], [4, 5, 50], [6, 7, 70] ]
    

    Parameters

    • ...arrayArgs Rest: any[]

    Returns any[]


  • assertPredicate<T>(predicate: Predicate, errMsg?: string | Function): Predicate
  • Given a .filter Predicate, builds a .filter Predicate which throws an error if any elements do not pass.

  • Given a .filter Predicate, builds a .filter Predicate which throws an error if any elements do not pass.

    example
    
    let isNumber = (obj) => typeof(obj) === 'number';
    let allNumbers = [ 1, 2, 3, 4, 5 ];
    allNumbers.filter(assertPredicate(isNumber)); //OK
    
    let oneString = [ 1, 2, 3, 4, "5" ];
    oneString.filter(assertPredicate(isNumber, "Not all numbers")); // throws Error(""Not all numbers"");
    

    Type parameters

    • T

    Parameters

    • predicate: Predicate
    • errMsg Default value: string | Function = "assert failure"

    Returns Predicate


  • bindFunctions(from: any, to: any, bindTo: any, fnNames?: string[]): void
  • Binds and copies functions onto an object

  • Binds and copies functions onto an object

    Takes functions from the 'from' object, binds those functions to the _this object, and puts the bound functions on the 'to' object.

    This example creates an new class instance whose functions are prebound to the new'd object.

    example
    
    class Foo {
      constructor(data) {
        // Binds all functions from Foo.prototype to 'this',
        // then copies them to 'this'
        bindFunctions(Foo.prototype, this, this);
        this.data = data;
      }
    
      log() {
        console.log(this.data);
      }
    }
    
    let myFoo = new Foo([1,2,3]);
    var logit = myFoo.log;
    logit(); // logs [1, 2, 3] from the myFoo 'this' instance
    

    This example creates a bound version of a service function, and copies it to another object

    example
    
    var SomeService = {
      this.data = [3, 4, 5];
      this.log = function() {
        console.log(this.data);
      }
    }
    
    // Constructor fn
    function OtherThing() {
      // Binds all functions from SomeService to SomeService,
      // then copies them to 'this'
      bindFunctions(SomeService, this, SomeService);
    }
    
    let myOtherThing = new OtherThing();
    myOtherThing.log(); // logs [3, 4, 5] from SomeService's 'this'
    

    Parameters

    • from: any
      :

      The object which contains the functions to be bound

    • to: any
      :

      The object which will receive the bound functions

    • bindTo: any
      :

      The object which the functions will be bound to

    • fnNames Default value: string[] = Object.keys(from)
      :

      The function names which will be bound (Defaults to all the functions found on the 'from' object)

    Returns void


  • defaults(opts?: object, ...defaultsList: Array<any>): any
  • Applies a set of defaults to an options object. The options object is filtered to only those properties of the objects in the defaultsList. Earlier objects in the defaultsList take precedence when applying defaults.

  • Applies a set of defaults to an options object. The options object is filtered to only those properties of the objects in the defaultsList. Earlier objects in the defaultsList take precedence when applying defaults.

    Parameters

    • opts Default value: object = {}
    • ...defaultsList Rest: Array<any>

    Returns any


  • equalForKeys(a: any, b: any, keys?: string[]): boolean
  • Performs a non-strict comparison of the subset of two objects, defined by a list of keys.

  • Performs a non-strict comparison of the subset of two objects, defined by a list of keys.

    Parameters

    • a: any
      :

      The first object.

    • b: any
      :

      The second object.

    • keys Default value: string[] = Object.keys(a)
      :

      The list of keys within each object to compare. If the list is empty or not specified, it defaults to the list of keys in a.

    Returns boolean

    :

    Returns true if the keys match, otherwise false.


  • filter<T>(collection: T[], callback: function): T[]
  • Given an array of objects, returns a new array containing only the elements which passed the callback predicate

  • filter<T>(collection: TypedMap<T>, callback: function): TypedMap<T>
  • Given an object, returns a new object with only those properties that passed the callback predicate

  • Given an array of objects, returns a new array containing only the elements which passed the callback predicate

    Type parameters

    • T

    Parameters

    • collection: T[]
    • callback: function
        • (T: any, key?: any): boolean
        • Parameters

          • T: any
          • key Optional: any

          Returns boolean

    Returns T[]


  • Given an object, returns a new object with only those properties that passed the callback predicate

    Type parameters

    • T

    Parameters

    • collection: TypedMap<T>
    • callback: function
        • (T: any, key?: any): boolean
        • Parameters

          • T: any
          • key Optional: any

          Returns boolean

    Returns TypedMap<T>


  • find<T>(collection: TypedMap<T>, callback: Predicate): T
  • Given an object, return the first property of that object which passed the callback predicate

  • find<T>(collection: T[], callback: Predicate): T
  • Given an array of objects, returns the first object which passed the callback predicate

  • Given an object, return the first property of that object which passed the callback predicate

    Type parameters

    • T

    Parameters

    Returns T


  • Given an array of objects, returns the first object which passed the callback predicate

    Type parameters

    • T

    Parameters

    Returns T


  • flatten(arr: any[]): any
  • Return a completely flattened version of an array.

  • Return a completely flattened version of an array.

    Parameters

    • arr: any[]

    Returns any


  • flattenR(memo: any[], elem: any): Array<any>
  • Reduce function which recursively un-nests all arrays

  • Reduce function which recursively un-nests all arrays

    Parameters

    • memo: any[]
    • elem: any

    Returns Array<any>


  • identity(x: any): any
  • inArray(array: any[], obj: any): boolean
  • Given an array, returns true if the object is found in the array, (using indexOf)

  • Given an array, returns true if the object is found in the array, (using indexOf)

    Parameters

    • array: any[]
    • obj: any

    Returns boolean


  • inherit(parent: any, extra: any): any
  • prototypal inheritance helper. Creates a new object which has parent object as its prototype, and then copies the properties from extra onto it

  • prototypal inheritance helper. Creates a new object which has parent object as its prototype, and then copies the properties from extra onto it

    Parameters

    • parent: any
    • extra: any

    Returns any


  • map<T, U>(collection: T[], callback: Mapper): U[]
  • Given an array, returns a new array, where each element is transformed by the callback function

  • map<T, U>(collection: object, callback: Mapper): object
  • Maps an array or object properties using a callback function

  • Given an array, returns a new array, where each element is transformed by the callback function

    Type parameters

    • T

    • U

    Parameters

    • collection: T[]
    • callback: Mapper

    Returns U[]


  • Maps an array or object properties using a callback function

    Type parameters

    • T

    • U

    Parameters

    • collection: object
      • [key: string]: T
    • callback: Mapper

    Returns object

    • [key: string]: U

  • merge(dst: any, ...objs: Object[]): any
  • Merges properties from the list of objects to the destination object. If a property already exists in the destination object, then it is not overwritten.

  • Merges properties from the list of objects to the destination object. If a property already exists in the destination object, then it is not overwritten.

    Parameters

    • dst: any
    • ...objs Rest: Object[]

    Returns any


  • mergeR(memo: any, item: any): any
  • Reduce function that merges each element of the list into a single object, using extend

  • Reduce function that merges each element of the list into a single object, using extend

    Parameters

    • memo: any
    • item: any

    Returns any


  • noop(): any
  • notImplemented(fnname: any): (Anonymous function)
  • for typedoc

  • omit(obj: any, propNames: string[]): Object
  • Return a copy of the object omitting the blacklisted properties.

  • omit(obj: any, ...propNames: string[]): Object
  • Return a copy of the object omitting the blacklisted properties.

  • Return a copy of the object omitting the blacklisted properties.

    example
    
    var foo = { a: 1, b: 2, c: 3 };
    var ab = omit(foo, ['a', 'b']); // { c: 3 }
    

    Parameters

    • obj: any
      :

      the source object

    • propNames: string[]
      :

      an Array of strings, which are the blacklisted property names

    Returns Object


  • Return a copy of the object omitting the blacklisted properties.

    example
    
    var foo = { a: 1, b: 2, c: 3 };
    var ab = omit(foo, 'a', 'b'); // { c: 3 }
    

    Parameters

    • obj: any
      :

      the source object

    • ...propNames Rest: string[]
      :

      1..n strings, which are the blacklisted property names

    Returns Object


  • pairs(object: any): Array<Array<any>>
  • Like _.pairs: Given an object, returns an array of key/value pairs

  • Like _.pairs: Given an object, returns an array of key/value pairs

    Parameters

    • object: any

    Returns Array<Array<any>>


  • pick(obj: any, propNames: string[]): Object
  • Return a copy of the object only containing the whitelisted properties.

  • pick(obj: any, ...propNames: string[]): Object
  • Return a copy of the object only containing the whitelisted properties.

  • Return a copy of the object only containing the whitelisted properties.

    example
    
    var foo = { a: 1, b: 2, c: 3 };
    var ab = pick(foo, ['a', 'b']); // { a: 1, b: 2 }
    

    Parameters

    • obj: any
      :

      the source object

    • propNames: string[]
      :

      an Array of strings, which are the whitelisted property names

    Returns Object


  • Return a copy of the object only containing the whitelisted properties.

    example
    
    var foo = { a: 1, b: 2, c: 3 };
    var ab = pick(foo, 'a', 'b'); // { a: 1, b: 2 }
    

    Parameters

    • obj: any
      :

      the source object

    • ...propNames Rest: string[]
      :

      1..n strings, which are the whitelisted property names

    Returns Object


  • pluck(collection: any[], propName: string): any[]
  • Given an array of objects, maps each element to a named property of the element.

  • pluck(collection: object, propName: string): object
  • Given an object, maps each property of the object to a named property of the property.

  • Given an array of objects, maps each element to a named property of the element.

    Parameters

    • collection: any[]
    • propName: string

    Returns any[]


  • Given an object, maps each property of the object to a named property of the property.

    Parameters

    • collection: object
      • [key: string]: any
    • propName: string

    Returns object

    • [key: string]: any

  • pushR(arr: any[], obj: any): Array<any>
  • Reduce function that pushes an object to an array, then returns the array. Mostly just for flattenR

  • Reduce function that pushes an object to an array, then returns the array. Mostly just for flattenR

    Parameters

    • arr: any[]
    • obj: any

    Returns Array<any>


  • restArgs(args: any, idx?: number): any
  • Given an arguments object, converts the arguments at index idx and above to an array. This is similar to es6 rest parameters.

  • Given an arguments object, converts the arguments at index idx and above to an array. This is similar to es6 rest parameters.

    Optionally, the argument at index idx may itself already be an array.

    For example, given either: arguments = [ obj, "foo", "bar" ] or: arguments = [ obj, ["foo", "bar"] ] then: restArgs(arguments, 1) == ["foo", "bar"]

    This allows functions like pick() to be implemented such that it allows either a bunch of string arguments (like es6 rest parameters), or a single array of strings:

    given: var obj = { foo: 1, bar: 2, baz: 3 }; then: pick(obj, "foo", "bar"); // returns { foo: 1, bar: 2 } pick(obj, ["foo", "bar"]); // returns { foo: 1, bar: 2 }

    Parameters

    • args: any
    • idx Default value: number = 0

    Returns any


  • silenceUncaughtInPromise(promise: Promise<any>): Promise<any>
  • silentRejection(error: any): Promise<any>
  • tail<T>(arr: T[]): T
  • Get the last element of an array

  • Get the last element of an array

    Type parameters

    • T

    Parameters

    • arr: T[]

    Returns T


  • uniqR(acc: any, token: any): any
  • Reduce function that filters out duplicates

  • Reduce function that filters out duplicates

    Parameters

    • acc: any
    • token: any

    Returns any


  • unnest(arr: any[]): any
  • Return a new array with a single level of arrays unnested.

  • Return a new array with a single level of arrays unnested.

    Parameters

    • arr: any[]

    Returns any


  • unnestR(memo: any[], elem: any): Array<any>
  • Reduce function which un-nests a single level of arrays

  • Reduce function which un-nests a single level of arrays

    Parameters

    • memo: any[]
    • elem: any

    Returns Array<any>


  • values(obj: any): Array<any>
  • Given an object, return its enumerable property values

  • Given an object, return its enumerable property values

    Parameters

    • obj: any

    Returns Array<any>


Object literals

services: object
$injector: undefined
$q: undefined
location: any
locationConfig: any
template: any

Generated using TypeDoc