@stemy/ngx-utils 12.2.15 → 12.2.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.
@@ -13,8 +13,12 @@ import { ɵangular_packages_platform_browser_platform_browser_g, DomSanitizer, E
13
13
  import { addListener, removeListener } from 'resize-detector';
14
14
  import { FormsModule } from '@angular/forms';
15
15
 
16
- const defaultPredicate = () => true;
17
- const ɵ0 = defaultPredicate;
16
+ function defaultPredicate(value, key, target, source) {
17
+ return true;
18
+ }
19
+ function shouldCopyDefault(key, value) {
20
+ return true;
21
+ }
18
22
  const hasBlob = typeof Blob !== "undefined" && !!Blob;
19
23
  const hasFile = typeof File !== "undefined" && !!File;
20
24
  class ObjectUtils {
@@ -174,17 +178,19 @@ class ObjectUtils {
174
178
  return isNaN(key) || isArray ? target : Object.values(target);
175
179
  }
176
180
  static filter(obj, predicate) {
177
- return ObjectUtils.copyRecursive(null, obj, predicate, new Map());
181
+ return ObjectUtils.copyRecursive(null, obj, predicate || defaultPredicate, new Map());
178
182
  }
179
183
  static copy(obj) {
180
- return ObjectUtils.copyRecursive(null, obj, null, new Map());
184
+ return ObjectUtils.copyRecursive(null, obj, defaultPredicate, new Map());
181
185
  }
182
186
  static assign(target, source, predicate) {
183
- return ObjectUtils.copyRecursive(target, source, predicate, new Map());
187
+ return ObjectUtils.copyRecursive(target, source, predicate || defaultPredicate, new Map());
184
188
  }
185
189
  static getType(obj) {
186
190
  const regex = new RegExp("\\s([a-zA-Z]+)");
187
- return Object.prototype.toString.call(obj).match(regex)[1].toLowerCase();
191
+ const target = !obj ? null : obj.constructor;
192
+ const type = !target ? null : Reflect.getMetadata("objectType", target);
193
+ return (type || Object.prototype.toString.call(obj).match(regex)[1]).toLowerCase();
188
194
  }
189
195
  static isPrimitive(value) {
190
196
  const type = typeof value;
@@ -231,6 +237,9 @@ class ObjectUtils {
231
237
  static isSet(value) {
232
238
  return value instanceof Set;
233
239
  }
240
+ static isConstructor(value) {
241
+ return (value && typeof value === "function" && value.prototype && value.prototype.constructor) === value && value.name !== "Object";
242
+ }
234
243
  static checkInterface(obj, interFaceObject) {
235
244
  return ObjectUtils.isInterface(obj, interFaceObject);
236
245
  }
@@ -256,33 +265,71 @@ class ObjectUtils {
256
265
  return str.length >= width ? str : new Array(width - str.length + 1).join(chr) + str;
257
266
  }
258
267
  static copyRecursive(target, source, predicate, copies) {
259
- predicate = predicate || defaultPredicate;
260
268
  if (ObjectUtils.isPrimitive(source) || ObjectUtils.isDate(source) || ObjectUtils.isBlob(source) || ObjectUtils.isFunction(source))
261
269
  return source;
262
- if (!copies.has(source)) {
263
- if (ObjectUtils.isArray(source)) {
264
- target = ObjectUtils.isArray(target) ? Array.from(target) : [];
265
- copies.set(source, target);
266
- source.forEach((item, index) => {
267
- if (!predicate(item, index, target, source))
268
- return;
269
- if (target.length > index)
270
- target[index] = ObjectUtils.copyRecursive(target[index], item, predicate, copies);
271
- else
272
- target.push(ObjectUtils.copyRecursive(null, item, predicate, copies));
273
- });
270
+ if (copies.has(source))
271
+ return copies.get(source);
272
+ if (ObjectUtils.isArray(source)) {
273
+ target = ObjectUtils.isArray(target) ? Array.from(target) : [];
274
+ copies.set(source, target);
275
+ for (let index = 0; index < source.length; index++) {
276
+ const item = source[index];
277
+ if (!predicate(item, index, target, source))
278
+ continue;
279
+ if (target.length > index)
280
+ target[index] = ObjectUtils.copyRecursive(target[index], item, predicate, copies);
281
+ else
282
+ target.push(ObjectUtils.copyRecursive(null, item, predicate, copies));
274
283
  }
275
- else {
276
- target = Object.assign({}, target);
277
- copies.set(source, target);
278
- Object.keys(source).forEach((key) => {
279
- if (!predicate(source[key], key, target, source))
280
- return;
281
- target[key] = ObjectUtils.copyRecursive(target[key], source[key], predicate, copies);
282
- });
284
+ return target;
285
+ }
286
+ // If object defines __shouldCopy as false, then don't copy it
287
+ if (source.__shouldCopy === false)
288
+ return source;
289
+ // Copy object
290
+ const shouldCopy = ObjectUtils.isFunction(source.__shouldCopy) ? source.__shouldCopy : shouldCopyDefault;
291
+ if (ObjectUtils.isConstructor(source.constructor)) {
292
+ if (!target) {
293
+ try {
294
+ target = new source.constructor();
295
+ }
296
+ catch (e) {
297
+ const proto = source.constructor.prototype || source.prototype;
298
+ target = Object.create(proto);
299
+ }
300
+ }
301
+ }
302
+ else {
303
+ target = Object.assign({}, target || {});
304
+ }
305
+ // Set to copies to prevent circular references
306
+ copies.set(source, target);
307
+ // Copy map entries
308
+ if (target instanceof Map) {
309
+ if (source instanceof Map) {
310
+ for (const [key, value] of source.entries()) {
311
+ if (!predicate(value, key, target, source))
312
+ continue;
313
+ target.set(key, !shouldCopy(key, value) ? value : ObjectUtils.copyRecursive(target.get(key), value, predicate, copies));
314
+ }
283
315
  }
316
+ return target;
317
+ }
318
+ // Copy object members
319
+ const keys = Object.keys(source);
320
+ for (const key of keys) {
321
+ if (!predicate(source[key], key, target, source))
322
+ continue;
323
+ target[key] = !shouldCopy(key, source[key]) ? source[key] : ObjectUtils.copyRecursive(target[key], source[key], predicate, copies);
284
324
  }
285
- return copies.get(source);
325
+ // Copy object properties
326
+ const descriptors = Object.getOwnPropertyDescriptors(source);
327
+ for (const key of Object.keys(descriptors)) {
328
+ if (keys.indexOf(key) >= 0)
329
+ continue;
330
+ Object.defineProperty(target, key, descriptors[key]);
331
+ }
332
+ return target;
286
333
  }
287
334
  }
288
335
 
@@ -345,6 +392,11 @@ function FactoryDependencies(...dependencies) {
345
392
  ReflectUtils.defineMetadata("factoryDependencies", dependencies, target, method);
346
393
  };
347
394
  }
395
+ function ObjectType(type) {
396
+ return function (target) {
397
+ ReflectUtils.defineMetadata("objectType", type, target);
398
+ };
399
+ }
348
400
  class PaginationItemContext {
349
401
  constructor(item, parallelItem, count, index, dataIndex) {
350
402
  this.item = item;
@@ -4998,5 +5050,5 @@ NgxUtilsModule.decorators = [
4998
5050
  * Generated bundle index. Do not edit.
4999
5051
  */
5000
5052
 
5001
- export { API_SERVICE, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseHttpClient, BaseHttpService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChunkPipe, Circle, ConfigService, ConsoleToasterService, DateUtils, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FileSystemEntry, FileUtils, FilterPipe, FindPipe, FormatNumberPipe, FormatterService, GLOBAL_TEMPLATES, GenericValue, GetOffsetPipe, GetTypePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, Initializer, IsTypePipe, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UnorederedListTemplate, ValuedPromise, ValuesPipe, Vector, pipes as ɵa, directives as ɵb, components as ɵc, providers as ɵd, loadConfig as ɵe };
5053
+ export { API_SERVICE, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseHttpClient, BaseHttpService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChunkPipe, Circle, ConfigService, ConsoleToasterService, DateUtils, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FileSystemEntry, FileUtils, FilterPipe, FindPipe, FormatNumberPipe, FormatterService, GLOBAL_TEMPLATES, GenericValue, GetOffsetPipe, GetTypePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, Initializer, IsTypePipe, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, ObjectType, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyClassDirective, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UnorederedListTemplate, ValuedPromise, ValuesPipe, Vector, defaultPredicate as ɵa, pipes as ɵb, directives as ɵc, components as ɵd, providers as ɵe, loadConfig as ɵf };
5002
5054
  //# sourceMappingURL=stemy-ngx-utils.js.map