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

angular-es-utils

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-es-utils - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

karma.conf.js

57

package.json
{
"name": "angular-es-utils",
"version": "1.1.1",
"version": "1.2.0",
"description": "es utils design for angular1.x",

@@ -9,24 +9,8 @@ "main": "./lib/index.js",

"codecheck": "NODE_EVN=test eslint src",
"start": "node server.js",
"prepush": "npm test",
"test": "ava -v"
"start": "NODE_ENV=dev karma start",
"prepush": "npm run codecheck && npm test",
"test": "karma start --single-run"
},
"author": "Kuitos<kuitos.lau@gmail.com>",
"ava": {
"files": [
"src/**/__tests__/*.js"
],
"require": [
"babel-register",
"./ava-test-helper.js"
],
"babel": "inherit"
},
"devDependencies": {
"angular": "^1.5.3",
"angular-mock": "^1.0.0",
"angular-mocks": "^1.5.3",
"assets-webpack-plugin": "^3.1.0",
"autoprefixer": "^6.3.6",
"ava": "^0.14.0",
"babel-core": "^6.7.4",

@@ -38,6 +22,3 @@ "babel-eslint": "^4.1.3",

"babel-preset-stage-0": "^6.5.0",
"clean-webpack-plugin": "^0.1.4",
"css-loader": "^0.21.0",
"esdoc": "^0.4.6",
"esdoc-es7-plugin": "0.0.3",
"chai": "^3.5.0",
"eslint": "^1.8.0",

@@ -47,24 +28,16 @@ "eslint-friendly-formatter": "^1.2.2",

"eslint-plugin-standard": "^1.3.1",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"html-loader": "^0.4.0",
"husky": "^0.10.1",
"image-webpack-loader": "^1.6.3",
"jsdom": "^8.3.1",
"json-mock-kuitos": "^1.0.3",
"node-dir": "^0.1.11",
"node-sass": "^3.4.1",
"postcss-loader": "^0.7.0",
"resolve-url-loader": "^1.4.3",
"sass-loader": "^3.1.1",
"style-loader": "^0.13.0",
"url-loader": "^0.5.7",
"webpack": "^1.12.2",
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.4.1"
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.3",
"karma-coverage": "^0.5.5",
"karma-mocha": "^0.2.2",
"karma-mocha-reporter": "^2.0.2",
"karma-webpack": "^1.7.0",
"mocha": "^2.4.5",
"webpack": "^1.13.0"
},
"dependencies": {
"angular": "^1.5.0"
"angular": "^1.5.3",
"angular-mocks": "^1.5.3"
}
}

