@angular-wave/angular.ts 0.4.6 → 0.5.0

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "description": "A modern, optimized and typesafe version of AngularJS",
4
4
  "license": "MIT",
5
- "version": "0.4.6",
5
+ "version": "0.5.0",
6
6
  "type": "module",
7
7
  "main": "dist/angular-ts.esm.js",
8
8
  "browser": "dist/angular-ts.umd.js",
@@ -61,7 +61,7 @@ export function AnimateJsProvider($animateProvider) {
61
61
  beforeFn = "leave";
62
62
  afterFn = "afterLeave"; // TODO(matsko): get rid of this
63
63
  } else {
64
- beforeFn = `before${event.charAt(0).toUpperCase()}${event.substr(1)}`;
64
+ beforeFn = `before${event.charAt(0).toUpperCase()}${event.substring(1)}`;
65
65
  afterFn = event;
66
66
  }
67
67
 
@@ -118,7 +118,7 @@ export function AnimateProvider($provide) {
118
118
  }
119
119
 
120
120
  const key = `${name}-animation`;
121
- provider.$$registeredAnimations[name.substr(1)] = key;
121
+ provider.$$registeredAnimations[name.substring(1)] = key;
122
122
  $provide.factory(key, factory);
123
123
  };
124
124
 
@@ -1010,7 +1010,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
1010
1010
  name = name
1011
1011
  .replace(PREFIX_REGEXP, "")
1012
1012
  .toLowerCase()
1013
- .substr(4 + ngPrefixMatch[1].length)
1013
+ .substring(4 + ngPrefixMatch[1].length)
1014
1014
  .replace(/_(.)/g, (match, letter) => letter.toUpperCase());
1015
1015
 
1016
1016
  // Support *-start / *-end multi element directives
@@ -1019,8 +1019,8 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
1019
1019
  directiveIsMultiElement(multiElementMatch[1])
1020
1020
  ) {
1021
1021
  attrStartName = name;
1022
- attrEndName = `${name.substr(0, name.length - 5)}end`;
1023
- name = name.substr(0, name.length - 6);
1022
+ attrEndName = `${name.substring(0, name.length - 5)}end`;
1023
+ name = name.substring(0, name.length - 6);
1024
1024
  }
1025
1025
 
