@angular-wave/angular.ts 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/index.html +66 -57
- package/package.json +1 -1
- package/src/animations/animate-children-directive.js +1 -1
- package/src/animations/animate-css-driver.js +1 -1
- package/src/animations/animate-css.js +2 -2
- package/src/animations/animate-js-driver.js +1 -1
- package/src/animations/animate-js.js +2 -2
- package/src/animations/animate-queue.js +3 -4
- package/src/animations/animation.js +1 -1
- package/src/animations/shared.js +4 -4
- package/src/core/animate-runner.js +1 -1
- package/src/core/animate.js +4 -5
- package/src/core/compile.js +5 -6
- package/src/core/controller.js +4 -3
- package/src/core/filter.js +1 -1
- package/src/core/interpolate.js +1 -1
- package/src/core/interval-factory.js +1 -1
- package/src/core/interval.js +1 -1
- package/src/core/location.js +1 -1
- package/src/core/parser/parse.js +1 -1
- package/src/core/q.js +2 -3
- package/src/core/root-scope.js +1 -1
- package/src/core/sanitize-uri.js +1 -1
- package/src/core/sce.js +1 -1
- package/src/core/task-tracker-factory.js +1 -1
- package/src/core/timeout.js +1 -1
- package/src/core/urlUtils.js +1 -1
- package/src/directive/attrs.js +1 -1
- package/src/directive/bind.js +1 -1
- package/src/directive/class.js +2 -2
- package/src/directive/events.js +1 -1
- package/src/directive/form.js +1 -1
- package/src/directive/include.js +1 -1
- package/src/directive/input.js +1 -1
- package/src/directive/list.js +2 -2
- package/src/directive/model-options.js +1 -1
- package/src/directive/model.js +1 -1
- package/src/directive/options.js +2 -3
- package/src/directive/ref.js +1 -1
- package/src/directive/repeat.js +1 -1
- package/src/directive/select.js +1 -1
- package/src/directive/switch.js +1 -1
- package/src/directive/transclude.js +1 -1
- package/src/directive/validators.js +1 -1
- package/src/exts/aria.js +1 -1
- package/src/exts/messages.js +3 -3
- package/src/exts/messages.md +28 -31
- package/src/filters/filter.js +2 -3
- package/src/filters/filters.js +1 -1
- package/src/filters/limit-to.js +1 -1
- package/src/filters/order-by.js +2 -3
- package/src/injector.js +8 -9
- package/src/jqLite.js +3 -4
- package/src/loader.js +1 -3
- package/src/public.js +1 -1
- package/src/router/common/coreservices.js +5 -0
- package/src/router/{core/common → common}/queue.js +1 -1
- package/src/router/{core/common → common}/trace.js +21 -19
- package/src/router/{adapter/directives → directives}/stateDirectives.js +24 -28
- package/src/router/{adapter/directives → directives}/viewDirective.js +9 -9
- package/src/router/{core/globals.js → globals.js} +13 -3
- package/src/router/{core/hooks → hooks}/coreResolvables.js +6 -4
- package/src/router/{core/hooks → hooks}/lazyLoad.js +5 -2
- package/src/router/{core/hooks → hooks}/redirectTo.js +1 -1
- package/src/router/{core/hooks → hooks}/resolve.js +2 -2
- package/src/router/{core/hooks → hooks}/updateGlobals.js +1 -1
- package/src/router/{core/hooks → hooks}/views.js +1 -1
- package/src/router/index.js +60 -0
- package/src/router/{adapter/injectables.js → injectables.js} +9 -9
- package/src/router/{adapter/locationServices.js → locationServices.js} +19 -12
- package/src/router/{core/params → params}/param.js +5 -10
- package/src/router/{core/params → params}/paramType.js +4 -4
- package/src/router/{core/params → params}/paramTypes.js +4 -3
- package/src/router/{core/params → params}/stateParams.js +1 -1
- package/src/router/{core/path → path}/pathNode.js +2 -2
- package/src/router/{core/path → path}/pathUtils.js +13 -7
- package/src/router/{core/resolve → resolve}/resolvable.js +5 -5
- package/src/router/{core/resolve → resolve}/resolveContext.js +16 -6
- package/src/router/router.js +172 -72
- package/src/router/{adapter/services.js → services.js} +47 -27
- package/src/router/{core/state → state}/stateBuilder.js +14 -10
- package/src/router/{core/state → state}/stateMatcher.js +2 -3
- package/src/router/{core/state → state}/stateObject.js +8 -6
- package/src/router/{core/state → state}/stateQueueManager.js +3 -3
- package/src/router/{core/state → state}/stateRegistry.js +6 -7
- package/src/router/{core/state → state}/stateService.js +12 -15
- package/src/router/{core/state → state}/targetState.js +2 -2
- package/src/router/{adapter/statebuilders → state}/views.js +17 -15
- package/src/router/{adapter/stateProvider.js → stateProvider.js} +52 -9
- package/src/router/{adapter/templateFactory.js → templateFactory.js} +10 -19
- package/src/router/{core/transition → transition}/hookBuilder.js +4 -3
- package/src/router/{core/transition → transition}/hookRegistry.js +3 -6
- package/src/router/{core/transition → transition}/rejectFactory.js +4 -5
- package/src/router/{core/transition → transition}/transition.js +10 -12
- package/src/router/{core/transition → transition}/transitionHook.js +4 -4
- package/src/router/{core/transition → transition}/transitionService.js +13 -13
- package/src/router/{core/url → url}/urlConfig.js +28 -19
- package/src/router/{core/url → url}/urlMatcher.js +14 -16
- package/src/router/{core/url → url}/urlMatcherFactory.js +7 -6
- package/src/router/{core/url → url}/urlRouter.js +6 -30
- package/src/router/{core/url → url}/urlRule.js +3 -3
- package/src/router/{core/url → url}/urlRules.js +10 -11
- package/src/router/{core/url → url}/urlService.js +12 -6
- package/src/router/{core/view → view}/view.js +32 -27
- package/src/router/{adapter/viewScroll.js → viewScroll.js} +3 -0
- package/src/services/anchor-scroll.js +1 -1
- package/src/services/browser.js +1 -1
- package/src/services/cache-factory.js +7 -1
- package/src/services/cookie-reader.js +1 -1
- package/src/services/http-backend.js +6 -1
- package/src/services/http.js +4 -5
- package/src/services/log.js +1 -1
- package/src/services/template-request.js +2 -2
- package/src/{router/core/common → shared}/common.js +35 -16
- package/src/{router/core/common → shared}/predicates.js +2 -12
- package/src/{router/core/common → shared}/strings.js +5 -13
- package/src/{core → shared}/utils.js +13 -29
- package/test/angular.spec.js +1 -31
- package/test/{ng → core}/animate.spec.js +1 -1
- package/test/{ng → core}/compile.spec.js +2 -3
- package/test/{ng → core}/http.spec.js +2 -2
- package/test/{ng → core}/on.spec.js +1 -1
- package/test/{ng → core}/parse.spec.js +1 -1
- package/test/{ng → core}/prop.spec.js +1 -1
- package/test/{ng → core}/scope.spec.js +1 -1
- package/test/{ng/directive → directive}/a.spec.js +4 -4
- package/test/{ng/directive → directive}/bind.spec.js +3 -3
- package/test/{ng/directive → directive}/boolean.spec.js +2 -2
- package/test/{ng/directive → directive}/change.spec.js +3 -3
- package/test/{ng/directive → directive}/class.spec.js +4 -4
- package/test/{ng/directive → directive}/click.spec.js +3 -3
- package/test/{ng/directive → directive}/cloak.spec.js +4 -4
- package/test/{ng/directive → directive}/constoller.spec.js +5 -5
- package/test/{ng/directive → directive}/element-style.spec.js +3 -3
- package/test/{ng/directive → directive}/event.spec.js +4 -4
- package/test/{ng/directive → directive}/form.spec.js +5 -5
- package/test/{ng/directive → directive}/href.spec.js +4 -4
- package/test/{ng/directive → directive}/if.spec.js +5 -5
- package/test/{ng/directive → directive}/include.spec.js +5 -5
- package/test/{ng/directive → directive}/init.spec.js +4 -4
- package/test/{ng/directive → directive}/input.spec.js +5 -5
- package/test/{ng/directive → directive}/list.spec.js +3 -3
- package/test/{ng/directive → directive}/model-options.spec.js +6 -6
- package/test/{ng/directive → directive}/model.spec.js +8 -8
- package/test/{ng/directive → directive}/non-bindable.spec.js +3 -3
- package/test/{ng/directive → directive}/options.spec.js +5 -5
- package/test/{ng/directive → directive}/ref.spec.js +2 -2
- package/test/{ng/directive → directive}/repeat.spec.js +5 -5
- package/test/{ng/directive → directive}/script.spec.js +3 -3
- package/test/{ng/directive → directive}/scrset.spec.js +3 -3
- package/test/{ng/directive → directive}/select.spec.js +5 -5
- package/test/{ng/directive → directive}/show-hide.spec.js +3 -3
- package/test/{ng/directive → directive}/src.spec.js +3 -3
- package/test/{ng/directive → directive}/style.spec.js +3 -3
- package/test/{ng/directive → directive}/switch.spec.js +3 -3
- package/test/{ng/directive → directive}/validators.spec.js +3 -3
- package/test/{ng/filter → filter}/filter.spec.js +4 -4
- package/test/{ng/filter → filter}/filters.spec.js +3 -3
- package/test/{ng/filter → filter}/limit-to.spec.js +3 -3
- package/test/{ng/filter → filter}/order-by.spec.js +2 -2
- package/test/injector.spec.js +1 -1
- package/test/jqlite.spec.js +1 -1
- package/test/messages/messages.spec.js +1 -1
- package/test/min-err.spec.js +1 -1
- package/test/original-test.html +4 -4
- package/test/router/glob.spec.js +78 -0
- package/test/router/state.spec.js +931 -0
- package/test/sanitize/bing-html.spec.js +1 -1
- package/test/shared/common.spec.js +283 -0
- package/test/shared/hof.spec.js +60 -0
- package/test/shared/strings.spec.js +40 -0
- package/test/{ng → shared}/utils.spec.js +1 -1
- package/types/router/angular.d.ts +1 -0
- package/types/router/core/common/common.d.ts +370 -0
- package/types/router/core/common/coreservices.d.ts +80 -0
- package/types/router/core/common/glob.d.ts +60 -0
- package/types/router/core/common/hof.d.ts +160 -0
- package/types/router/core/common/index.d.ts +8 -0
- package/types/router/core/common/predicates.d.ts +25 -0
- package/types/router/core/common/queue.d.ts +15 -0
- package/types/router/core/common/safeConsole.d.ts +5 -0
- package/types/router/core/common/strings.d.ts +64 -0
- package/types/router/core/common/trace.d.ts +114 -0
- package/types/router/core/globals.d.ts +45 -0
- package/types/router/core/hooks/coreResolvables.d.ts +4 -0
- package/types/router/core/hooks/ignoredTransition.d.ts +2 -0
- package/types/router/core/hooks/invalidTransition.d.ts +2 -0
- package/types/router/core/hooks/lazyLoad.d.ts +12 -0
- package/types/router/core/hooks/onEnterExitRetain.d.ts +4 -0
- package/types/router/core/hooks/redirectTo.d.ts +2 -0
- package/types/router/core/hooks/resolve.d.ts +5 -0
- package/types/router/core/hooks/updateGlobals.d.ts +2 -0
- package/types/router/core/hooks/url.d.ts +2 -0
- package/types/router/core/hooks/views.d.ts +3 -0
- package/types/router/core/index.d.ts +12 -0
- package/types/router/core/interface.d.ts +102 -0
- package/types/router/core/params/index.d.ts +12 -0
- package/types/router/core/params/interface.d.ts +606 -0
- package/types/router/core/params/param.d.ts +65 -0
- package/types/router/core/params/paramType.d.ts +65 -0
- package/types/router/core/params/paramTypes.d.ts +190 -0
- package/types/router/core/params/stateParams.d.ts +15 -0
- package/types/router/core/path/index.d.ts +2 -0
- package/types/router/core/path/pathNode.d.ts +60 -0
- package/types/router/core/path/pathUtils.d.ts +79 -0
- package/types/router/core/resolve/index.d.ts +3 -0
- package/types/router/core/resolve/interface.d.ts +210 -0
- package/types/router/core/resolve/resolvable.d.ts +69 -0
- package/types/router/core/resolve/resolveContext.d.ts +92 -0
- package/types/router/core/router.d.ts +95 -0
- package/types/router/core/state/index.d.ts +28 -0
- package/types/router/core/state/interface.d.ts +708 -0
- package/types/router/core/state/stateBuilder.d.ts +104 -0
- package/types/router/core/state/stateMatcher.d.ts +11 -0
- package/types/router/core/state/stateObject.d.ts +155 -0
- package/types/router/core/state/stateQueueManager.d.ts +24 -0
- package/types/router/core/state/stateRegistry.d.ts +136 -0
- package/types/router/core/state/stateService.d.ts +350 -0
- package/types/router/core/state/targetState.d.ts +100 -0
- package/types/router/core/transition/hookBuilder.d.ts +45 -0
- package/types/router/core/transition/hookRegistry.d.ts +93 -0
- package/types/router/core/transition/index.d.ts +20 -0
- package/types/router/core/transition/interface.d.ts +819 -0
- package/types/router/core/transition/rejectFactory.d.ts +103 -0
- package/types/router/core/transition/transition.d.ts +527 -0
- package/types/router/core/transition/transitionEventType.d.ts +17 -0
- package/types/router/core/transition/transitionHook.d.ts +88 -0
- package/types/router/core/transition/transitionService.d.ts +187 -0
- package/types/router/core/url/index.d.ts +8 -0
- package/types/router/core/url/interface.d.ts +156 -0
- package/types/router/core/url/urlConfig.d.ts +141 -0
- package/types/router/core/url/urlMatcher.d.ts +180 -0
- package/types/router/core/url/urlMatcherFactory.d.ts +52 -0
- package/types/router/core/url/urlRouter.d.ts +85 -0
- package/types/router/core/url/urlRule.d.ts +120 -0
- package/types/router/core/url/urlRules.d.ts +244 -0
- package/types/router/core/url/urlService.d.ts +206 -0
- package/types/router/core/vanilla.d.ts +1 -0
- package/types/router/core/view/index.d.ts +2 -0
- package/types/router/core/view/interface.d.ts +46 -0
- package/types/router/core/view/view.d.ts +167 -0
- package/types/router/directives/stateDirectives.d.ts +3 -0
- package/types/router/directives/viewDirective.d.ts +143 -0
- package/types/router/index.d.ts +19 -0
- package/types/router/interface.d.ts +491 -0
- package/types/router/legacy/resolveService.d.ts +44 -0
- package/types/router/legacy/stateEvents.d.ts +123 -0
- package/types/router/locationServices.d.ts +43 -0
- package/types/router/services.d.ts +15 -0
- package/types/router/stateFilters.d.ts +11 -0
- package/types/router/stateProvider.d.ts +254 -0
- package/types/router/statebuilders/onEnterExitRetain.d.ts +12 -0
- package/types/router/statebuilders/views.d.ts +41 -0
- package/types/router/templateFactory.d.ts +84 -0
- package/types/router/viewScroll.d.ts +9 -0
- package/src/router/adapter/statebuilders/onEnterExitRetain.js +0 -29
- package/src/router/core/common/coreservices.js +0 -15
- package/src/router/core/common/safeConsole.js +0 -38
- package/src/router/core/interface.js +0 -3
- package/src/router/core/resolve/interface.js +0 -10
- package/src/router/core/router.js +0 -203
- package/src/router/core/url/interface.js +0 -1
- package/src/router/core/view/interface.js +0 -1
- /package/src/router/{core/common → common}/glob.js +0 -0
- /package/src/router/{core/hooks → hooks}/ignoredTransition.js +0 -0
- /package/src/router/{core/hooks → hooks}/invalidTransition.js +0 -0
- /package/src/router/{core/hooks → hooks}/onEnterExitRetain.js +0 -0
- /package/src/router/{core/hooks → hooks}/url.js +0 -0
- /package/src/router/{core/params → params}/README.md +0 -0
- /package/src/router/{core/state → state}/README.md +0 -0
- /package/src/router/{adapter/stateFilters.js → stateFilters.js} +0 -0
- /package/src/router/{core/transition → transition}/interface.js +0 -0
- /package/src/router/{core/transition → transition}/transitionEventType.js +0 -0
- /package/src/{router/core/common → shared}/hof.js +0 -0
- /package/test/{ng → core}/cache-factor.spec.js +0 -0
- /package/test/{ng → core}/controller-provider.spec.js +0 -0
- /package/test/{ng → core}/cookie-reader.spec.js +0 -0
- /package/test/{ng → core}/document.spec.js +0 -0
- /package/test/{ng → core}/filter.spec.js +0 -0
- /package/test/{ng → core}/http-backend.spec.js +0 -0
- /package/test/{ng → core}/interpolate.spec.js +0 -0
- /package/test/{ng → core}/interval.spec.js +0 -0
- /package/test/{ng → core}/location.spec.js +0 -0
- /package/test/{ng → core}/q.spec.js +0 -0
- /package/test/{ng → core}/root-element.spec.js +0 -0
- /package/test/{ng → core}/sanitize-uri.spec.js +0 -0
- /package/test/{ng → core}/sce.spec.js +0 -0
- /package/test/{ng → core}/template-request.spec.js +0 -0
- /package/test/{ng → core}/timeout.spec.js +0 -0
- /package/test/{ng → core}/url-utils.spec.js +0 -0
- /package/{src/router/adapter/interface.js → types/router/injectables.d.ts} +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { defaults, filter, map, mapObj, pick } from "../../src/shared/common";
|
|
2
|
+
import { is, eq, not, pattern, val } from "../../src/shared/hof";
|
|
3
|
+
import { isInjectable } from "../../src/shared/predicates";
|
|
4
|
+
import { Queue } from "../../src/router/common/queue";
|
|
5
|
+
|
|
6
|
+
describe("common", function () {
|
|
7
|
+
describe("filter", function () {
|
|
8
|
+
it("should filter arrays", function () {
|
|
9
|
+
const input = [1, 2, 3, 4, 5];
|
|
10
|
+
const filtered = filter(input, function (int) {
|
|
11
|
+
return int > 2;
|
|
12
|
+
});
|
|
13
|
+
expect(filtered.length).toBe(3);
|
|
14
|
+
expect(filtered).toEqual([3, 4, 5]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should properly compact arrays", function () {
|
|
18
|
+
expect(
|
|
19
|
+
filter([0, 1, 0, 2, 0, 3, 4], function (v) {
|
|
20
|
+
return !!v;
|
|
21
|
+
}),
|
|
22
|
+
).toEqual([1, 2, 3, 4]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should filter objects", function () {
|
|
26
|
+
const input = { foo: 1, bar: 2, baz: 3, qux: 4 };
|
|
27
|
+
const filtered = filter(input, function (value, _key) {
|
|
28
|
+
return value > 2;
|
|
29
|
+
});
|
|
30
|
+
expect(Object.keys(filtered).length).toBe(2);
|
|
31
|
+
expect(filtered).toEqual({ baz: 3, qux: 4 });
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("defaults", function () {
|
|
36
|
+
it("should do left-associative object merge", function () {
|
|
37
|
+
const options = { param1: "new val" };
|
|
38
|
+
const result = defaults(options, {
|
|
39
|
+
param1: "default val",
|
|
40
|
+
param2: "default val 2",
|
|
41
|
+
});
|
|
42
|
+
expect(result).toEqual({ param1: "new val", param2: "default val 2" });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should whitelist keys present in default values", function () {
|
|
46
|
+
const options = { param1: 1, param2: 2, param3: 3 };
|
|
47
|
+
const result = defaults(options, {
|
|
48
|
+
param1: 0,
|
|
49
|
+
param2: 0,
|
|
50
|
+
});
|
|
51
|
+
expect(result).toEqual({ param1: 1, param2: 2 });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should return an object when passed an empty value", function () {
|
|
55
|
+
const vals = { param1: 0, param2: 0 };
|
|
56
|
+
expect(defaults(null, vals)).toEqual(vals);
|
|
57
|
+
expect(defaults(undefined, vals)).toEqual(vals);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("not", function () {
|
|
62
|
+
it("should allow double-negatives", function () {
|
|
63
|
+
function T() {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function F() {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
function empty() {
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
expect(not(not(T))()).toBe(true);
|
|
74
|
+
expect(not(not(F))()).toBe(false);
|
|
75
|
+
expect(not(not(empty))()).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("val", function () {
|
|
80
|
+
it("should return identity", function () {
|
|
81
|
+
const f = function () {},
|
|
82
|
+
foo = {};
|
|
83
|
+
expect(val(f)()).toBe(f);
|
|
84
|
+
expect(val(foo)()).toBe(foo);
|
|
85
|
+
expect(val(true)()).toBe(true);
|
|
86
|
+
expect(val(false)()).toBe(false);
|
|
87
|
+
expect(val(null)()).toBe(null);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("pattern", function () {
|
|
92
|
+
it("should return the result of a paired function when a condition function returns true", function () {
|
|
93
|
+
const typeChecker = pattern([
|
|
94
|
+
[is(Number), val("number!")],
|
|
95
|
+
[is(String), val("string!")],
|
|
96
|
+
[is(Boolean), val("boolean!")],
|
|
97
|
+
[eq(null), val("null!")],
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
expect(typeChecker(1)).toBe("number!");
|
|
101
|
+
expect(typeChecker("foo!")).toBe("string!");
|
|
102
|
+
expect(typeChecker(true)).toBe("boolean!");
|
|
103
|
+
expect(typeChecker(false)).toBe("boolean!");
|
|
104
|
+
expect(typeChecker(null)).toBe("null!");
|
|
105
|
+
expect(typeChecker(undefined)).toBe(undefined);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("isInjectable", function () {
|
|
110
|
+
it("should accept functions", function () {
|
|
111
|
+
function fn() {}
|
|
112
|
+
expect(isInjectable(fn)).toBeTruthy();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should accept functions with parameters", function () {
|
|
116
|
+
function fn(_foo, _bar) {}
|
|
117
|
+
expect(isInjectable(fn)).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should accept ng1 annotated functions", function () {
|
|
121
|
+
fn["$inject"] = ["foo", "bar"];
|
|
122
|
+
function fn(_foo, _bar) {}
|
|
123
|
+
expect(isInjectable(fn)).toBeTruthy();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should accept ng1 array notation", function () {
|
|
127
|
+
const fn = ["foo", "bar", function (_foo, _bar) {}];
|
|
128
|
+
expect(isInjectable(fn)).toBeTruthy();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("pick", () => {
|
|
133
|
+
it("should pick inherited properties", () => {
|
|
134
|
+
const parent = { foo: "foo", bar: "bar" };
|
|
135
|
+
const child = Object.create(parent);
|
|
136
|
+
expect(pick(child, ["foo"])).toEqual({ foo: "foo" });
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should not pick missing properties", () => {
|
|
140
|
+
const obj = { foo: "foo", bar: "bar" };
|
|
141
|
+
expect(pick(obj, ["baz"])).toEqual({});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("map", () => {
|
|
146
|
+
it("should map arrays", () => {
|
|
147
|
+
const src = [1, 2, 3, 4];
|
|
148
|
+
const dest = map(src, (x) => x * 2);
|
|
149
|
+
|
|
150
|
+
expect(src).toEqual([1, 2, 3, 4]);
|
|
151
|
+
expect(dest).toEqual([2, 4, 6, 8]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should map arrays in place when target === src", () => {
|
|
155
|
+
const src = [1, 2, 3, 4];
|
|
156
|
+
const dest = map(src, (x) => x * 2, src);
|
|
157
|
+
|
|
158
|
+
expect(src).toEqual([2, 4, 6, 8]);
|
|
159
|
+
expect(dest).toEqual([2, 4, 6, 8]);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("mapObj", () => {
|
|
164
|
+
it("should map objects", () => {
|
|
165
|
+
const src = { foo: 1, bar: 2, baz: 3 };
|
|
166
|
+
const dest = mapObj(src, (x) => x * 2);
|
|
167
|
+
|
|
168
|
+
expect(src).toEqual({ foo: 1, bar: 2, baz: 3 });
|
|
169
|
+
expect(dest).toEqual({ foo: 2, bar: 4, baz: 6 });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should map objects in place when target === src", () => {
|
|
173
|
+
const src = { foo: 1, bar: 2, baz: 3 };
|
|
174
|
+
const dest = mapObj(src, (x) => x * 2, src);
|
|
175
|
+
|
|
176
|
+
expect(src).toEqual({ foo: 2, bar: 4, baz: 6 });
|
|
177
|
+
expect(dest).toEqual({ foo: 2, bar: 4, baz: 6 });
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("Queue", () => {
|
|
182
|
+
it("peekTail() should show the last enqueued item", () => {
|
|
183
|
+
const q = new Queue();
|
|
184
|
+
q.enqueue(1);
|
|
185
|
+
q.enqueue(2);
|
|
186
|
+
q.enqueue(3);
|
|
187
|
+
expect(q.size()).toBe(3);
|
|
188
|
+
expect(q.peekTail()).toBe(3);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("peekHead() should show the first enqueued item", () => {
|
|
192
|
+
const q = new Queue();
|
|
193
|
+
q.enqueue(1);
|
|
194
|
+
q.enqueue(2);
|
|
195
|
+
q.enqueue(3);
|
|
196
|
+
expect(q.size()).toBe(3);
|
|
197
|
+
expect(q.peekHead()).toBe(1);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("should support a limit (max number of items)", () => {
|
|
201
|
+
const q = new Queue([], 2);
|
|
202
|
+
q.enqueue(1);
|
|
203
|
+
q.enqueue(2);
|
|
204
|
+
q.enqueue(3);
|
|
205
|
+
expect(q.size()).toBe(2);
|
|
206
|
+
expect(q.peekHead()).toBe(2);
|
|
207
|
+
expect(q.peekTail()).toBe(3);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("clear() should remove all items", () => {
|
|
211
|
+
const q = new Queue([], 2);
|
|
212
|
+
q.enqueue(1);
|
|
213
|
+
q.enqueue(2);
|
|
214
|
+
q.enqueue(3);
|
|
215
|
+
expect(q.size()).toBe(2);
|
|
216
|
+
|
|
217
|
+
q.clear();
|
|
218
|
+
expect(q.size()).toBe(0);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("enqueue() should evict from the head when max length is reached", () => {
|
|
222
|
+
const q = new Queue([], 3);
|
|
223
|
+
q.enqueue(1);
|
|
224
|
+
q.enqueue(2);
|
|
225
|
+
q.enqueue(3);
|
|
226
|
+
expect(q.size()).toBe(3);
|
|
227
|
+
|
|
228
|
+
q.enqueue(4);
|
|
229
|
+
expect(q.size()).toBe(3);
|
|
230
|
+
|
|
231
|
+
const a = q.dequeue();
|
|
232
|
+
const b = q.dequeue();
|
|
233
|
+
const c = q.dequeue();
|
|
234
|
+
|
|
235
|
+
expect(q.size()).toBe(0);
|
|
236
|
+
expect([a, b, c]).toEqual([2, 3, 4]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("onEvict() handlers should be called when an item is evicted", () => {
|
|
240
|
+
const log = [];
|
|
241
|
+
const q = new Queue([], 2);
|
|
242
|
+
|
|
243
|
+
q.onEvict((item) => log.push(item));
|
|
244
|
+
|
|
245
|
+
q.enqueue(1);
|
|
246
|
+
expect(q.size()).toBe(1);
|
|
247
|
+
expect(log).toEqual([]);
|
|
248
|
+
|
|
249
|
+
q.enqueue(2);
|
|
250
|
+
expect(q.size()).toBe(2);
|
|
251
|
+
expect(log).toEqual([]);
|
|
252
|
+
|
|
253
|
+
q.enqueue(3);
|
|
254
|
+
expect(q.size()).toBe(2);
|
|
255
|
+
expect(log).toEqual([1]);
|
|
256
|
+
|
|
257
|
+
q.enqueue(4);
|
|
258
|
+
expect(q.size()).toBe(2);
|
|
259
|
+
expect(log).toEqual([1, 2]);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("onEvict() should support multiple handlers", () => {
|
|
263
|
+
const log = [];
|
|
264
|
+
const log2 = [];
|
|
265
|
+
const q = new Queue([], 2);
|
|
266
|
+
|
|
267
|
+
q.onEvict((item) => log.push(item));
|
|
268
|
+
q.onEvict((item) => log2.push(item));
|
|
269
|
+
|
|
270
|
+
q.enqueue(1);
|
|
271
|
+
q.enqueue(2);
|
|
272
|
+
q.enqueue(3);
|
|
273
|
+
expect(q.size()).toBe(2);
|
|
274
|
+
expect(log).toEqual([1]);
|
|
275
|
+
expect(log2).toEqual([1]);
|
|
276
|
+
|
|
277
|
+
q.enqueue(4);
|
|
278
|
+
expect(q.size()).toBe(2);
|
|
279
|
+
expect(log).toEqual([1, 2]);
|
|
280
|
+
expect(log2).toEqual([1, 2]);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { curry } from "../../src/shared/hof";
|
|
2
|
+
|
|
3
|
+
describe("curry", () => {
|
|
4
|
+
let original;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
original = jasmine.createSpy("original", function (a, b, c) {});
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should accept a function and return a new function", () => {
|
|
11
|
+
expect(typeof curry(original)).toBe("function");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should return a function that invokes original only when all arguments are supplied", () => {
|
|
15
|
+
const curried1 = curry(original);
|
|
16
|
+
curried1(1, 2, 3);
|
|
17
|
+
expect(original).toHaveBeenCalledTimes(1);
|
|
18
|
+
expect(original).toHaveBeenCalledWith(1, 2, 3);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should pass extra arguments through to original function", () => {
|
|
22
|
+
const curried1 = curry(original);
|
|
23
|
+
curried1(1, 2, 3, 4);
|
|
24
|
+
expect(original).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(original).toHaveBeenCalledWith(1, 2, 3, 4);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should keep returning functions that return functions if no arguments are supplied", () => {
|
|
29
|
+
const curried1 = curry(original);
|
|
30
|
+
expect(typeof curried1).toBe("function");
|
|
31
|
+
|
|
32
|
+
const curried2 = curried1();
|
|
33
|
+
expect(typeof curried2).toBe("function");
|
|
34
|
+
|
|
35
|
+
const curried3 = curried2();
|
|
36
|
+
expect(typeof curried3).toBe("function");
|
|
37
|
+
|
|
38
|
+
const curried4 = curried3();
|
|
39
|
+
expect(typeof curried4).toBe("function");
|
|
40
|
+
|
|
41
|
+
const curried5 = curried4();
|
|
42
|
+
expect(typeof curried5).toBe("function");
|
|
43
|
+
|
|
44
|
+
const curried6 = curried5();
|
|
45
|
+
expect(typeof curried6).toBe("function");
|
|
46
|
+
|
|
47
|
+
expect(original).toHaveBeenCalledTimes(0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should keep returning functions that return functions until all arguments are supplied", () => {
|
|
51
|
+
const curried1 = curry(original);
|
|
52
|
+
const curried2 = curried1(1);
|
|
53
|
+
const curried3 = curried2(2);
|
|
54
|
+
const result = curried3(3);
|
|
55
|
+
|
|
56
|
+
expect(result).toBeUndefined();
|
|
57
|
+
expect(original).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(original).toHaveBeenCalledWith(1, 2, 3);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { stripLastPathElement } from "../../src/shared/strings";
|
|
2
|
+
|
|
3
|
+
describe("string functions:", () => {
|
|
4
|
+
describe("stripLastPathElement", () => {
|
|
5
|
+
it("should strip trailing filenames from a path", () => {
|
|
6
|
+
const result = stripLastPathElement("/some/path/to/file.html");
|
|
7
|
+
expect(result).toBe("/some/path/to");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should strip a filename (with no extension) from a path ", () => {
|
|
11
|
+
const result = stripLastPathElement("/some/path/to/file");
|
|
12
|
+
expect(result).toBe("/some/path/to");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should strip trailing filenames from a root path", () => {
|
|
16
|
+
const result = stripLastPathElement("/file.html");
|
|
17
|
+
expect(result).toBe("");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should strip a filename (with no extension) from a root path", () => {
|
|
21
|
+
const result = stripLastPathElement("/file");
|
|
22
|
+
expect(result).toBe("");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should strip a trailing slash", () => {
|
|
26
|
+
expect(stripLastPathElement("/path/")).toBe("/path");
|
|
27
|
+
expect(stripLastPathElement("/path/foo/")).toBe("/path/foo");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should return empty string given an empty string", () => {
|
|
31
|
+
const result = stripLastPathElement("");
|
|
32
|
+
expect(result).toBe("");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should return an empty string given a slash", () => {
|
|
36
|
+
const result = stripLastPathElement("/");
|
|
37
|
+
expect(result).toBe("");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/** @hidden */ export declare const ng: any;
|