@angular-wave/angular.ts 0.0.1

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.
Files changed (231) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +29 -0
  3. package/.github/workflows/playwright.yml +27 -0
  4. package/CHANGELOG.md +17974 -0
  5. package/CODE_OF_CONDUCT.md +3 -0
  6. package/CONTRIBUTING.md +246 -0
  7. package/DEVELOPERS.md +488 -0
  8. package/LICENSE +22 -0
  9. package/Makefile +31 -0
  10. package/README.md +115 -0
  11. package/RELEASE.md +98 -0
  12. package/SECURITY.md +16 -0
  13. package/TRIAGING.md +135 -0
  14. package/css/angular.css +22 -0
  15. package/dist/angular-ts.cjs.js +36843 -0
  16. package/dist/angular-ts.esm.js +36841 -0
  17. package/dist/angular-ts.umd.js +36848 -0
  18. package/dist/build/angular-animate.js +4272 -0
  19. package/dist/build/angular-aria.js +426 -0
  20. package/dist/build/angular-message-format.js +1072 -0
  21. package/dist/build/angular-messages.js +829 -0
  22. package/dist/build/angular-mocks.js +3757 -0
  23. package/dist/build/angular-parse-ext.js +1275 -0
  24. package/dist/build/angular-resource.js +911 -0
  25. package/dist/build/angular-route.js +1266 -0
  26. package/dist/build/angular-sanitize.js +891 -0
  27. package/dist/build/angular-touch.js +368 -0
  28. package/dist/build/angular.js +36600 -0
  29. package/e2e/unit.spec.ts +15 -0
  30. package/images/android-chrome-192x192.png +0 -0
  31. package/images/android-chrome-512x512.png +0 -0
  32. package/images/apple-touch-icon.png +0 -0
  33. package/images/favicon-16x16.png +0 -0
  34. package/images/favicon-32x32.png +0 -0
  35. package/images/favicon.ico +0 -0
  36. package/images/site.webmanifest +1 -0
  37. package/index.html +104 -0
  38. package/package.json +47 -0
  39. package/playwright.config.ts +78 -0
  40. package/public/circle.html +1 -0
  41. package/public/my_child_directive.html +1 -0
  42. package/public/my_directive.html +1 -0
  43. package/public/my_other_directive.html +1 -0
  44. package/public/test.html +1 -0
  45. package/rollup.config.js +31 -0
  46. package/src/animations/animateCache.js +55 -0
  47. package/src/animations/animateChildrenDirective.js +105 -0
  48. package/src/animations/animateCss.js +1139 -0
  49. package/src/animations/animateCssDriver.js +291 -0
  50. package/src/animations/animateJs.js +367 -0
  51. package/src/animations/animateJsDriver.js +67 -0
  52. package/src/animations/animateQueue.js +851 -0
  53. package/src/animations/animation.js +506 -0
  54. package/src/animations/module.js +779 -0
  55. package/src/animations/ngAnimateSwap.js +119 -0
  56. package/src/animations/rafScheduler.js +50 -0
  57. package/src/animations/shared.js +378 -0
  58. package/src/constants.js +20 -0
  59. package/src/core/animate.js +845 -0
  60. package/src/core/animateCss.js +73 -0
  61. package/src/core/animateRunner.js +195 -0
  62. package/src/core/attributes.js +199 -0
  63. package/src/core/cache.js +45 -0
  64. package/src/core/compile.js +4727 -0
  65. package/src/core/controller.js +225 -0
  66. package/src/core/exceptionHandler.js +63 -0
  67. package/src/core/filter.js +146 -0
  68. package/src/core/interpolate.js +442 -0
  69. package/src/core/interval.js +188 -0
  70. package/src/core/intervalFactory.js +57 -0
  71. package/src/core/location.js +1086 -0
  72. package/src/core/parser/parse.js +2562 -0
  73. package/src/core/parser/parse.md +13 -0
  74. package/src/core/q.js +746 -0
  75. package/src/core/rootScope.js +1596 -0
  76. package/src/core/sanitizeUri.js +85 -0
  77. package/src/core/sce.js +1161 -0
  78. package/src/core/taskTrackerFactory.js +125 -0
  79. package/src/core/timeout.js +121 -0
  80. package/src/core/urlUtils.js +187 -0
  81. package/src/core/utils.js +1349 -0
  82. package/src/directive/a.js +37 -0
  83. package/src/directive/attrs.js +283 -0
  84. package/src/directive/bind.js +51 -0
  85. package/src/directive/bind.md +142 -0
  86. package/src/directive/change.js +12 -0
  87. package/src/directive/change.md +25 -0
  88. package/src/directive/cloak.js +12 -0
  89. package/src/directive/cloak.md +24 -0
  90. package/src/directive/events.js +75 -0
  91. package/src/directive/events.md +166 -0
  92. package/src/directive/form.js +725 -0
  93. package/src/directive/init.js +15 -0
  94. package/src/directive/init.md +41 -0
  95. package/src/directive/input.js +1783 -0
  96. package/src/directive/list.js +46 -0
  97. package/src/directive/list.md +22 -0
  98. package/src/directive/ngClass.js +249 -0
  99. package/src/directive/ngController.js +64 -0
  100. package/src/directive/ngCsp.js +82 -0
  101. package/src/directive/ngIf.js +134 -0
  102. package/src/directive/ngInclude.js +217 -0
  103. package/src/directive/ngModel.js +1356 -0
  104. package/src/directive/ngModelOptions.js +509 -0
  105. package/src/directive/ngOptions.js +670 -0
  106. package/src/directive/ngRef.js +90 -0
  107. package/src/directive/ngRepeat.js +650 -0
  108. package/src/directive/ngShowHide.js +255 -0
  109. package/src/directive/ngSwitch.js +178 -0
  110. package/src/directive/ngTransclude.js +98 -0
  111. package/src/directive/non-bindable.js +11 -0
  112. package/src/directive/non-bindable.md +17 -0
  113. package/src/directive/script.js +30 -0
  114. package/src/directive/select.js +624 -0
  115. package/src/directive/style.js +25 -0
  116. package/src/directive/style.md +23 -0
  117. package/src/directive/validators.js +329 -0
  118. package/src/exts/aria.js +544 -0
  119. package/src/exts/messages.js +852 -0
  120. package/src/filters/filter.js +207 -0
  121. package/src/filters/filter.md +69 -0
  122. package/src/filters/filters.js +239 -0
  123. package/src/filters/json.md +16 -0
  124. package/src/filters/limit-to.js +43 -0
  125. package/src/filters/limit-to.md +19 -0
  126. package/src/filters/order-by.js +183 -0
  127. package/src/filters/order-by.md +83 -0
  128. package/src/index.js +13 -0
  129. package/src/injector.js +1034 -0
  130. package/src/jqLite.js +1117 -0
  131. package/src/loader.js +1320 -0
  132. package/src/public.js +215 -0
  133. package/src/routeToRegExp.js +41 -0
  134. package/src/services/anchorScroll.js +135 -0
  135. package/src/services/browser.js +321 -0
  136. package/src/services/cacheFactory.js +398 -0
  137. package/src/services/cookieReader.js +72 -0
  138. package/src/services/document.js +64 -0
  139. package/src/services/http.js +1537 -0
  140. package/src/services/httpBackend.js +206 -0
  141. package/src/services/log.js +160 -0
  142. package/src/services/templateRequest.js +139 -0
  143. package/test/angular.spec.js +2153 -0
  144. package/test/aria/aria.spec.js +1245 -0
  145. package/test/binding.spec.js +504 -0
  146. package/test/build-test.html +14 -0
  147. package/test/injector.spec.js +2327 -0
  148. package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
  149. package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
  150. package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
  151. package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
  152. package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
  153. package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
  154. package/test/jasmine/jasmine-browser.json +17 -0
  155. package/test/jasmine/jasmine.json +9 -0
  156. package/test/jqlite.spec.js +2133 -0
  157. package/test/loader.spec.js +219 -0
  158. package/test/messages/messages.spec.js +1146 -0
  159. package/test/min-err.spec.js +174 -0
  160. package/test/mock-test.html +13 -0
  161. package/test/module-test.html +15 -0
  162. package/test/ng/anomate.spec.js +606 -0
  163. package/test/ng/cache-factor.spec.js +334 -0
  164. package/test/ng/compile.spec.js +17956 -0
  165. package/test/ng/controller-provider.spec.js +227 -0
  166. package/test/ng/cookie-reader.spec.js +98 -0
  167. package/test/ng/directive/a.spec.js +192 -0
  168. package/test/ng/directive/bind.spec.js +334 -0
  169. package/test/ng/directive/boolean.spec.js +136 -0
  170. package/test/ng/directive/change.spec.js +71 -0
  171. package/test/ng/directive/class.spec.js +858 -0
  172. package/test/ng/directive/click.spec.js +38 -0
  173. package/test/ng/directive/cloak.spec.js +44 -0
  174. package/test/ng/directive/constoller.spec.js +194 -0
  175. package/test/ng/directive/element-style.spec.js +92 -0
  176. package/test/ng/directive/event.spec.js +282 -0
  177. package/test/ng/directive/form.spec.js +1518 -0
  178. package/test/ng/directive/href.spec.js +143 -0
  179. package/test/ng/directive/if.spec.js +402 -0
  180. package/test/ng/directive/include.spec.js +828 -0
  181. package/test/ng/directive/init.spec.js +68 -0
  182. package/test/ng/directive/input.spec.js +3810 -0
  183. package/test/ng/directive/list.spec.js +170 -0
  184. package/test/ng/directive/model-options.spec.js +1008 -0
  185. package/test/ng/directive/model.spec.js +1905 -0
  186. package/test/ng/directive/non-bindable.spec.js +55 -0
  187. package/test/ng/directive/options.spec.js +3583 -0
  188. package/test/ng/directive/ref.spec.js +575 -0
  189. package/test/ng/directive/repeat.spec.js +1675 -0
  190. package/test/ng/directive/script.spec.js +52 -0
  191. package/test/ng/directive/scrset.spec.js +67 -0
  192. package/test/ng/directive/select.spec.js +2541 -0
  193. package/test/ng/directive/show-hide.spec.js +253 -0
  194. package/test/ng/directive/src.spec.js +157 -0
  195. package/test/ng/directive/style.spec.js +178 -0
  196. package/test/ng/directive/switch.spec.js +647 -0
  197. package/test/ng/directive/validators.spec.js +717 -0
  198. package/test/ng/document.spec.js +52 -0
  199. package/test/ng/filter/filter.spec.js +714 -0
  200. package/test/ng/filter/filters.spec.js +35 -0
  201. package/test/ng/filter/limit-to.spec.js +251 -0
  202. package/test/ng/filter/order-by.spec.js +891 -0
  203. package/test/ng/filter.spec.js +149 -0
  204. package/test/ng/http-backend.spec.js +398 -0
  205. package/test/ng/http.spec.js +4071 -0
  206. package/test/ng/interpolate.spec.js +642 -0
  207. package/test/ng/interval.spec.js +343 -0
  208. package/test/ng/location.spec.js +3488 -0
  209. package/test/ng/on.spec.js +229 -0
  210. package/test/ng/parse.spec.js +4655 -0
  211. package/test/ng/prop.spec.js +805 -0
  212. package/test/ng/q.spec.js +2904 -0
  213. package/test/ng/root-element.spec.js +16 -0
  214. package/test/ng/sanitize-uri.spec.js +249 -0
  215. package/test/ng/sce.spec.js +660 -0
  216. package/test/ng/scope.spec.js +3442 -0
  217. package/test/ng/template-request.spec.js +236 -0
  218. package/test/ng/timeout.spec.js +351 -0
  219. package/test/ng/url-utils.spec.js +156 -0
  220. package/test/ng/utils.spec.js +144 -0
  221. package/test/original-test.html +21 -0
  222. package/test/public.spec.js +34 -0
  223. package/test/sanitize/bing-html.spec.js +36 -0
  224. package/test/server/express.js +158 -0
  225. package/test/test-utils.js +11 -0
  226. package/tsconfig.json +17 -0
  227. package/types/angular.d.ts +138 -0
  228. package/types/global.d.ts +9 -0
  229. package/types/index.d.ts +2357 -0
  230. package/types/jqlite.d.ts +558 -0
  231. package/vite.config.js +14 -0