1026
1026
  if (isNgProp || isNgEvent) {
@@ -2100,7 +2100,7 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
2100
2100
  *
2101
2101
  * @param {string} name name of the directive to look up.
2102
2102
  * @param {string} location The directive must be found in specific format.
2103
- * String containing any of theses characters:
2103
+ * String containing any of these characters:
2104
2104
  *
2105
2105
  * * `E`: element name
2106
2106
  * * `A': attribute
@@ -2115,8 +2115,8 @@ export function CompileProvider($provide, $$sanitizeUriProvider) {
2115
2115
  startAttrName,
2116
2116
  endAttrName,
2117
2117
  ) {
2118
- if (name === ignoreDirective) return null;
2119
- let match = null;
2118
+ if (name === ignoreDirective) return false;
2119
+ let match = false;
2120
2120
  if (Object.prototype.hasOwnProperty.call(hasDirectives, name)) {
2121
2121
  for (
2122
2122
  let directive,
@@ -13,7 +13,7 @@ describe("$$cookieReader", () => {
13
13
  for (let i = 0; i < cookies.length; i++) {
14
14
  const cookie = cookies[i];
15
15
  const eqPos = cookie.indexOf("=");
16
- const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
16
+ const name = eqPos > -1 ? cookie.substring(0, eqPos) : cookie;
17
17
  const parts = path.split("/");
18
18
  while (parts.length) {
19
19
  document.cookie = `${name}=;path=${parts.join("/") || "/"};expires=Thu, 01 Jan 1970 00:00:00 GMT`;
@@ -2,6 +2,7 @@ import { JQLite } from "../../shared/jqlite/jqlite";
2
2
  import { urlResolve } from "../url-utils/url-utils";
3
3
  import {
4
4
  encodeUriSegment,
5
+ isBoolean,
5
6
  isDefined,
6
7
  isNumber,
7
8
  isObject,
@@ -389,7 +390,7 @@ export class LocationHtml5Url extends Location {
389
390
  }
390
391
 
391
392
  $$normalizeUrl(url) {
392
- return this.appBaseNoFile + url.substr(1); // first char is always '/'
393
+ return this.appBaseNoFile + url.substring(1); // first char is always '/'
393
394
  }
394
395
 
395
396
  /**
@@ -541,28 +542,26 @@ export class LocationHashbangUrl extends Location {
541
542
  }
542
543
  }
543
544
 
544
- export class LocationProvider {
545
- constructor() {
546
- this.hashPrefixValue = "!";
547
- this.html5ModeConfig = {
548
- enabled: false,
549
- requireBase: true,
550
- rewriteLinks: true,
551
- };
552
- }
545
+ export function LocationProvider() {
546
+ let hashPrefix = "!";
547
+ const html5Mode = {
548
+ enabled: false,
549
+ requireBase: true,
550
+ rewriteLinks: true,
551
+ };
553
552
 
554
553
  /**
555
554
  * The default value for the prefix is `'!'`.
556
- * @param {string=} prefix - Prefix for hash part (containing path and search)
557
- * @returns {string|LocationProvider} current value if used as getter or itself (chaining) if used as setter
555
+ * @param {string=} prefix Prefix for hash part (containing path and search)
556
+ * @returns {*} current value if used as getter or itself (chaining) if used as setter
558
557
  */
559
- hashPrefix(prefix) {
560
- if (typeof prefix !== "undefined") {
561
- this.hashPrefixValue = prefix;
558
+ this.hashPrefix = function (prefix) {
559
+ if (isDefined(prefix)) {
560
+ hashPrefix = prefix;
562
561
  return this;
563
562
  }
564
- return this.hashPrefixValue;
565
- }
563
+ return hashPrefix;
564
+ };
566
565
 
567
566
  /**
568
567
  * @param {(boolean|Object)=} mode If boolean, sets `html5Mode.enabled` to value.
@@ -584,29 +583,30 @@ export class LocationProvider {
584
583
  *
585
584
  * @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter
586
585
  */
587
- html5Mode(mode) {
588
- if (typeof mode === "boolean") {
589
- this.html5ModeConfig.enabled = mode;
586
+ this.html5Mode = function (mode) {
587
+ if (isBoolean(mode)) {
588
+ html5Mode.enabled = mode;
590
589
  return this;
591
590
  }
591
+ if (isObject(mode)) {
592
+ if (isBoolean(mode.enabled)) {
593
+ html5Mode.enabled = mode.enabled;
594
+ }
592
595
 
593
- if (typeof mode === "object") {
594
- if (typeof mode.enabled === "boolean")
595
- this.html5ModeConfig.enabled = mode.enabled;
596
- if (typeof mode.requireBase === "boolean")
597
- this.html5ModeConfig.requireBase = mode.requireBase;
598
- if (
599
- typeof mode.rewriteLinks === "boolean" ||
600
- typeof mode.rewriteLinks === "string"
601
- ) {
602
- this.html5ModeConfig.rewriteLinks = mode.rewriteLinks;
596
+ if (isBoolean(mode.requireBase)) {
597
+ html5Mode.requireBase = mode.requireBase;
603
598
  }
599
+
600
+ if (isBoolean(mode.rewriteLinks) || isString(mode.rewriteLinks)) {
601
+ html5Mode.rewriteLinks = mode.rewriteLinks;
602
+ }
603
+
604
604
  return this;
605
605
  }
606
- return this.html5ModeConfig;
607
- }
606
+ return html5Mode;
607
+ };
608
608
 
609
- $get = [
609
+ this.$get = [
610
610
  "$rootScope",
611
611
  "$browser",
612
612
  "$rootElement",
@@ -625,8 +625,8 @@ export class LocationProvider {
625
625
  const initialUrl = /** @type {string} */ ($browser.url());
626
626
  let appBase;
627
627
 
628
- if (this.html5Mode.enabled) {
629
- if (!baseHref && this.html5Mode.requireBase) {
628
+ if (html5Mode.enabled) {
629
+ if (!baseHref && html5Mode.requireBase) {
630
630
  throw $locationMinErr(
631
631
  "nobase",
632
632
  "$location in HTML5 mode requires a <base> tag to be present!",
@@ -640,11 +640,7 @@ export class LocationProvider {
640
640
  }
641
641
  const appBaseNoFile = stripFile(appBase);
642
642
 
643
- $location = new LocationMode(
644
- appBase,
645
- appBaseNoFile,
646
- `#${this.hashPrefix}`,
647
- );
643
+ $location = new LocationMode(appBase, appBaseNoFile, `#${hashPrefix}`);
648
644
  $location.$$parseLinkUrl(initialUrl, initialUrl);
