typescript-angular-utilities
Advanced tools
Comparing version 2.1.2 to 2.1.3
{ | ||
"name": "typescript-angular-utilities", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Typescript utility classes published as angular services", | ||
@@ -24,3 +24,3 @@ "author": "Renovo Development Team", | ||
"clean": "gulp clean", | ||
"publish.prep": "npm run update && npm run test.full && npm run build && npm run build.library" | ||
"publish.prep": "npm run update && npm run build && npm run test.full && npm run build.library" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var object_service_1 = require('../../services/object/object.service'); | ||
exports.moduleName = 'rl21.utilities.filters.truncate'; | ||
exports.moduleName = 'rl.utilities.filters.truncate'; | ||
exports.serviceName = 'truncate'; | ||
@@ -8,0 +8,0 @@ exports.filterName = exports.serviceName + 'Filter'; |
@@ -13,3 +13,3 @@ 'use strict'; | ||
export var moduleName: string = 'rl21.utilities.filters.truncate'; | ||
export var moduleName: string = 'rl.utilities.filters.truncate'; | ||
export var serviceName: string = 'truncate'; | ||
@@ -16,0 +16,0 @@ export var filterName: string = serviceName + 'Filter'; |
@@ -11,3 +11,3 @@ 'use strict'; | ||
__export(require('./fileSizeFilter')); | ||
exports.moduleName = 'rl21.utilities.services.fileSize'; | ||
exports.moduleName = 'rl.utilities.services.fileSize'; | ||
angular.module(exports.moduleName, [number_service_1.moduleName]) | ||
@@ -14,0 +14,0 @@ .factory(fileSize_service_1.factoryName, fileSize_service_1.fileSizeFactory) |
@@ -12,3 +12,3 @@ 'use strict'; | ||
export var moduleName: string = 'rl21.utilities.services.fileSize'; | ||
export var moduleName: string = 'rl.utilities.services.fileSize'; | ||
@@ -15,0 +15,0 @@ angular.module(moduleName, [numberModuleName]) |
'use strict'; | ||
var angular = require('angular'); | ||
exports.moduleName = 'rl21.utilities.services.parentChildBehavior'; | ||
exports.moduleName = 'rl.utilities.services.parentChildBehavior'; | ||
exports.serviceName = 'parentChildBehavior'; | ||
@@ -5,0 +5,0 @@ var ParentChildBehaviorService = (function () { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
export var moduleName: string = 'rl21.utilities.services.parentChildBehavior'; | ||
export var moduleName: string = 'rl.utilities.services.parentChildBehavior'; | ||
export var serviceName: string = 'parentChildBehavior'; | ||
@@ -8,0 +8,0 @@ |
@@ -16,3 +16,5 @@ /// <reference path='../../../typings/chai/chai.d.ts' /> | ||
describe('promiseUtility', () => { | ||
var promiseUtility: IPromiseUtility; | ||
let promiseUtility: IPromiseUtility; | ||
let mockedValue: any; | ||
let $rootScope: angular.IRootScopeService; | ||
@@ -22,4 +24,11 @@ beforeEach(() => { | ||
var services: any = angularFixture.inject(serviceName); | ||
mockedValue = 5; | ||
angularFixture.mock({ | ||
value: mockedValue, | ||
}); | ||
let services: any = angularFixture.inject(serviceName, '$rootScope'); | ||
promiseUtility = services[serviceName]; | ||
$rootScope = services.$rootScope; | ||
}); | ||
@@ -29,3 +38,3 @@ | ||
it('should return true if the object is a promise', (): void => { | ||
var promise: Object = { | ||
let promise: Object = { | ||
then: sinon.spy(), | ||
@@ -39,4 +48,4 @@ catch: sinon.spy(), | ||
it('should return false if the object is not a promise', (): void => { | ||
var str: string = 'promise'; | ||
var obj: Object = {}; | ||
let str: string = 'promise'; | ||
let obj: Object = {}; | ||
@@ -47,2 +56,42 @@ expect(promiseUtility.isPromise(str)).to.be.false; | ||
}); | ||
describe('resolvePromises', (): void => { | ||
it('should return the value directly if type is object or primitive', (done: MochaDone): void => { | ||
let object: Object = { prop: 5 }; | ||
promiseUtility.resolvePromises({ object: object, num: 5 }).then((resolveData: any): void => { | ||
expect(resolveData.object).to.equal(object); | ||
expect(resolveData.num).to.equal(5); | ||
done(); | ||
}); | ||
$rootScope.$digest(); | ||
}); | ||
it('should inject the specified value if the type is string', (done: MochaDone): void => { | ||
promiseUtility.resolvePromises({ data: 'value' }).then((resolveData: any): void => { | ||
expect(resolveData.data).to.equal(mockedValue); | ||
done(); | ||
}); | ||
$rootScope.$digest(); | ||
}); | ||
it('should invoke the value with dependencies if type is function or an array with a function as the last param', (done: MochaDone): void => { | ||
let func: Sinon.SinonSpy = sinon.spy((value: number): number => { return value - 1; }); | ||
func.$inject = ['value']; | ||
let array: any[] = ['value', sinon.spy((value: number): number => { return value * 2; })]; | ||
promiseUtility.resolvePromises({ func: func, array: array }).then((resolveData: any): void => { | ||
expect(resolveData.func).to.equal(mockedValue - 1); | ||
expect(resolveData.array).to.equal(mockedValue * 2); | ||
sinon.assert.calledOnce(func); | ||
sinon.assert.calledWith(func, mockedValue); | ||
sinon.assert.calledOnce(array[1]); | ||
sinon.assert.calledWith(array[1], mockedValue); | ||
done(); | ||
}); | ||
$rootScope.$digest(); | ||
}); | ||
}); | ||
}); |
@@ -12,8 +12,27 @@ 'use strict'; | ||
isPromise(promise: angular.IPromise<any>): boolean; | ||
resolvePromises(resolves: any): angular.IPromise<any>; | ||
} | ||
class PromiseUtility implements IPromiseUtility { | ||
static $inject: string[] = ['$q', '$injector']; | ||
constructor(private $q: angular.IQService, private $injector: angular.auto.IInjectorService) {} | ||
isPromise(promise: any): boolean { | ||
return _.isObject(promise) && _.isFunction(promise.then) && _.isFunction(promise.catch); | ||
} | ||
resolvePromises(resolves: any): angular.IPromise<any> { | ||
let promises: any = {}; | ||
_.each(resolves, (value: any, key: any): void => { | ||
if (_.isFunction(value) || _.isArray(value)) { | ||
promises[key] = (this.$q.when(this.$injector.invoke(value))); | ||
} else if (_.isString(value)) { | ||
promises[key] = (this.$q.when(this.$injector.get(value))); | ||
} else { | ||
promises[key] = (this.$q.when(value)); | ||
} | ||
}); | ||
return this.$q.all(promises); | ||
} | ||
} | ||
@@ -20,0 +39,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
238577
4763