@@ -37,3 +37,3 @@ /**

});
element.classList.add(className);

@@ -46,3 +46,3 @@ },

});
element.classList.remove(className);

@@ -49,0 +49,0 @@ }

@@ -7,78 +7,80 @@ /**

import test from 'ava';
import Bind from '../Bind';
import Inject from '../Inject';
import Throttle from '../Throttle';
import Debounce from '../Debounce';
import useCase from './use-case';
import {assert} from 'chai';
@Inject('$scope', '$q')
class Test {
describe('decorators', () => {
constructor() {
this.name = 'kuitos';
this.age = 0;
}
let $injector, serviceInstance, controllerInstance, componentController, $scope, bindings;
@Bind
getName() {
return this.name;
}
beforeEach(angular.mock.module(useCase));
beforeEach(angular.mock.inject((_$injector_, _$controller_, _$rootScope_, $componentController) => {
$injector = _$injector_;
$scope = _$rootScope_.$new();
componentController = $componentController('component', {$scope}, bindings = {data: {name: 'component'}});
serviceInstance = $injector.get('Service');
controllerInstance = _$controller_('Controller', {$scope});
}));
@Throttle(100)
resize() {
this.age++;
}
describe('inject', () => {
@Debounce(100)
switcher(cb) {
this.age++;
cb();
}
it('Service Recipe: external service should be members of instance which start with underscore', () => {
assert.equal(serviceInstance._$q, $injector.get('$q'));
assert.equal(serviceInstance.getQ(), $injector.get('$q'));
});
}
it('Controller Recipe: external service should be members of instance which start with underscore', () => {
assert.equal(controllerInstance._$scope, $scope);
});
test('inject decorator', t => {
it('Component Recipe: external service should be members of instance which start with underscore', () => {
assert.equal(componentController._$scope, $scope);
});
const ctrl = new (Function.prototype.bind.apply(Test, [null, {name: '$scope'}, {name: '$q'}]))();
it('Component Controller Recipe: bindings data should be bind to controller instance', () => {
assert.equal(componentController.data, bindings.data);
assert.equal(componentController._$scope.$ctrl.data, bindings.data);
assert.equal(componentController.recipe, 'componentController');
});
t.deepEqual(Test.$inject, ['$scope', '$q']);
t.is(ctrl._$scope.name, '$scope');
t.is(ctrl._$q.name, '$q');
t.is(ctrl.name, 'kuitos');
t.is(ctrl.getName(), 'kuitos');
});
});
describe('bind', () => {
test('bind decorator', t => {
it('Service Recipe: this pointer always equal service instance', () => {
const getName = serviceInstance.getName;
assert.equal(getName(), serviceInstance.name);
});
const test = new Test();
const getName = test.getName;
t.is(getName(), 'kuitos');
it('Component Controller Recipe: this pointer always equal component controller instance', () => {
const getRecipe = componentController.getRecipe;
assert.equal(getRecipe(), componentController.recipe);
});
});
});
describe('throttle', () => {
test('throttle decorator', t => {
it('service recipe: method only run once per 100 milliseconds', () => {
const now = Date.now();
while (Date.now() - now < 1000) {
serviceInstance.resize();
}
assert.equal(serviceInstance.age, 10);
});
const test = new Test();
});
let now = Date.now();
while (Date.now() - now < 1000) {
test.resize();
}
describe('debounce', () => {
t.is(test.age, 10);
});
it('service recipe: method only run once in 1000 milliseconds', done => {
const now = Date.now();
while (Date.now() - now < 1000) {
test.cb('debounce decorator', t => {
const test = new Test();
let now = Date.now();
while (Date.now() - now < 1000) {
test.switcher(() => {
t.is(test.age, 1);
t.end();
serviceInstance.switcher(() => {
assert.equal(serviceInstance.age, 1);
done();
});
}
});
}
});
});

@@ -16,9 +16,16 @@ /**

const OriginalConstructor = target;
class Constructor {
constructor(...args) {
// 将依赖服务挂载在原始构造函数的prototype上(不是直接绑定到this上,节省空间)
args.forEach((arg, i) => target.prototype[`_${dependencies[i]}`] = arg);
// 使用原始构造函数实例化
return new target(...args);
let instance = new OriginalConstructor(...args);
// 存在通过 fn.apply(instance, locals) 的方式调用的情况,所以需要把apply过来的实例的属性复制一遍
Object.assign(instance, this);
// 将注入的服务已下滑线开头(私有属性)的命名规则绑定到实例上
dependencies.forEach((dependency, i) => instance[`_${dependency}`] = args[i]);
return instance;
}

@@ -25,0 +32,0 @@ }

@@ -7,35 +7,29 @@ /**

import test from 'ava';
import Inject from '../../decorators/Inject';
import FactoryCreator from '../index';
import useCase from './use-case';
import {assert} from 'chai';
@Inject('$scope')
class Test {
describe('factory creator', () => {
constructor() {
this.name = 'kuitos';
}
let $compile, $rootScope, directive;
getScope() {
return this._$scope;
}
beforeEach(angular.mock.module(useCase));
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
$compile = _$compile_;
$rootScope = _$rootScope_;
getName() {
return this.name;
}
const scope = $rootScope.$new();
Object.assign(scope, {data: {name: 'kuitos'}});
directive = $compile('<directive data="data"></directive>')(scope);
}
}));
test('factory creator should bind this to function', t => {
describe('transform directive constructor into factory', () => {
const testFactory = FactoryCreator.create(Test);
it('controller $onInit should run before link function', () => {
$rootScope.$digest();
assert.include(directive.html(), 'kuitos rootScope');
});
const test = testFactory({name: 'scope'});
});
const getScope = test.getScope;
const getName = test.getName;
t.is(getName(), 'kuitos');
t.is(getScope().name, 'scope');
});

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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