649
645
 
650
646
  $location.$$state = $browser.state();
@@ -671,7 +667,7 @@ export class LocationProvider {
671
667
  }
672
668
 
673
669
  $rootElement.on("click", (event) => {
674
- const { rewriteLinks } = this.html5Mode;
670
+ const { rewriteLinks } = html5Mode;
675
671
  // TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
676
672
  // currently we open nice url link and redirect then
677
673
 
@@ -774,7 +770,7 @@ export class LocationProvider {
774
770
  });
775
771
 
776
772
  // update browser
777
- function browserUpdate() {
773
+ $rootScope.$watch(() => {
778
774
  if (initializing || $location.$$urlUpdatedByLocation) {
779
775
  $location.$$urlUpdatedByLocation = false;
780
776
 
@@ -822,9 +818,7 @@ export class LocationProvider {
822
818
 
823
819
  // we don't need to return anything because $evalAsync will make the digest loop dirty when
824
820
  // there is a change
825
- }
826
-
827
- setTimeout(() => browserUpdate());
821
+ });
828
822
 
829
823
  return $location;
830
824
 
@@ -836,7 +830,6 @@ export class LocationProvider {
836
830
  $location.$$state,
837
831
  oldState,
838
832
  );
839
- browserUpdate();
840
833
  }
841
834
  },
842
835
  ];
@@ -889,6 +882,19 @@ function normalizePath(pathValue, searchValue, hashValue) {
889
882
  return path + (search ? `?${search}` : "") + hash;
890
883
  }
891
884
 
