{"version":3,"sources":["../src/lib/type-names.ts","../src/lib/get-node-type.ts","../src/lib/is-primitive.ts","../src/bin/BaseIterator.ts","../src/bin/DepthFirstIterator.ts","../src/bin/BreadthFirstIterator.ts","../src/index.ts"],"names":["unknown","object","array","set","map","OBJECT","ARRAY","SET","MAP","NULL","getNodeType","node","type","isPrimitive","BaseIterator","root","depth","algorithm","rootName","repeat","liaf","nextLevel","value","key","keys","i","DepthFirstIterator","Iterator","_Iterator","iterator","response","item"],"mappings":"AAAO,IAAMA,EAAU,GACVC,EAAS,SACTC,EAAQ,QACRC,EAAM,MACNC,EAAM,MCFnB,IAAMC,EAAS,SACTC,EAAQ,QACRC,EAAM,MACNC,EAAM,MACNC,EAAO,OAEE,SAARC,EAA6BC,EAAkB,CACpD,GAAIA,IAAS,KAAM,OAAOF,EAC1B,IAAMG,EAAO,OAAOD,EACpB,OAAIC,IAASP,EACPM,aAAgB,MAAcL,EACzBK,aAAgB,IAAYJ,EAC5BI,aAAgB,IAAYH,EACzBH,EACAO,CAChB,CChBA,IAAIA,EAAO,GACI,SAARC,EAA6BF,EAAa,CAE/C,GADAC,EAAO,OAAOD,EAAK,MACfC,IAAS,SAAU,MAAO,GAE5B,OAAQA,EAAM,CACZ,IAAK,SACL,IAAK,SACL,IAAK,UACL,IAAK,SACL,IAAK,SACL,IAAK,YACL,IAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CAEJ,CCbA,IAAqBE,EAArB,KAAuD,CAarD,YAAYC,EAAWC,EAAeC,EAAgCC,EAAmB,CAXzF,KAAQ,SAAoB,CAAC,EAC7B,KAAQ,QAAoB,IAAI,IAgB9B,GALA,KAAK,MAAQH,EACb,KAAK,OAASC,EACd,KAAK,YAAcA,IAAU,GACzB,OAAOE,GAAa,SAAU,KAAK,UAAYA,GAAY,OAC1D,KAAK,UAAY,OAClBD,IAAc,QAAS,KAAK,WAAa,WACpCA,IAAc,UAAW,KAAK,WAAa,OAC/C,OAAM,IAAI,MAAM,0BAA0B,EAC/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J,KAAQA,EAAOF,EAAS,KAAK,GAC3BC,EAAS,KAAKC,CAAI,EAEpB,OAAOD,CACT,CAWA,OAAO,+BAA+Bf,EAAWC,EAA6B,WAAYE,EAA4B,CACpH,IAAMW,EAAWD,EAAS,2BAA2Bb,EAAMC,EAAO,OAAOE,GAAa,UAAYA,EAAS,OAAS,EAAIA,EAAW,MAAM,EACvIY,EAAoB,CAAC,EACnBC,EACJ,KAAQA,EAAOF,EAAS,KAAK,GAC3BC,EAAS,KAAKC,CAAI,EAEpB,OAAOD,CACT,CAWA,OAAO,6BAA6Bf,EAAWC,EAA6B,WAAYE,EAA4B,CAClH,IAAMW,EAAWD,EAAS,yBAAyBb,EAAMC,EAAO,OAAOE,GAAa,UAAYA,EAAS,OAAS,EAAIA,EAAW,MAAM,EACrIY,EAAoB,CAAC,EACnBC,EACJ,KAAQA,EAAOF,EAAS,SAAS,GAC/BC,EAAS,KAAKC,CAAI,EAEpB,OAAOD,CACT,CAWA,OAAO,+BAA+Bf,EAAWC,EAA6B,WAAYE,EAA4B,CACpH,IAAMW,EAAWD,EAAS,2BAA2Bb,EAAMC,EAAO,OAAOE,GAAa,UAAYA,EAAS,OAAS,EAAIA,EAAW,MAAM,EACvIY,EAAoB,CAAC,EACnBC,EACJ,KAAQA,EAAOF,EAAS,SAAS,GAC/BC,EAAS,KAAKC,CAAI,EAEpB,OAAOD,CACT,CACF","sourcesContent":["export const unknown = '';\nexport const object = 'object';\nexport const array = 'array';\nexport const set = 'set';\nexport const map = 'map';\n","import { TNode } from '@/@types/general';\n\nconst OBJECT = 'object';\nconst ARRAY = 'array';\nconst SET = 'set';\nconst MAP = 'map';\nconst NULL = 'null';\n\nexport default function getNodeType(node: any): TNode {\n  if (node === null) return NULL;\n  const type = typeof node;\n  if (type === OBJECT) {\n    if (node instanceof Array) return ARRAY;\n    else if (node instanceof Set) return SET;\n    else if (node instanceof Map) return MAP;\n    else return OBJECT;\n  } else return type;\n}\n","import { INode } from '@/@types/general';\nlet type = '';\nexport default function isPrimitive(node: INode) {\n  type = typeof node.value;\n  if (type === 'object') return false;\n  else {\n    switch (type) {\n      case 'string':\n      case 'number':\n      case 'boolean':\n      case 'symbol':\n      case 'bigint':\n      case 'undefined':\n      case 'null':\n        return true;\n      default:\n        return false;\n    }\n  }\n}\n","import type { INode } from '@/@types/general';\nimport type { IIterator } from '@/@types/iterator';\nimport { unknown, object, array, set, map } from '@/lib/type-names';\nimport getNodeType from '@/lib/get-node-type';\nimport isPrimitive from '@/lib/is-primitive';\n\nexport default class BaseIterator implements IIterator {\n  //#region Приватные переменные\n  private _storage: INode[] = [];\n  private _filter: Set<any> = new Set();\n\n  private _rootName: string;\n  private _root: any;\n  private _current?: INode;\n  private _depth: number;\n  private _isInfinity: boolean;\n  private _algorithm: boolean;\n  //#endregion\n\n  constructor(root: any, depth: number, algorithm: 'depth' | 'breadth', rootName?: string) {\n    this._root = root;\n    this._depth = depth;\n    this._isInfinity = depth === -1;\n    if (typeof rootName === 'string') this._rootName = rootName || 'root';\n    else this._rootName = 'root';\n    if (algorithm === 'depth') this._algorithm = true;\n    else if (algorithm === 'breadth') this._algorithm = false;\n    else throw new Error('Incorrect algorithm name');\n    this._storage.push({ value: root, level: 0, key: this._rootName, type: getNodeType(root), empty: false });\n  }\n\n  public has(): boolean {\n    return this._storage.length > 0;\n  }\n\n  public get(): INode | undefined {\n    return this._current;\n  }\n\n  public next(): INode | undefined {\n    let repeat = false,\n      node: INode | undefined;\n    do {\n      node = this._getNextNode();\n      this._current = node;\n      if (node === undefined) return undefined;\n      if (isPrimitive(node)) repeat = false;\n      else repeat = this._handler(node);\n    } while (repeat);\n    return node;\n  }\n\n  public nextLiaf(): INode | undefined {\n    let liaf: INode | undefined;\n    do {\n      liaf = this.next();\n      if (liaf === undefined) return undefined;\n      if (isPrimitive(liaf)) return liaf;\n    } while (this.has());\n    return undefined;\n  }\n\n  public reset(): void {\n    this._filter.clear();\n    this._storage = [];\n    this._handler({ value: this._root, level: 0, type: unknown, key: this._rootName, empty: false });\n  }\n\n  private _handler(node: INode): boolean {\n    const nextLevel = node.level + 1;\n    if (!(this._isInfinity || this._depth > node.level)) return true;\n    const type = typeof node.value;\n    if (type === object && !this._filter.has(node.value)) {\n      this._filter.add(node.value);\n      if (node.value instanceof Array) {\n        node.type = array;\n        if (node.value.length > 0) {\n          let i = node.value.length - 1;\n          do {\n            this._storage.push({ value: node.value[i], level: nextLevel, type: getNodeType(node.value[i]), key: `${i}`, empty: false });\n          } while (i--);\n        } else {\n          node.empty = true;\n        }\n      } else if (node.value instanceof Set) {\n        node.type = set;\n        if (node.value.size > 0) {\n          node.value.forEach((value: any) => {\n            this._storage.push({ value: value, level: nextLevel, type: getNodeType(value), key: value, empty: false });\n          });\n        } else {\n          node.empty = true;\n        }\n      } else if (node.value instanceof Map) {\n        node.type = map;\n        if (node.value.size > 0) {\n          node.value.forEach((value: any, key: any) => {\n            this._storage.push({ value: value, level: nextLevel, type: getNodeType(value), key: key, empty: false });\n          });\n        } else {\n          node.empty = true;\n        }\n      } else if (node.value instanceof Function) {\n        node.type = 'function';\n        node.value = 'Function()';\n        node.empty = true;\n      } else if (node.value instanceof Date) {\n        node.type = 'date';\n        node.value = String(node.value);\n      } else {\n        node.type = object;\n        const keys = Object.keys(node.value);\n        if (keys.length > 0) {\n          for (let i = keys.length - 1; i >= 0; i--) {\n            if (Object.prototype.hasOwnProperty.call(node.value, keys[i]))\n              this._storage.push({\n                value: node.value[keys[i]],\n                key: keys[i],\n                level: nextLevel,\n                type: getNodeType(node.value[keys[i]]),\n                empty: false\n              });\n          }\n        } else {\n          node.empty = true;\n        }\n      }\n    } else {\n      node.value = 'ref *';\n      node.type = 'ref';\n      node.empty = true;\n    }\n    return false;\n  }\n\n  private _getNextNode(): INode | undefined {\n    return this._algorithm ? this._storage.pop() : this._storage.shift();\n  }\n}\n","import type { IIterator } from '@/@types/iterator';\nimport BaseIterator from './BaseIterator';\n\nexport default class DepthFirstIterator extends BaseIterator implements IIterator {\n  constructor(root: any, depth: number, rootName?: string) {\n    super(root, depth, 'depth', rootName);\n  }\n}\n","import type { IIterator } from '@/@types/iterator';\nimport BaseIterator from './BaseIterator';\n\nexport default class DepthFirstIterator extends BaseIterator implements IIterator {\n  constructor(root: any, depth: number, rootName?: string) {\n    super(root, depth, 'breadth', rootName);\n  }\n}\n","import DepthFirstIterator from '@/bin/DepthFirstIterator';\nimport BreadthFirstIterator from '@/bin/BreadthFirstIterator';\nimport { INode } from '@/@types/general';\nexport * from '@/@types/general';\nexport * from '@/@types/iterator';\n/**\n * @descroption Iterator builder. Contains static methods for generating iterators or ready-made\n * sequences obtained by traversing your object with an iterator\n * @class\n */\nexport default class Iterator {\n  /**\n   * @description Creates a depth-first traversal iterator object\n   * @param {any} root Any value\n   * @param {number | 'Infinity'} depth Maximum object bypass depth\n   * @returns {DeepFirstIterator} Depth-first iterator\n   * @static\n   */\n  static createDepthFirstIterator(root: any, depth: number | 'Infinity' = 'Infinity', rootName?: string): DepthFirstIterator {\n    if (depth === 'Infinity') return new DepthFirstIterator(root, -1, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root');\n    else if (typeof depth === 'number' && depth > 0)\n      return new DepthFirstIterator(root, depth, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root');\n    else throw new Error('Depth parameter must be a positive number');\n  }\n\n  /**\n   * @description Creates a breadth-first traversal iterator object\n   * @param {any} root Any value\n   * @param {number | 'Infinity'} depth Maximum object bypass depth\n   * @returns {DeepFirstIterator} Breadth-first iterator\n   * @static\n   */\n  static createBreadthFirstIterator(root: any, depth: number | 'Infinity' = 'Infinity', rootName?: string): BreadthFirstIterator {\n    if (depth === 'Infinity') return new BreadthFirstIterator(root, -1, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root');\n    else if (typeof depth === 'number' && depth > 0)\n      return new BreadthFirstIterator(root, depth, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root');\n    else throw new Error('Depth parameter must be a positive number');\n  }\n\n  /**\n   * @description Creates an array of INode interface objects. The array is a linear sequence of\n   * ALL nodes obtained during a depth-first traversal of the object tree\n   * @param {any} root Any value\n   * @param {number | 'Infinity'} depth Maximum object bypass depth\n   * @returns {INode[]} An array of ALL object nodes arranged in order corresponding to the result\n   * of a depth-first traversal of this object\n   * @static\n   */\n  static createDepthFirstSequenceNode(root: any, depth: number | 'Infinity' = 'Infinity', rootName?: string): INode[] {\n    const iterator = Iterator.createDepthFirstIterator(root, depth, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root'),\n      response: INode[] = [];\n    let item: INode | undefined;\n    while ((item = iterator.next())) {\n      response.push(item);\n    }\n    return response;\n  }\n\n  /**\n   * @description Creates an array of INode interface objects. The array is a linear sequence of\n   * ALL nodes obtained during a breadth-first traversal of the object tree\n   * @param {any} root Any value\n   * @param {number | 'Infinity'} depth Maximum object bypass depth\n   * @returns {INode[]} An array of ALL object nodes arranged in order corresponding to the result\n   * of a breadth-first traversal of this object\n   * @static\n   */\n  static createBreadthFirstSequenceNode(root: any, depth: number | 'Infinity' = 'Infinity', rootName?: string): INode[] {\n    const iterator = Iterator.createBreadthFirstIterator(root, depth, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root'),\n      response: INode[] = [];\n    let item: INode | undefined;\n    while ((item = iterator.next())) {\n      response.push(item);\n    }\n    return response;\n  }\n\n  /**\n   * @description Creates an array of INode interface objects. An array is a linear sequence of\n   * all PRIMITIVE VALUES obtained from a depth-first traversal of the object tree.\n   * @param {any} root Any value\n   * @param {number | 'Infinity'} depth Maximum object bypass depth\n   * @returns {INode[]} An array of PRIMITIVE values  of objects, arranged in order corresponding\n   * to the result of a depth-first traversal of this object.\n   * @static\n   */\n  static createDepthFirstSequenceLiaf(root: any, depth: number | 'Infinity' = 'Infinity', rootName?: string): INode[] {\n    const iterator = Iterator.createDepthFirstIterator(root, depth, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root'),\n      response: INode[] = [];\n    let item: INode | undefined;\n    while ((item = iterator.nextLiaf())) {\n      response.push(item);\n    }\n    return response;\n  }\n\n  /**\n   * @description Creates an array of INode interface objects. An array is a linear sequence of all\n   * PRIMITIVE VALUES obtained from a breadth-first traversal of the object tree.\n   * @param {any} root Any value\n   * @param {number | 'Infinity'} depth Maximum object bypass depth\n   * @returns {INode[]} An array of PRIMITIVE values   of objects, arranged in order corresponding\n   * to the result of a breadth-first traversal of this object.\n   * @static\n   */\n  static createBreadthFirstSequenceLiaf(root: any, depth: number | 'Infinity' = 'Infinity', rootName?: string): INode[] {\n    const iterator = Iterator.createBreadthFirstIterator(root, depth, typeof rootName === 'string' && rootName.length > 0 ? rootName : 'root'),\n      response: INode[] = [];\n    let item: INode | undefined;\n    while ((item = iterator.nextLiaf())) {\n      response.push(item);\n    }\n    return response;\n  }\n}\n"]}