{"_id":"@alius/utils","_rev":"8-4bb0be03f672fadd6df6932127c02126","time":{"created":"2023-02-02T06:44:10.616Z","1.0.1":"2023-01-12T23:12:01.616Z","modified":"2023-02-04T03:57:49.428Z","1.0.2":"2023-02-01T10:16:36.028Z","1.0.3":"2023-02-02T03:28:21.173Z","1.0.5":"2023-02-02T06:44:10.803Z","1.0.6":"2023-02-04T03:57:49.340Z"},"name":"@alius/utils","dist-tags":{"latest":"1.0.6"},"versions":{"1.0.5":{"name":"@alius/utils","version":"1.0.5","description":"Utilities","author":{"name":"Aleksandras Novikovas","email":"Aleksandras.Novikovas@gmail.com","url":"http://www.systemtier.com/"},"license":"MIT","type":"module","repository":{"type":"git","url":"git+https://aleksandras-novikovas@bitbucket.org/aleksandras-novikovas/utils.git"},"exports":{".":"./index.js","./index.js":"./index.js"},"types":"./index.d.ts","scripts":{"doc":"npx jsdoc src -c $NODE_PATH/jsdoc-import/jsdoc.json -r -d web/docs","lint":"npx eslint src test","test":"npx mocha --loader=$NODE_PATH/esml/esmLoader.js","types":"npx tsc ./src/* -lib esnext --declaration --allowJs --emitDeclarationOnly --esModuleInterop --outDir types"},"keywords":["utils"],"dependencies":{"@alius/exception":"^1.0.5"},"eslintConfig":{"env":{"es2021":true,"node":true},"extends":"eslint:recommended","parserOptions":{"ecmaVersion":2022,"sourceType":"module"},"rules":{"indent":["error",2],"linebreak-style":["error","unix"],"quotes":["error","double"],"semi":["error","always"],"padded-blocks":["error",{"blocks":"never","classes":"never","switches":"never"}]}},"mocha":{"recursive":true},"gitHead":"abd03e9066e03804d374843e6bf1c0316f743690","bugs":{"url":"https://bitbucket.org/aleksandras-novikovas/utils/issues"},"homepage":"https://bitbucket.org/aleksandras-novikovas/utils#readme","_id":"@alius/utils@1.0.5","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-SliLdtWz0Vzfoz+mAggawBn9O5IWocamPa1cqSd0ygIo53Bu23zlXhRBwoddB35j10d9kqxH9Ys9uPsekFMOPg==","shasum":"fbd852db4213b3faf593179a035517ef092732b5","tarball":"https://registry.npmjs.org/@alius/utils/-/utils-1.0.5.tgz","fileCount":13,"unpackedSize":69904,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCN8VvzdaGp9VHopcf6NNr2DfwD1kj6ZUKtWs/ZLNYVnQIgOyYVRLY4XnGeoQOe9iwCcastwb3MtRvMTsEZsNiSb90="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj21u6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr2BA/+OgALC8P2KBLVL5KGeYYj8kBSYwwVgfxvhuCWoVEgQZTFI7l7\r\ndoeb+kxgOlUcmmpx5BTZhZh8zrh6uFNxkMGx/NEOmE3wBPhzsFSvfEAYGzMJ\r\nnElPa8Hr5ZVKxWqhQhkMl6i78O2/ExJfqHYrG+hv1AOQnMf0TcM0ZPrEuRU+\r\nJ97Os7UWII9z1CBYvI0Av2z4e7rZBRAgR+RMUdtpuunRGRfMJRT6ep8+JbX7\r\nZ8gCmSlfgG9Hs+aooF0n4SXi6tpt5fZDEP641y2UwoDilIbq6Z/vy1vHt+P0\r\na3y3th98ySYvS3YXPhBg1wV4QLXDuauwaMDt7pSkB8QWMaqzWzi7AhOJNRXB\r\nIfUpVhEGn7lNWa/WJrBaWoN0JKdg9/RDnD3T0kAK5SxfLz4VRqiSNA7uO73k\r\n2fVx+r+lP04RGB5ALjpPRGoszv3oEI7Ph2KgnKxk9VbECq5piA50oHO+Sd9s\r\n9/6Qep6ivHLJiR31lTpybVj2bOK5fpV+riA8o6nn4T/DlnWsJXZmynUAdxGk\r\ni2Wm0Y3MjNgk6jxiINesQx7uSD6Iug9CKjjnlkUvM6fQUi1iOQ6G+yX1EjL6\r\n6aRbdJFv18AcxO35nxI/H8/Wsyab5eMpdy9TyG83DkqYjarXiwRVu5jZBJYe\r\n9/s0aFYP+BbB4EMxq/WlX1Dro+nr+WW1SXk=\r\n=f1kX\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alius","email":"Aleksandras.Novikovas@gmail.com"},"directories":{},"maintainers":[{"name":"alius","email":"Aleksandras.Novikovas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils_1.0.5_1675320250667_0.4262009264868747"},"_hasShrinkwrap":false},"1.0.6":{"name":"@alius/utils","version":"1.0.6","description":"Utilities","author":{"name":"Aleksandras Novikovas","email":"Aleksandras.Novikovas@gmail.com","url":"http://www.systemtier.com/"},"license":"MIT","type":"module","repository":{"type":"git","url":"git+https://aleksandras-novikovas@bitbucket.org/aleksandras-novikovas/utils.git"},"exports":{".":"./index.js","./index.js":"./index.js"},"types":"./index.d.ts","scripts":{"doc":"npx jsdoc src -c $NODE_PATH/jsdoc-import/jsdoc.json -r -d web/docs","lint":"npx eslint src test","test":"npx mocha --loader=$NODE_PATH/esml/esmLoader.js","types":"npx tsc ./src/* -lib esnext --declaration --allowJs --emitDeclarationOnly --esModuleInterop --outDir types"},"keywords":["utils"],"dependencies":{"@alius/exception":"^1.0.5"},"eslintConfig":{"env":{"es2021":true,"node":true},"extends":"eslint:recommended","parserOptions":{"ecmaVersion":2022,"sourceType":"module"},"rules":{"indent":["error",2],"linebreak-style":["error","unix"],"quotes":["error","double"],"semi":["error","always"],"padded-blocks":["error",{"blocks":"never","classes":"never","switches":"never"}]}},"mocha":{"recursive":true},"gitHead":"424fa33df14656984b3c19b48ca7faee9c8dbbbb","bugs":{"url":"https://bitbucket.org/aleksandras-novikovas/utils/issues"},"homepage":"https://bitbucket.org/aleksandras-novikovas/utils#readme","_id":"@alius/utils@1.0.6","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-4pCT0UxIsLu2hfGAn/hT25ciPEdBL8DQA3v2VzcC4FjBv7MMwE7vw/6sXUjVKVu+3aNIl62v0phSga8yb4iYZg==","shasum":"b333e86faad72ee3d80dc543c2c01afb0ea47fb8","tarball":"https://registry.npmjs.org/@alius/utils/-/utils-1.0.6.tgz","fileCount":13,"unpackedSize":69929,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0pWQgh7RtjVTN1Pg9IMwOjzdl9MojR2RkExsPkZCfFgIgS0i666tWhXYgn72ucQatdtiXot3hoggUJ/cp70XcxiM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj3de9ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqmUxAAnz5mfWBbp1haKgyii1EeNeZUVXqrSli2StHexuwNAgQcAqVv\r\nDvg3nnjEgkVJewrN160TCefkB0VmD/X2NSisyKqXZRrs5qr07FWo0hqhnp3a\r\ndykQyw1YfXUKIaE5fiRf5RELQ0p/GQai/S+J+/NCDR8BGxWyWX5azlzJbMYs\r\ntpCXNcVKF4csZ9vj8wtF97r2rcAVdm89JnjxA9s8Jw/EW7EeGil8qb5a8aMv\r\ntYVeim3ymETIGLPeVkW81shiiz/GoOWffAyfolIqICJceqWbDdHh9KFwrKv1\r\nX0S+BIsX2kD5mU/KAZk4LfLOmonP7F0yVQKZzPfjoUpkcggm7sGdYIELC1y4\r\njMDVmVgJT62YPNdo4+vvbD4DLeVsb1T9Qbp8cTPcpvWaMQSjwS67w7FbWmoR\r\n31RjMZ8G+c4J2qJCNkjBuoI5YSr7zzPgfFTqgYtXYDxRv8eSDkw3NARznktY\r\nUduec6++NHKkfYYC4btJO84ntW4PraJxPA8u6IuM2PPuiSiAEQQ3GQz6mX+Z\r\n1HU0ZyGCMjK2PH6KeXy7vIkPgP7z6KwLD96PqwCZaaN5y9VCaIAwQQB/02+q\r\nl1HJHqt2pQZl2KBi+SIBdgkklNvEHhKM7co8gWCcA0CxErLq6Bz1cd61zzea\r\n+WEFgsQFWwiguOuQ2atGBgI7A/4xlinHYDk=\r\n=1wik\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alius","email":"Aleksandras.Novikovas@gmail.com"},"directories":{},"maintainers":[{"name":"alius","email":"Aleksandras.Novikovas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utils_1.0.6_1675483069191_0.15202315527786636"},"_hasShrinkwrap":false}},"maintainers":[{"name":"alius","email":"Aleksandras.Novikovas@gmail.com"}],"description":"Utilities","homepage":"https://bitbucket.org/aleksandras-novikovas/utils#readme","keywords":["utils"],"repository":{"type":"git","url":"git+https://aleksandras-novikovas@bitbucket.org/aleksandras-novikovas/utils.git"},"author":{"name":"Aleksandras Novikovas","email":"Aleksandras.Novikovas@gmail.com","url":"http://www.systemtier.com/"},"bugs":{"url":"https://bitbucket.org/aleksandras-novikovas/utils/issues"},"license":"MIT","readme":"Various utilities - classes with static getters and methods.\n\n# Installation\n```\nnpm install @alius/utils\n```\n\n# API\n\n## EnvUtils\n### Properties\n### `isBrowser`\nReturns true if code is running in browser environment.\n### `isNode`\nReturns true if code is running in Node.js environment.\n### `isDeno`\nReturns true if code is running in Deno environment.\n\n## StringUtils\n### Properties\n### `HTML_CHAR_MAP`\nMap of characters to HTML\n### `XML_CHAR_MAP`\nMap of characters to XML\n\n### Methods\n### `escapeHtml(text)`\nEscapes special characters so it is safe to add text to html as value.\nReplaces following characters: & < > \" ' \\ \\n \\r \\t \\u2028 \\u2029.\nIf parameter is not string - it is converted to string before escaping.\nReturns empty string if parameter is null or undefined.\n### `escapeXml(text)`\nEscapes special characters so it is safe to add text to xml as value.\nReplaces following characters: & < > \" '\nIf parameter is not string - it is converted to string before escaping.\nReturns empty string if parameter is null or undefined.\n### `escapeRegExp(text)`\nEscapes `RegExp` control characters.\nIf parameter is not string - it is converted to string before escaping.\nReturns empty string if parameter is null or undefined.\n### `pretty(object, indent, indentLevel = 2)`\nConverts provided value to pretty string.\nObject properties and array elements can be indented with specified number of spaces.\n### `toUTF8Bytes(text)`\nConverts string to array of\n[UTF-8](https://datatracker.ietf.org/doc/html/rfc3629) bytes.\n### `fromUTF8Bytes(bytes)`\nConverts array of [UTF-8](https://datatracker.ietf.org/doc/html/rfc3629)\nbytes to string.\n### `fromBase64(text)`\nDecodes [base64](https://datatracker.ietf.org/doc/html/rfc4648#section-4) encoded string.\n### `toBase64(bytes)`\nEncodes byte array to [base64](https://datatracker.ietf.org/doc/html/rfc4648#section-4) string.\n### `fromBase64url(text)`\nDecodes [base64url](https://datatracker.ietf.org/doc/html/rfc4648#section-5) encoded string.\n### `toBase64url(bytes)`\nEncodes byte array to [base64url](https://datatracker.ietf.org/doc/html/rfc4648#section-5) string.\n\n## ObjectUtils\n### Types\n### Cloner\n* `test: (value: any) => boolean` - function tests wether this cloner should be used\n* `clone: (value: any, cloners: Array<Cloner>, path: Array<[any, any]>) => any` - function clones provided value\n\nCloner type.\nObjects of this type are used in `ObjectUtils.deepClone()` to clone provided values.\n`cloner.test()` is used to test if this cloner should be used to clone specified value.\n`cloner.clone()` should clone provided value.\nIf you need deep clone any internal property - add original and cloned values to path and\npass cloners and path params further down eg:\n```\nconst cloned = {};\npath.push([orig, cloned]);\ncloned.internal1 = ObjectUtils.deepClone(orig.internal1, cloners, path);\ncloned.internal2 = ObjectUtils.deepClone(orig.internal2, cloners, path);\n```\n\n### Methods\n### `deepFreeze(o)`\nDeep freezes provided object.\nIf provided object is `array` - deep freezes all elements of that array.\nIf provided object is `Set` - deep freezes all elements of that set.\nIf provided object is `Map` - deep freezes all keys and values of that map.\nIf provided object is `Object` - deep freezes all values of that object.\n### `filter(obj, props = [])`\nMakes shallow object copy with only specified properties.\n```\nconst o = {\n  prop1: 1,\n  prop2: \"Hello\",\n  prop3: true\n};\nconsole.log(ObjectUtils.filter(o, [\"prop1\", \"prop3\"])) // {prop1: 1, prop3: true}\n```\nIf `obj` is not an object - returns `obj`.\nIf `props` is empty - returns shallow copy of provided object.\nIf `props` is specified - returned object will contain only properties specifed in it.\n### `deepClone(object, cloners = [])`\nDeep clones specified object.\nSupports following types:\n* undefined - undefined\n* null - null\n* boolean - boolean\n* number - number\n* bigint - bigint\n* string - string\n* symbol - Does not clone: returns same Symbol object\n* function - Does not clone: returns same function object. Covers AsyncFunction, AsyncGeneratorFunction, GeneratorFunction\n* BigInt - Wrapper for primitive. Does not clone: returns same object\n* Boolean - Wrapper for primitive. Does not clone: returns same object\n* Number - Wrapper for primitive. Does not clone: returns same object\n* String - Wrapper for primitive. Does not clone: returns same object\n* Symbol - Wrapper for primitive. Does not clone: returns same object\n* Atomics - JS defined object. Does not clone: returns same object\n* globalThis - JS defined object. Does not clone: returns same object\n* Intl - JS defined object. Does not clone: returns same object\n* JSON - JS defined object. Does not clone: returns same object\n* Math - JS defined object. Does not clone: returns same object\n* Reflect - JS defined object. Does not clone: returns same object\n* Error - Does not clone: returns same object. Covers all instances of Error\n* ArrayBuffer|SharedArrayBuffer - new object with copied underlying buffer\n* DataView - new object with copied underlying buffer\n* TypedArray - new object with copied underlying buffer. Covers following typed buffers: BigInt64Array, BigUint64Array, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray\n* AsyncGenerator|Generator - Does not clone: returns same object\n* FinalizationRegistry|WeakSet|WeakMap|WeakRef - Does not clone: returns same object\n* Promise - Does not clone: returns same object\n* Date - new Date created with same getTime() as original\n* RegExp - new RegExp created with same pattern and flags as original\n* Set - new Set with deep cloned elements\n* Array - new Array with deep cloned elements\n* Map - new Map with deep cloned keys and deep cloned values.\n* Object - new Object with same prototype and deep cloned own properties.\n\nProxy instances are cloned as normal instances because there is no official way\nto identify is provided object is a proxy or not\nHandles circular references:\nkeeps track of all traversed objects and their respective clones;\nif encounters reference to already traversed object - returns it's respective clone.\n```\nclass Person {\n  #firstName;\n  #lastName;\n  constructor(firstName, lastName) {\n    this.#firstName = firstName;\n    this.#lastName = lastName;\n  }\n  get fullName() {\n    return this.#firstName + \" \" + this.#lastName;\n  }\n  clone() {\n    return new Person(this.#firstName, this.#lastName);\n  }\n}\n\nconst o = {\n  person: new Person(\"John\", \"Doe\"),\n  title: \"worker\",\n  started: new Date(\"2023-01-01\"),\n  manager: new Person(\"Jane\", \"Smith\")\n};\n\nconst oc = ObjectUtils.deepClone(o, [{\n  test: value => value instanceof Person,\n  clone: value => value.clone()\n}]);\n\n```\n### `getPathValue(obj, path)`\nRetrieves value from provided object via specified path.\nIf provided path is empty - returns initial `obj` value.\nIf provided path can not be traversed - returns `undefined`.\n```\nconst o = {\n  prop1: [\n    1,\n    {\n      prop: \"Hello\"\n    },\n    false\n  ],\n  prop2: \"World\"\n};\n\nconsole.log(ObjectUtils.getPathValue(o, \"prop1[0]\")) // 1\nconsole.log(ObjectUtils.getPathValue(o, \"prop1[1].prop\")) // Hello\nconsole.log(ObjectUtils.getPathValue(o, \"prop2\")) // World\n```\n\n## ClassUtils\n### Types\n### ClassDescriptorType\n* module: string - module name\n* class?: string - class name\n* method?: string - method name\n\nClass descriptor type.\nObjects of this type can be used to load classes\nwith Utils.loadClass().\n\n### Methods\n### `isClassDescriptor(descriptor)`\nTests is provided object is instance of `ClassDescriptorType`\n\n### `loadClass(descriptor)`\nLoads class.\nLocal module (name starts with ./ or ../) will be loaded relative\nto current working directory. Otherwise module (from node_modules) will be loaded.\nIf `descriptor` contains property `class` then\nit will be used to select specific class from module export\notherwise default export will be used.\n\n### `importTextModule(jsCode)`\nLoads javascript source code as module (import).\n```\nconst code = `\nexport const hi = \"Hello world\";\nexport function sum(a, b) {\n  return a + b;\n}\n`;\nconst module = await ClassUtils.importTextModule(code);\nconsole.log(module.hi); // Hello world\nconsole.log(module.sum(1, 2)); // 3\n```\n","readmeFilename":"README.md"}