885
+ /**
886
+ * @param {string} absoluteUrl
887
+ * @param {Location} locationObj
888
+ */
889
+ function parseAbsoluteUrl(absoluteUrl, locationObj) {
890
+ const parsedUrl = urlResolve(absoluteUrl);
891
+
892
+ locationObj.$$protocol = parsedUrl.protocol;
893
+ locationObj.$$host = parsedUrl.hostname;
894
+ locationObj.$$port =
895
+ toInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
896
+ }
897
+
892
898
  function parseAppUrl(url, locationObj, html5Mode) {
893
899
  if (/^\s*[\\/]{2,}/.test(url)) {
894
900
  throw $locationMinErr("badpath", 'Invalid url "{0}".', url);
@@ -926,17 +932,17 @@ function startsWith(str, search) {
926
932
  */
927
933
  export function stripBaseUrl(base, url) {
928
934
  if (startsWith(url, base)) {
929
- return url.substr(base.length);
935
+ return url.substring(base.length);
930
936
  }
931
937
  }
932
938
 
933
939
  export function stripHash(url) {
934
940
  const index = url.indexOf("#");
935
- return index === -1 ? url : url.substr(0, index);
941
+ return index === -1 ? url : url.substring(0, index);
936
942
  }
937
943
 
938
944
  export function stripFile(url) {
939
- return url.substr(0, stripHash(url).lastIndexOf("/") + 1);
945
+ return url.substring(0, stripHash(url).lastIndexOf("/") + 1);
940
946
  }
941
947
 
942
948
  /* return the server only (scheme://host:port) */
@@ -688,7 +688,7 @@ describe("parser", () => {
688
688
  scope.zero = 0;
689
689
  scope.bool = false;
690
690
 
691
- expect(scope.$eval("empty.substr(0)")).toBe("");
691
+ expect(scope.$eval("empty.substring(0)")).toBe("");
692
692
  expect(scope.$eval("zero.toString()")).toBe("0");
693
693
  expect(scope.$eval("bool.toString()")).toBe("false");
694
694
  });
@@ -1265,7 +1265,7 @@ describe("ngModel", () => {
1265
1265
 
1266
1266
  it("should always use the most recent $viewValue for validation", () => {
1267
1267
  ctrl.$parsers.push((value) => {
1268
- if (value && value.substr(-1) === "b") {
1268
+ if (value && value.slice(-1) === "b") {
1269
1269
  value = "a";
1270
1270
  ctrl.$setViewValue(value);
1271
1271
  ctrl.$render();
@@ -1288,14 +1288,14 @@ describe("ngModel", () => {
1288
1288
 
1289
1289
  it("should validate even if the modelValue did not change", () => {
1290
1290
  ctrl.$parsers.push((value) => {
1291
- if (value && value.substr(-1) === "b") {
1291
+ if (value && value.slice(-1) === "b") {
1292
1292
  value = "a";
1293
1293
  }
1294
1294
 
1295
1295
  return value;
1296
1296
  });
1297
1297
 
1298
- ctrl.$validators.mock = function (modelValue) {
1298
+ ctrl.$validators.mock = function () {
1299
1299
  return true;
1300
1300
  };
1301
1301
 
package/src/loader.js CHANGED
@@ -146,13 +146,14 @@ export class Angular {
146
146
  * @param {import("./core/di/internal-injector").InjectorService} $injector
147
147
  */
148
148
  function (scope, el, compile, $injector) {
149
+ // ng-route deps
150
+ services.$injector = $injector;
151
+ services.$q = $injector.get("$q");
149
152
  scope.$apply(() => {
150
153
  el.data("$injector", $injector);
151
154
  compile(el)(scope);
152
155
  });
153
- // ng-route deps
154
- services.$injector = $injector;
155
- services.$q = $injector.get("$q");
156
+
156
157
  // https://github.com/angular-ui/ui-router/issues/3678
157
158
  if (!Object.prototype.hasOwnProperty.call($injector, "strictDi")) {
158
159
  try {
@@ -51,7 +51,7 @@ export class ParamType {
51
51
  }
52
52
  $subPattern() {
53
53
  const sub = this.pattern.toString();
54
- return sub.substr(1, sub.length - 2);
54
+ return sub.substring(1, sub.length - 2);
55
55
  }
56
56
  toString() {
57
57
  return `{ParamType:${this.name}}`;
@@ -177,7 +177,7 @@ export class Ng1ViewConfig {
177
177
  ngViewName = relativeViewNameSugar[2]; // set view-name to "foo.bar"
178
178
  }
179
179
  if (ngViewName.charAt(0) === "!") {
180
- ngViewName = ngViewName.substr(1);
180
+ ngViewName = ngViewName.substring(1);
181
181
  ngViewContextAnchor = ""; // target absolutely from root
182
182
  }
183
183
  // handle parent relative targeting "^.^.^"
@@ -20,7 +20,7 @@ import { pattern, val } from "./hof";
20
20
  */
21
21
  export function maxLength(max, str) {
22
22
  if (str.length <= max) return str;
23
- return str.substr(0, max - 3) + "...";
23
+ return str.substring(0, max - 3) + "...";
24
24
  }
25
25
  /**
26
26
  * Returns a string, with spaces added to the end, up to a desired str length
@@ -46,7 +46,7 @@ export function functionToString(fn) {
46
46
  const toStr = namedFunctionMatch ? namedFunctionMatch[1] : fnStr;
47
47
  const fnName = fn["name"] || "";
48
48
  if (fnName && toStr.match(/function \(/)) {
49
- return "function " + fnName + toStr.substr(9);
49
+ return "function " + fnName + toStr.substring(9);
50
50
  }
51
51
  return toStr;
52
52
  }
@@ -97,7 +97,7 @@ export const beforeAfterSubstr = (char) => (str) => {
97
97
  if (!str) return ["", ""];
98
98
  const idx = str.indexOf(char);
99
99
  if (idx === -1) return [str, ""];
100
- return [str.substr(0, idx), str.substr(idx + 1)];
100
+ return [str.substring(0, idx), str.substring(idx + 1)];
101
101
  };
102
102
  export const hostRegex = new RegExp("^(?:[a-z]+:)?//[^/]+/");
103
103
  export const stripLastPathElement = (str) => str.replace(/\/[^/]*$/, "");