@@ -0,0 +1,207 @@
1
+ import {
2
+ minErr,
3
+ isArrayLike,
4
+ isFunction,
5
+ isUndefined,
6
+ isObject,
7
+ lowercase,
8
+ isArray,
9
+ hasCustomToString,
10
+ equals,
11
+ } from "../core/utils";
12
+
13
+ /**
14
+ * @returns {angular.IFilterFilter}
15
+ */
16
+ export function filterFilter() {
17
+ return function (array, expression, comparator, anyPropertyKey) {
18
+ if (!isArrayLike(array)) {
19
+ if (array == null) {
20
+ return array;
21
+ }
22
+ throw minErr("filter")(
23
+ "notarray",
24
+ "Expected array but received: {0}",
25
+ array,
26
+ );
27
+ }
28
+
29
+ anyPropertyKey = anyPropertyKey || "$";
30
+ let predicateFn;
31
+ let matchAgainstAnyProp;
32
+
33
+ switch (getTypeForFilter(expression)) {
34
+ case "function":
35
+ predicateFn = expression;
36
+ break;
37
+ case "boolean":
38
+ case "null":
39
+ case "number":
40
+ case "string":
41
+ matchAgainstAnyProp = true;
42
+ // falls through
43
+ case "object":
44
+ predicateFn = createPredicateFn(
45
+ expression,
46
+ comparator,
47
+ anyPropertyKey,
48
+ matchAgainstAnyProp,
49
+ );
50
+ break;
51
+ default:
52
+ return array;
53
+ }
54
+
55
+ return Array.prototype.filter.call(array, predicateFn);
56
+ };
57
+ }
58
+
59
+ // Helper functions for `filterFilter`
60
+ function createPredicateFn(
61
+ expression,
62
+ comparator,
63
+ anyPropertyKey,
64
+ matchAgainstAnyProp,
65
+ ) {
66
+ const shouldMatchPrimitives =
67
+ isObject(expression) && anyPropertyKey in expression;
68
+ let predicateFn;
69
+
70
+ if (comparator === true) {
71
+ comparator = equals;
72
+ } else if (!isFunction(comparator)) {
73
+ comparator = function (actual, expected) {
74
+ if (isUndefined(actual)) {
75
+ // No substring matching against `undefined`
76
+ return false;
77
+ }
78
+ if (actual === null || expected === null) {
79
+ // No substring matching against `null`; only match against `null`
80
+ return actual === expected;
81
+ }
82
+ if (
83
+ isObject(expected) ||
84
+ (isObject(actual) && !hasCustomToString(actual))
85
+ ) {
86
+ // Should not compare primitives against objects, unless they have custom `toString` method
87
+ return false;
88
+ }
89
+
90
+ actual = lowercase(`${actual}`);
91
+ expected = lowercase(`${expected}`);
92
+ return actual.indexOf(expected) !== -1;
93
+ };
94
+ }
95
+
96
+ predicateFn = function (item) {
97
+ if (shouldMatchPrimitives && !isObject(item)) {
98
+ return deepCompare(
99
+ item,
100
+ expression[anyPropertyKey],
101
+ comparator,
102
+ anyPropertyKey,
103
+ false,
104
+ );
105
+ }
106
+ return deepCompare(
107
+ item,
108
+ expression,
109
+ comparator,
110
+ anyPropertyKey,
111
+ matchAgainstAnyProp,
112
+ );
113
+ };
114
+
115
+ return predicateFn;
116
+ }
117
+
118
+ function deepCompare(
119
+ actual,
120
+ expected,
121
+ comparator,
122
+ anyPropertyKey,
123
+ matchAgainstAnyProp,
124
+ dontMatchWholeObject,
125
+ ) {
126
+ const actualType = getTypeForFilter(actual);
127
+ const expectedType = getTypeForFilter(expected);
128
+
129
+ if (expectedType === "string" && expected.charAt(0) === "!") {
130
+ return !deepCompare(
131
+ actual,
132
+ expected.substring(1),
133
+ comparator,
134
+ anyPropertyKey,
135
+ matchAgainstAnyProp,
136
+ );
137
+ }
138
+ if (isArray(actual)) {
139
+ // In case `actual` is an array, consider it a match
140
+ // if ANY of it's items matches `expected`
141
+ return actual.some((item) =>
142
+ deepCompare(
143
+ item,
144
+ expected,
145
+ comparator,
146
+ anyPropertyKey,
147
+ matchAgainstAnyProp,
148
+ ),
149
+ );
150
+ }
151
+
152
+ switch (actualType) {
153
+ case "object":
154
+ var key;
155
+ if (matchAgainstAnyProp) {
156
+ for (key in actual) {
157
+ // Under certain, rare, circumstances, key may not be a string and `charAt` will be undefined
158
+ // See: https://github.com/angular/angular.js/issues/15644
159
+ if (
160
+ key.charAt &&
161
+ key.charAt(0) !== "$" &&
162
+ deepCompare(actual[key], expected, comparator, anyPropertyKey, true)
163
+ ) {
164
+ return true;
165
+ }
166
+ }
167
+ return dontMatchWholeObject
168
+ ? false
169
+ : deepCompare(actual, expected, comparator, anyPropertyKey, false);
170
+ }
171
+ if (expectedType === "object") {
172
+ for (key in expected) {
173
+ const expectedVal = expected[key];
174
+ if (isFunction(expectedVal) || isUndefined(expectedVal)) {
175
+ continue;
176
+ }
177
+
178
+ const matchAnyProperty = key === anyPropertyKey;
179
+ const actualVal = matchAnyProperty ? actual : actual[key];
180
+ if (
181
+ !deepCompare(
182
+ actualVal,
183
+ expectedVal,
184
+ comparator,
185
+ anyPropertyKey,
186
+ matchAnyProperty,
187
+ matchAnyProperty,
188
+ )
189
+ ) {
190
+ return false;
191
+ }
192
+ }
193
+ return true;
194
+ }
195
+ return comparator(actual, expected);
196
+
197
+ case "function":
198
+ return false;
199
+ default:
200
+ return comparator(actual, expected);
201
+ }
202
+ }
203
+
204
+ // Used for easily differentiating between `null` and actual `object`
205
+ function getTypeForFilter(val) {
206
+ return val === null ? "null" : typeof val;
207
+ }
@@ -0,0 +1,69 @@
1
+ /\*\*
2
+
3
+ - @ngdoc filter
4
+ - @name filter
5
+ - @kind function
6
+ -
7
+ - @description
8
+ - Selects a subset of items from `array` and returns it as a new array.
9
+ -
10
+ - @param {Array} array The source array.
11
+ - <div class="alert alert-info">
12
+ - **Note**: If the array contains objects that reference themselves, filtering is not possible.
13
+ - </div>
14
+ - @param {string|Object|function()} expression The predicate to be used for selecting items from
15
+ - `array`.
16
+ -
17
+ - Can be one of:
18
+ -
19
+ - - `string`: The string is used for matching against the contents of the `array`. All strings or
20
+ - objects with string properties in `array` that match this string will be returned. This also
21
+ - applies to nested object properties.
22
+ - The predicate can be negated by prefixing the string with `!`.
23
+ -
24
+ - - `Object`: A pattern object can be used to filter specific properties on objects contained
25
+ - by `array`. For example `{name:"M", phone:"1"}` predicate will return an array of items
26
+ - which have property `name` containing "M" and property `phone` containing "1". A special
27
+ - property name (`$` by default) can be used (e.g. as in `{$: "text"}`) to accept a match
28
+ - against any property of the object or its nested object properties. That's equivalent to the
29
+ - simple substring match with a `string` as described above. The special property name can be
30
+ - overwritten, using the `anyPropertyKey` parameter.
31
+ - The predicate can be negated by prefixing the string with `!`.
32
+ - For example `{name: "!M"}` predicate will return an array of items which have property `name`
33
+ - not containing "M".
34
+ -
35
+ - Note that a named property will match properties on the same level only, while the special
36
+ - `$` property will match properties on the same level or deeper. E.g. an array item like
37
+ - `{name: {first: 'John', last: 'Doe'}}` will **not** be matched by `{name: 'John'}`, but
38
+ - **will** be matched by `{$: 'John'}`.
39
+ -
40
+ - - `function(value, index, array)`: A predicate function can be used to write arbitrary filters.
41
+ - The function is called for each element of the array, with the element, its index, and
42
+ - the entire array itself as arguments.
43
+ -
44
+ - The final result is an array of those elements that the predicate returned true for.
45
+ -
46
+ - @param {function(actual, expected)|true|false} [comparator] Comparator which is used in
47
+ - determining if values retrieved using `expression` (when it is not a function) should be
48
+ - considered a match based on the expected value (from the filter expression) and actual
49
+ - value (from the object in the array).
50
+ -
51
+ - Can be one of:
52
+ -
53
+ - - `function(actual, expected)`:
54
+ - The function will be given the object value and the predicate value to compare and
55
+ - should return true if both values should be considered equal.
56
+ -
57
+ - - `true`: A shorthand for `function(actual, expected) { return angular.equals(actual, expected)}`.
58
+ - This is essentially strict comparison of expected and actual.
59
+ -
60
+ - - `false`: A short hand for a function which will look for a substring match in a case
61
+ - insensitive way. Primitive values are converted to strings. Objects are not compared against
62
+ - primitives, unless they have a custom `toString` method (e.g. `Date` objects).
63
+ -
64
+ -
65
+ - Defaults to `false`.
66
+ -
67
+ - @param {string} [anyPropertyKey] The special property name that matches against any property.
68
+ - By default `$`.
69
+ - \*/
@@ -0,0 +1,239 @@
1
+ import { isNumber, isString, isUndefined, toJson } from "../core/utils";
2
+
3
+ const MAX_DIGITS = 22;
4
+ const DECIMAL_SEP = ".";
5
+ const ZERO_CHAR = "0";
6
+
7
+ /**
8
+ * Parse a number (as a string) into three components that can be used
9
+ * for formatting the number.
10
+ *
11
+ * (Significant bits of this parse algorithm came from https://github.com/MikeMcl/big.js/)
12
+ *
13
+ * @param {string} numStr The number to parse
14
+ * @return {object} An object describing this number, containing the following keys:
15
+ * - d : an array of digits containing leading zeros as necessary
16
+ * - i : the number of the digits in `d` that are to the left of the decimal point
17
+ * - e : the exponent for numbers that would need more than `MAX_DIGITS` digits in `d`
18
+ *
19
+ */
20
+ function parse(numStr) {
21
+ let exponent = 0;
22
+ let digits;
23
+ let numberOfIntegerDigits;
24
+ let i;
25
+ let j;
26
+ let zeros;
27
+
28
+ // Decimal point?
29
+ if ((numberOfIntegerDigits = numStr.indexOf(DECIMAL_SEP)) > -1) {
30
+ numStr = numStr.replace(DECIMAL_SEP, "");
31
+ }
32
+
33
+ // Exponential form?
34
+ if ((i = numStr.search(/e/i)) > 0) {
35
+ // Work out the exponent.
36
+ if (numberOfIntegerDigits < 0) numberOfIntegerDigits = i;
37
+ numberOfIntegerDigits += +numStr.slice(i + 1);
38
+ numStr = numStr.substring(0, i);
39
+ } else if (numberOfIntegerDigits < 0) {
40
+ // There was no decimal point or exponent so it is an integer.
41
+ numberOfIntegerDigits = numStr.length;
42
+ }
43
+
44
+ // Count the number of leading zeros.
45
+ for (i = 0; numStr.charAt(i) === ZERO_CHAR; i++) {
46
+ /* empty */
47
+ }
48
+
49
+ if (i === (zeros = numStr.length)) {
50
+ // The digits are all zero.
51
+ digits = [0];
52
+ numberOfIntegerDigits = 1;
53
+ } else {
54
+ // Count the number of trailing zeros
55
+ zeros--;
56
+ while (numStr.charAt(zeros) === ZERO_CHAR) zeros--;
57
+
58
+ // Trailing zeros are insignificant so ignore them
59
+ numberOfIntegerDigits -= i;
60
+ digits = [];
61
+ // Convert string to array of digits without leading/trailing zeros.
62
+ for (j = 0; i <= zeros; i++, j++) {
63
+ digits[j] = +numStr.charAt(i);
64
+ }
65
+ }
66
+
67
+ // If the number overflows the maximum allowed digits then use an exponent.
68
+ if (numberOfIntegerDigits > MAX_DIGITS) {
69
+ digits = digits.splice(0, MAX_DIGITS - 1);
70
+ exponent = numberOfIntegerDigits - 1;
71
+ numberOfIntegerDigits = 1;
72
+ }
73
+
74
+ return { d: digits, e: exponent, i: numberOfIntegerDigits };
75
+ }
76
+
77
+ /**
78
+ * Round the parsed number to the specified number of decimal places
79
+ * This function changed the parsedNumber in-place
80
+ */
81
+ function roundNumber(parsedNumber, fractionSize, minFrac, maxFrac) {
82
+ const digits = parsedNumber.d;
83
+ let fractionLen = digits.length - parsedNumber.i;
84
+
85
+ // determine fractionSize if it is not specified; `+fractionSize` converts it to a number
86
+ fractionSize = isUndefined(fractionSize)
87
+ ? Math.min(Math.max(minFrac, fractionLen), maxFrac)
88
+ : +fractionSize;
89
+
90
+ // The index of the digit to where rounding is to occur
91
+ let roundAt = fractionSize + parsedNumber.i;
92
+ const digit = digits[roundAt];
93
+
94
+ if (roundAt > 0) {
95
+ // Drop fractional digits beyond `roundAt`
96
+ digits.splice(Math.max(parsedNumber.i, roundAt));
97
+
98
+ // Set non-fractional digits beyond `roundAt` to 0
99
+ for (let j = roundAt; j < digits.length; j++) {
100
+ digits[j] = 0;
101
+ }
102
+ } else {
103
+ // We rounded to zero so reset the parsedNumber
104
+ fractionLen = Math.max(0, fractionLen);
105
+ parsedNumber.i = 1;
106
+ digits.length = Math.max(1, (roundAt = fractionSize + 1));
107
+ digits[0] = 0;
108
+ for (let i = 1; i < roundAt; i++) digits[i] = 0;
109
+ }
110
+
111
+ if (digit >= 5) {
112
+ if (roundAt - 1 < 0) {
113
+ for (let k = 0; k > roundAt; k--) {
114
+ digits.unshift(0);
115
+ parsedNumber.i++;
116
+ }
117
+ digits.unshift(1);
118
+ parsedNumber.i++;
119
+ } else {
120
+ digits[roundAt - 1]++;
121
+ }
122
+ }
123
+
124
+ // Pad out with zeros to get the required fraction length
125
+ for (; fractionLen < Math.max(0, fractionSize); fractionLen++) digits.push(0);
126
+
127
+ // Do any carrying, e.g. a digit was rounded up to 10
128
+ const carry = digits.reduceRight((carry, d, i, digits) => {
129
+ d += carry;
130
+ digits[i] = d % 10;
131
+ return Math.floor(d / 10);
132
+ }, 0);
133
+ if (carry) {
134
+ digits.unshift(carry);
135
+ parsedNumber.i++;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Format a number into a string
141
+ * @param {number} number The number to format
142
+ * @param {{
143
+ * minFrac, // the minimum number of digits required in the fraction part of the number
144
+ * maxFrac, // the maximum number of digits required in the fraction part of the number
145
+ * gSize, // number of digits in each group of separated digits
146
+ * lgSize, // number of digits in the last group of digits before the decimal separator
147
+ * negPre, // the string to go in front of a negative number (e.g. `-` or `(`))
148
+ * posPre, // the string to go in front of a positive number
149
+ * negSuf, // the string to go after a negative number (e.g. `)`)
150
+ * posSuf // the string to go after a positive number
151
+ * }} pattern
152
+ * @param {string} groupSep The string to separate groups of number (e.g. `,`)
153
+ * @param {string} decimalSep The string to act as the decimal separator (e.g. `.`)
154
+ * @param {[type]} fractionSize The size of the fractional part of the number
155
+ * @return {string} The number formatted as a string
156
+ */
157
+
158
+ export function formatNumber(
159
+ number,
160
+ pattern,
161
+ groupSep,
162
+ decimalSep,
163
+ fractionSize,
164
+ ) {
165
+ if (!(isString(number) || isNumber(number)) || Number.isNaN(number))
166
+ return "";
167
+
168
+ const isInfinity = !Number.isFinite(number);
169
+ let isZero = false;
170
+ const numStr = `${Math.abs(number)}`;
171
+ let formattedText = "";
172
+ let parsedNumber;
173
+
174
+ if (isInfinity) {
175
+ formattedText = "\u221e";
176
+ } else {
177
+ parsedNumber = parse(numStr);
178
+
179
+ roundNumber(parsedNumber, fractionSize, pattern.minFrac, pattern.maxFrac);
180
+
181
+ let digits = parsedNumber.d;
182
+ let integerLen = parsedNumber.i;
183
+ const exponent = parsedNumber.e;
184
+ let decimals = [];
185
+ isZero = digits.reduce((isZero, d) => isZero && !d, true);
186
+
187
+ // pad zeros for small numbers
188
+ while (integerLen < 0) {
189
+ digits.unshift(0);
190
+ integerLen++;
191
+ }
192
+
193
+ // extract decimals digits
194
+ if (integerLen > 0) {
195
+ decimals = digits.splice(integerLen, digits.length);
196
+ } else {
197
+ decimals = digits;
198
+ digits = [0];
199
+ }
200
+
201
+ // format the integer digits with grouping separators
202
+ const groups = [];
203
+ if (digits.length >= pattern.lgSize) {
204
+ groups.unshift(digits.splice(-pattern.lgSize, digits.length).join(""));
205
+ }
206
+ while (digits.length > pattern.gSize) {
207
+ groups.unshift(digits.splice(-pattern.gSize, digits.length).join(""));
208
+ }
209
+ if (digits.length) {
210
+ groups.unshift(digits.join(""));
211
+ }
212
+ formattedText = groups.join(groupSep);
213
+
214
+ // append the decimal digits
215
+ if (decimals.length) {
216
+ formattedText += decimalSep + decimals.join("");
217
+ }
218
+
219
+ if (exponent) {
220
+ formattedText += `e+${exponent}`;
221
+ }
222
+ }
223
+ if (number < 0 && !isZero) {
224
+ return pattern.negPre + formattedText + pattern.negSuf;
225
+ }
226
+ return pattern.posPre + formattedText + pattern.posSuf;
227
+ }
228
+
229
+ /**
230
+ * @returns {angular.IFilterJson}
231
+ */
232
+ export function jsonFilter() {
233
+ return function (object, spacing) {
234
+ if (isUndefined(spacing)) {
235
+ spacing = 2;
236
+ }
237
+ return toJson(object, spacing);
238
+ };
239
+ }
@@ -0,0 +1,16 @@
1
+ # JSON Filter
2
+
3
+ ## Description
4
+
5
+ Allows you to convert a JavaScript object into a JSON string.
6
+
7
+ This filter is mostly useful for debugging. When using the double curly `{{value}}` notation, the binding is automatically converted to JSON.
8
+
9
+ ## Parameters
10
+
11
+ - **object** `{*}`: Any JavaScript object (including arrays and primitive types) to filter.
12
+ - **spacing** `{number=}`: The number of spaces to use per indentation, defaults to 2.
13
+
14
+ ## Returns
15
+
16
+ - `{string}`: JSON string.
@@ -0,0 +1,43 @@
1
+ import {
2
+ isArrayLike,
3
+ isNumber,
4
+ isNumberNaN,
5
+ isString,
6
+ toInt,
7
+ } from "../core/utils";
8
+
9
+ /**
10
+ * @returns {angular.IFilterLimitTo}
11
+ */
12
+ export function limitToFilter() {
13
+ return function (input, limit, begin) {
14
+ if (Math.abs(Number(limit)) === Infinity) {
15
+ limit = Number(limit);
16
+ } else {
17
+ limit = toInt(limit);
18
+ }
19
+ if (isNumberNaN(limit)) return input;
20
+
21
+ if (isNumber(input)) input = input.toString();
22
+ if (!isArrayLike(input)) return input;
23
+
24
+ begin = !begin || isNaN(begin) ? 0 : toInt(begin);
25
+ begin = begin < 0 ? Math.max(0, input.length + begin) : begin;
26
+
27
+ if (limit >= 0) {
28
+ return sliceFn(input, begin, begin + limit);
29
+ } else {
30
+ if (begin === 0) {
31
+ return sliceFn(input, limit, input.length);
32
+ } else {
33
+ return sliceFn(input, Math.max(0, begin + limit), begin);
34
+ }
35
+ }
36
+ };
37
+ }
38
+
39
+ function sliceFn(input, begin, end) {
40
+ if (isString(input)) return input.slice(begin, end);
41
+
42
+ return [].slice.call(input, begin, end);
43
+ }
@@ -0,0 +1,19 @@
1
+ # limitTo Filter
2
+
3
+ ## Description
4
+
5
+ Creates a new array or string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array, string, or number, as specified by the value and sign (positive or negative) of `limit`. Other array-like objects are also supported (e.g., array subclasses, NodeLists, jqLite/jQuery collections, etc.). If a number is used as input, it is converted to a string.
6
+
7
+ ## Parameters
8
+
9
+ - **input** `{Array|ArrayLike|string|number}`: Array/array-like, string, or number to be limited.
10
+ - **limit** `{string|number}`: The length of the returned array or string.
11
+ - If the `limit` number is positive, `limit` number of items from the beginning of the source array/string are copied.
12
+ - If the number is negative, `limit` number of items from the end of the source array/string are copied.
13
+ - The `limit` will be trimmed if it exceeds `array.length`.
14
+ - If `limit` is undefined, the input will be returned unchanged.
15
+ - **begin** `{(string|number)=}`: Index at which to begin limitation. As a negative index, `begin` indicates an offset from the end of `input`. Defaults to `0`.
16
+
17
+ ## Returns
18
+
19
+ - `{Array|string}`: A new sub-array or substring of length `limit` or less if the input had less than `limit` elements.