diff --git a/.eslintrc.js b/.eslintrc.js index ede62aa..cd334ba 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,7 +49,6 @@ module.exports = { 'no-restricted-syntax': 'off', 'no-param-reassign': 'off', '@typescript-eslint/ban-ts-comment': 'off', - '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/ban-types': 'off', 'no-console': 'off', diff --git a/.prettierrc b/.prettierrc index 25786c4..523eaf9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,6 +2,22 @@ "printWidth": 150, "tabWidth": 2, "singleQuote": true, - "trailingComma": "all", - "jsxBracketSameLine": true + "trailingComma": "es5", + "jsxBracketSameLine": true, + "arrowParens": "always", + "endOfLine": "lf", + "overrides": [ + { + "files": "*.vue", + "options": { "parser": "vue" } + }, + { + "files": "*.component.html", + "options": { "parser": "angular" } + }, + { + "files": ".prettierrc", + "options": { "parser": "json" } + } + ] } diff --git a/jest.config.js b/jest.config.js index 1b482e0..d6484b7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,6 +9,6 @@ module.exports = { coverageDirectory: 'coverage', moduleDirectories: resolve.directories, moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')), - testPathIgnorePatterns: ['\\\\node_modules\\\\', 'src/', 'dist/'], + testPathIgnorePatterns: ['\\\\node_modules\\\\'], verbose: true, }; diff --git a/packages/overlayscrollbars/dist/overlayscrollbars.esm.js b/packages/overlayscrollbars/dist/overlayscrollbars.esm.js index 8827213..983f8de 100644 --- a/packages/overlayscrollbars/dist/overlayscrollbars.esm.js +++ b/packages/overlayscrollbars/dist/overlayscrollbars.esm.js @@ -15,7 +15,7 @@ function isArrayLike(obj) { return isArray(obj) || !isFunction(obj) && isNumber(length) && length > -1 && length % 1 == 0; } -const keys = obj => Object.keys(obj); +const keys = obj => obj ? Object.keys(obj) : []; function each(source, callback) { if (isArrayLike(source)) { diff --git a/packages/overlayscrollbars/dist/overlayscrollbars.esm.js.map b/packages/overlayscrollbars/dist/overlayscrollbars.esm.js.map index 7547473..57ad163 100644 --- a/packages/overlayscrollbars/dist/overlayscrollbars.esm.js.map +++ b/packages/overlayscrollbars/dist/overlayscrollbars.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"overlayscrollbars.esm.js","sources":["../src/core/utils/types.ts","../src/core/utils/object.ts","../src/core/utils/array.ts","../src/core/dom/traversal.ts","../src/core/dom/manipulation.ts","../src/core/dom/create.ts","../src/index.ts"],"sourcesContent":["import { PlainObject } from 'core/typings';\n\nexport const type: (obj: any) => string = (obj) => {\n if (obj === undefined) return `${obj}`;\n if (obj === null) return `${obj}`;\n return Object.prototype.toString\n .call(obj)\n .replace(/^\\[object (.+)\\]$/, '$1')\n .toLowerCase();\n};\n\nexport function isNumber(obj: any): obj is number {\n return typeof obj === 'number';\n}\n\nexport function isString(obj: any): obj is string {\n return typeof obj === 'string';\n}\n\nexport function isBoolean(obj: any): obj is boolean {\n return typeof obj === 'boolean';\n}\n\nexport function isFunction(obj: any): obj is (...args: Array) => unknown {\n return typeof obj === 'function';\n}\n\nexport function isUndefined(obj: any): obj is undefined {\n return obj === undefined;\n}\n\nexport function isNull(obj: any): obj is null {\n return obj === null;\n}\n\nexport function isArray(obj: any): obj is Array {\n return Array.isArray(obj);\n}\n\nexport function isObject(obj: any): boolean {\n return typeof obj === 'object' && !isArray(obj) && !isNull(obj);\n}\n\n/**\n * Returns true if the given object is array like, false otherwise.\n * @param obj The Object\n */\nexport function isArrayLike(obj: any): obj is ArrayLike {\n const length = !!obj && obj.length;\n return isArray(obj) || (!isFunction(obj) && isNumber(length) && length > -1 && length % 1 == 0); // eslint-disable-line eqeqeq\n}\n\n/**\n * Returns true if the given object is a \"plain\" (e.g. { key: value }) object, false otherwise.\n * @param obj The Object.\n */\nexport function isPlainObject(obj: any): obj is PlainObject {\n if (!obj || !isObject(obj) || type(obj) !== 'object') return false;\n\n let key;\n const proto = 'prototype';\n const { hasOwnProperty } = Object[proto];\n const hasOwnConstructor = hasOwnProperty.call(obj, 'constructor');\n const hasIsPrototypeOf = obj.constructor && obj.constructor[proto] && hasOwnProperty.call(obj.constructor[proto], 'isPrototypeOf');\n\n if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {\n return false;\n }\n\n /* eslint-disable no-restricted-syntax */\n for (key in obj) {\n /**/\n }\n /* eslint-enable */\n\n return isUndefined(key) || hasOwnProperty.call(obj, key);\n}\n\n/**\n * Checks whether the given object is a HTMLElement.\n * @param obj The object which shall be checked.\n */\nexport function isHTMLElement(obj: any): obj is HTMLElement {\n const instaceOfRightHandSide = window.HTMLElement;\n const doInstanceOf = isObject(instaceOfRightHandSide) || isFunction(instaceOfRightHandSide);\n return !!(doInstanceOf ? obj instanceof instaceOfRightHandSide : obj && isObject(obj) && obj.nodeType === 1 && isString(obj.nodeName));\n}\n\n/**\n * Returns true if the given object is empty, false otherwise.\n * @param obj The Object.\n */\nexport function isEmptyObject(obj: any): boolean {\n /* eslint-disable no-restricted-syntax, guard-for-in */\n for (const name in obj) return false;\n return true;\n /* eslint-enable */\n}\n","/**\r\n * Determines whether the passed object has a property with the passed name.\r\n * @param obj The object.\r\n * @param prop The name of the property.\r\n */\r\nexport const hasOwnProperty: (obj: any, prop: string | number | symbol) => boolean = (obj: any, prop: string | number | symbol) =>\r\n Object.prototype.hasOwnProperty.call(obj, prop);\r\n\r\n/**\r\n * Returns the names of the enumerable string properties and methods of an object.\r\n * @param obj The object of which the properties shall be returned.\r\n */\r\nexport const keys: (obj: any) => Array = (obj: any) => Object.keys(obj);\r\n","import { keys } from 'core/utils/object';\nimport { isArrayLike } from 'core/utils/types';\nimport { PlainObject } from 'core/typings';\n\n/**\n * Iterates through a array or object\n * @param arrayLikeOrObject The array or object through which shall be iterated.\n * @param callback The function which is responsible for the iteration.\n * If the function returns true its treated like a \"continue\" statement.\n * If the function returns false its treated like a \"break\" statement.\n */\nexport function each(\n array: Array | ReadonlyArray,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray;\nexport function each(\n array: Array | ReadonlyArray | null,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray | null;\nexport function each(\n arrayLikeObject: ArrayLike,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike;\nexport function each(\n arrayLikeObject: ArrayLike | null,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike | null;\nexport function each(obj: PlainObject, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject;\nexport function each(obj: PlainObject | null, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject | null;\nexport function each(\n source: ArrayLike | PlainObject | null,\n callback: (value: T | any, indexOrKey: any, source: any) => boolean | void,\n): Array | ReadonlyArray | ArrayLike | PlainObject | null {\n if (isArrayLike(source)) {\n for (let i = 0; i < source.length; i++) {\n if (callback(source[i], i, source) === false) {\n break;\n }\n }\n } else if (source) {\n each(keys(source), (key) => callback(source[key], key, source));\n }\n return source;\n}\n\n/**\n * Returns the index of the given inside the given array or -1 if the given item isn't part of the given array.\n * @param arr The array.\n * @param item The item.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\nexport const indexOf: (arr: Array, item: T, fromIndex?: number) => number = (arr, item, fromIndex) => arr.indexOf(item, fromIndex);\n","import { each } from 'core/utils/array';\n\nconst elementIsVisible: (elm: HTMLElement) => boolean = (elm) => !!(elm.offsetWidth || elm.offsetHeight || elm.getClientRects().length);\n\nexport const find: (selector: string, elm?: Element | null) => ReadonlyArray = (selector, elm?) => {\n const arr: Array = [];\n\n each((elm || document).querySelectorAll(selector), (e: Element) => {\n arr.push(e);\n });\n\n return arr;\n};\n\nexport const findFirst: (selector: string, elm?: Element | null) => Element | null = (selector, elm?) => (elm || document).querySelector(selector);\n\nexport const is: (elm: Element | null, selector: string) => boolean = (elm, selector) => {\n if (elm) {\n if (selector === ':visible') {\n return elementIsVisible(elm as HTMLElement);\n }\n if (selector === ':hidden') {\n return !elementIsVisible(elm as HTMLElement);\n }\n if (elm.matches(selector)) {\n return true;\n }\n }\n return false;\n};\n\nexport const children: (elm: Element | null, selector?: string) => ReadonlyArray = (elm, selector?) => {\n const childs: Array = [];\n\n each(elm && elm.children, (child: Element) => {\n if (selector) {\n if (child.matches(selector)) {\n childs.push(child);\n }\n } else {\n childs.push(child);\n }\n });\n\n return childs;\n};\n\nexport const contents: (elm: Element | null) => ReadonlyArray = (elm) => (elm ? Array.from(elm.childNodes) : []);\n\nexport const parent: (elm: Node | null) => Node | null = (elm) => (elm ? elm.parentElement : null);\n","import { isArrayLike } from 'core/utils/types';\nimport { each } from 'core/utils/array';\nimport { parent } from 'core/dom/traversal';\n\ntype NodeCollection = ArrayLike | Node | undefined | null;\n\n/**\n * Inserts Nodes before the given preferredAnchor element.\n * @param parentElm The parent of the preferredAnchor element or the element which shall be the parent of the inserted Nodes.\n * @param preferredAnchor The element before which the Nodes shall be inserted or null if the elements shall be appended at the end.\n * @param insertedElms The Nodes which shall be inserted.\n */\nconst before: (parentElm: Node | null, preferredAnchor: Node | null, insertedElms: NodeCollection) => void = (\n parentElm,\n preferredAnchor,\n insertedElms,\n) => {\n if (insertedElms) {\n let anchor: Node | null = preferredAnchor;\n let fragment: DocumentFragment | Node | undefined | null;\n\n // parent must be defined\n if (parentElm) {\n if (isArrayLike(insertedElms)) {\n fragment = document.createDocumentFragment();\n\n // append all insertedElms to the fragment and if one of these is the anchor, change the anchor\n each(insertedElms, (insertedElm) => {\n if (insertedElm === anchor) {\n anchor = insertedElm.previousSibling;\n }\n fragment!.appendChild(insertedElm);\n });\n } else {\n fragment = insertedElms;\n }\n\n // if the preferred anchor isn't null set it to a valid anchor\n if (preferredAnchor) {\n if (!anchor) {\n anchor = parentElm.firstChild;\n } else if (anchor !== preferredAnchor) {\n anchor = anchor.nextSibling;\n }\n }\n\n parentElm.insertBefore(fragment, anchor);\n }\n }\n};\n\n/**\n * Appends the given children at the end of the given Node.\n * @param node The Node to which the children shall be appended.\n * @param children The Nodes which shall be appended.\n */\nexport const appendChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, null, children);\n};\n\n/**\n * Prepends the given children at the start of the given Node.\n * @param node The Node to which the children shall be prepended.\n * @param children The Nodes which shall be prepended.\n */\nexport const prependChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, node && node.firstChild, children);\n};\n\n/**\n * Inserts the given Nodes before the given Node.\n * @param node The Node before which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertBefore: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node, insertedNodes);\n};\n\n/**\n * Inserts the given Nodes after the given Node.\n * @param node The Node after which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertAfter: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node && node.nextSibling, insertedNodes);\n};\n\n/**\n * Removes the given Nodes from their parent.\n * @param nodes The Nodes which shall be removed.\n */\nexport const removeElements: (nodes: NodeCollection) => void = (nodes) => {\n if (isArrayLike(nodes)) {\n each(Array.from(nodes), (e) => removeElements(e));\n } else if (nodes) {\n const { parentNode } = nodes;\n if (parentNode) {\n parentNode.removeChild(nodes);\n }\n }\n};\n","import { each } from 'core/utils/array';\nimport { contents } from 'core/dom/traversal';\nimport { removeElements } from 'core/dom/manipulation';\n\nexport const createDiv: () => HTMLDivElement = () => document.createElement('div');\n\nexport const createDOM: (html: string) => ReadonlyArray = (html) => {\n const createdDiv = createDiv();\n createdDiv.innerHTML = html.trim();\n\n return each(contents(createdDiv), (elm) => removeElements(elm));\n};\n","import { createDOM } from 'core/dom';\n\n/*\nexport * from 'core/compatibility';\nexport * from 'core/utils';\nexport * from 'core/dom';\nexport * from 'core/options';\nexport * from 'instances';\n*/\n\nconst abc = {\n a: 1,\n b: 1,\n c: 1,\n};\n\nexport default () => {\n const { a, b, c } = abc;\n return [\n createDOM(\n '\\\n
\\\n
\\\n
\\\n
\\\n
\\\n fdfhdfgh\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
',\n ),\n a,\n b,\n c,\n ];\n};\n\nexport const a = 1;\n"],"names":["isNumber","obj","isFunction","isArray","Array","isArrayLike","length","keys","Object","each","source","callback","i","key","contents","elm","from","childNodes","removeElements","nodes","e","parentNode","removeChild","createDiv","document","createElement","createDOM","html","createdDiv","innerHTML","trim","abc","a","b","c"],"mappings":"SAWgBA,SAASC;AACvB,SAAO,OAAOA,GAAP,KAAe,QAAtB;AACD;;SAUeC,WAAWD;AACzB,SAAO,OAAOA,GAAP,KAAe,UAAtB;AACD;;SAUeE,QAAQF;AACtB,SAAOG,KAAK,CAACD,OAAN,CAAcF,GAAd,CAAP;AACD;;SAUeI,YAAyCJ;AACvD,QAAMK,MAAM,GAAG,CAAC,CAACL,GAAF,IAASA,GAAG,CAACK,MAA5B;AACA,SAAOH,OAAO,CAACF,GAAD,CAAP,IAAiB,CAACC,UAAU,CAACD,GAAD,CAAX,IAAoBD,QAAQ,CAACM,MAAD,CAA5B,IAAwCA,MAAM,GAAG,CAAC,CAAlD,IAAuDA,MAAM,GAAG,CAAT,IAAc,CAA7F;;;ACrCK,MAAMC,IAAI,GAAiCN,GAAD,IAAcO,MAAM,CAACD,IAAP,CAAYN,GAAZ,CAAxD;;SCiBSQ,KACdC,QACAC;AAEA,MAAIN,WAAW,CAACK,MAAD,CAAf,EAAyB;AACvB,SAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,MAAM,CAACJ,MAA3B,EAAmCM,CAAC,EAApC,EAAwC;AACtC,UAAID,QAAQ,CAACD,MAAM,CAACE,CAAD,CAAP,EAAYA,CAAZ,EAAeF,MAAf,CAAR,KAAmC,KAAvC,EAA8C;AAC5C;AACD;AACF;AACF,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;AAAQC,IAAAA;AAAR,MAAcH,GAApB;AACA,SAAO,CACLL,SAAS,CACP;;;;;;;;;;;;;;;;;;;;;WADO,CADJ,EAyBLM,CAzBK,EA0BLC,CA1BK,EA2BLC,CA3BK,CAAP;AA6BD,CA/BD;;MAiCaF,CAAC,GAAG;;"} \ No newline at end of file +{"version":3,"file":"overlayscrollbars.esm.js","sources":["../src/core/utils/types.ts","../src/core/utils/object.ts","../src/core/utils/array.ts","../src/core/dom/traversal.ts","../src/core/dom/manipulation.ts","../src/core/dom/create.ts","../src/index.ts"],"sourcesContent":["import { PlainObject } from 'core/typings';\n\nexport const type: (obj: any) => string = (obj) => {\n if (obj === undefined) return `${obj}`;\n if (obj === null) return `${obj}`;\n return Object.prototype.toString\n .call(obj)\n .replace(/^\\[object (.+)\\]$/, '$1')\n .toLowerCase();\n};\n\nexport function isNumber(obj: any): obj is number {\n return typeof obj === 'number';\n}\n\nexport function isString(obj: any): obj is string {\n return typeof obj === 'string';\n}\n\nexport function isBoolean(obj: any): obj is boolean {\n return typeof obj === 'boolean';\n}\n\nexport function isFunction(obj: any): obj is (...args: Array) => unknown {\n return typeof obj === 'function';\n}\n\nexport function isUndefined(obj: any): obj is undefined {\n return obj === undefined;\n}\n\nexport function isNull(obj: any): obj is null {\n return obj === null;\n}\n\nexport function isArray(obj: any): obj is Array {\n return Array.isArray(obj);\n}\n\nexport function isObject(obj: any): boolean {\n return typeof obj === 'object' && !isArray(obj) && !isNull(obj);\n}\n\n/**\n * Returns true if the given object is array like, false otherwise.\n * @param obj The Object\n */\nexport function isArrayLike(obj: any): obj is ArrayLike {\n const length = !!obj && obj.length;\n return isArray(obj) || (!isFunction(obj) && isNumber(length) && length > -1 && length % 1 == 0); // eslint-disable-line eqeqeq\n}\n\n/**\n * Returns true if the given object is a \"plain\" (e.g. { key: value }) object, false otherwise.\n * @param obj The Object.\n */\nexport function isPlainObject(obj: any): obj is PlainObject {\n if (!obj || !isObject(obj) || type(obj) !== 'object') return false;\n\n let key;\n const proto = 'prototype';\n const { hasOwnProperty } = Object[proto];\n const hasOwnConstructor = hasOwnProperty.call(obj, 'constructor');\n const hasIsPrototypeOf = obj.constructor && obj.constructor[proto] && hasOwnProperty.call(obj.constructor[proto], 'isPrototypeOf');\n\n if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {\n return false;\n }\n\n /* eslint-disable no-restricted-syntax */\n for (key in obj) {\n /**/\n }\n /* eslint-enable */\n\n return isUndefined(key) || hasOwnProperty.call(obj, key);\n}\n\n/**\n * Checks whether the given object is a HTMLElement.\n * @param obj The object which shall be checked.\n */\nexport function isHTMLElement(obj: any): obj is HTMLElement {\n const instaceOfRightHandSide = window.HTMLElement;\n const doInstanceOf = isObject(instaceOfRightHandSide) || isFunction(instaceOfRightHandSide);\n return !!(doInstanceOf ? obj instanceof instaceOfRightHandSide : obj && isObject(obj) && obj.nodeType === 1 && isString(obj.nodeName));\n}\n\n/**\n * Returns true if the given object is empty, false otherwise.\n * @param obj The Object.\n */\nexport function isEmptyObject(obj: any): boolean {\n /* eslint-disable no-restricted-syntax, guard-for-in */\n for (const name in obj) return false;\n return true;\n /* eslint-enable */\n}\n","/**\r\n * Determines whether the passed object has a property with the passed name.\r\n * @param obj The object.\r\n * @param prop The name of the property.\r\n */\r\nexport const hasOwnProperty: (obj: any, prop: string | number | symbol) => boolean = (obj: any, prop: string | number | symbol) =>\r\n Object.prototype.hasOwnProperty.call(obj, prop);\r\n\r\n/**\r\n * Returns the names of the enumerable string properties and methods of an object.\r\n * @param obj The object of which the properties shall be returned.\r\n */\r\nexport const keys: (obj: any) => Array = (obj: any) => (obj ? Object.keys(obj) : []);\r\n","import { keys } from 'core/utils/object';\nimport { isArrayLike } from 'core/utils/types';\nimport { PlainObject } from 'core/typings';\n\n/**\n * Iterates through a array or object\n * @param arrayLikeOrObject The array or object through which shall be iterated.\n * @param callback The function which is responsible for the iteration.\n * If the function returns true its treated like a \"continue\" statement.\n * If the function returns false its treated like a \"break\" statement.\n */\nexport function each(\n array: Array | ReadonlyArray,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray;\nexport function each(\n array: Array | ReadonlyArray | null,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray | null;\nexport function each(\n arrayLikeObject: ArrayLike,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike;\nexport function each(\n arrayLikeObject: ArrayLike | null,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike | null;\nexport function each(obj: PlainObject, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject;\nexport function each(obj: PlainObject | null, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject | null;\nexport function each(\n source: ArrayLike | PlainObject | null,\n callback: (value: T | any, indexOrKey: any, source: any) => boolean | void,\n): Array | ReadonlyArray | ArrayLike | PlainObject | null {\n if (isArrayLike(source)) {\n for (let i = 0; i < source.length; i++) {\n if (callback(source[i], i, source) === false) {\n break;\n }\n }\n } else if (source) {\n each(keys(source), (key) => callback(source[key], key, source));\n }\n return source;\n}\n\n/**\n * Returns the index of the given inside the given array or -1 if the given item isn't part of the given array.\n * @param arr The array.\n * @param item The item.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\nexport const indexOf: (arr: Array, item: T, fromIndex?: number) => number = (arr, item, fromIndex) => arr.indexOf(item, fromIndex);\n","import { each } from 'core/utils/array';\n\nconst elementIsVisible: (elm: HTMLElement) => boolean = (elm) => !!(elm.offsetWidth || elm.offsetHeight || elm.getClientRects().length);\n\nexport const find: (selector: string, elm?: Element | null) => ReadonlyArray = (selector, elm?) => {\n const arr: Array = [];\n\n each((elm || document).querySelectorAll(selector), (e: Element) => {\n arr.push(e);\n });\n\n return arr;\n};\n\nexport const findFirst: (selector: string, elm?: Element | null) => Element | null = (selector, elm?) => (elm || document).querySelector(selector);\n\nexport const is: (elm: Element | null, selector: string) => boolean = (elm, selector) => {\n if (elm) {\n if (selector === ':visible') {\n return elementIsVisible(elm as HTMLElement);\n }\n if (selector === ':hidden') {\n return !elementIsVisible(elm as HTMLElement);\n }\n if (elm.matches(selector)) {\n return true;\n }\n }\n return false;\n};\n\nexport const children: (elm: Element | null, selector?: string) => ReadonlyArray = (elm, selector?) => {\n const childs: Array = [];\n\n each(elm && elm.children, (child: Element) => {\n if (selector) {\n if (child.matches(selector)) {\n childs.push(child);\n }\n } else {\n childs.push(child);\n }\n });\n\n return childs;\n};\n\nexport const contents: (elm: Element | null) => ReadonlyArray = (elm) => (elm ? Array.from(elm.childNodes) : []);\n\nexport const parent: (elm: Node | null) => Node | null = (elm) => (elm ? elm.parentElement : null);\n","import { isArrayLike } from 'core/utils/types';\nimport { each } from 'core/utils/array';\nimport { parent } from 'core/dom/traversal';\n\ntype NodeCollection = ArrayLike | Node | undefined | null;\n\n/**\n * Inserts Nodes before the given preferredAnchor element.\n * @param parentElm The parent of the preferredAnchor element or the element which shall be the parent of the inserted Nodes.\n * @param preferredAnchor The element before which the Nodes shall be inserted or null if the elements shall be appended at the end.\n * @param insertedElms The Nodes which shall be inserted.\n */\nconst before: (parentElm: Node | null, preferredAnchor: Node | null, insertedElms: NodeCollection) => void = (\n parentElm,\n preferredAnchor,\n insertedElms,\n) => {\n if (insertedElms) {\n let anchor: Node | null = preferredAnchor;\n let fragment: DocumentFragment | Node | undefined | null;\n\n // parent must be defined\n if (parentElm) {\n if (isArrayLike(insertedElms)) {\n fragment = document.createDocumentFragment();\n\n // append all insertedElms to the fragment and if one of these is the anchor, change the anchor\n each(insertedElms, (insertedElm) => {\n if (insertedElm === anchor) {\n anchor = insertedElm.previousSibling;\n }\n fragment!.appendChild(insertedElm);\n });\n } else {\n fragment = insertedElms;\n }\n\n // if the preferred anchor isn't null set it to a valid anchor\n if (preferredAnchor) {\n if (!anchor) {\n anchor = parentElm.firstChild;\n } else if (anchor !== preferredAnchor) {\n anchor = anchor.nextSibling;\n }\n }\n\n parentElm.insertBefore(fragment, anchor);\n }\n }\n};\n\n/**\n * Appends the given children at the end of the given Node.\n * @param node The Node to which the children shall be appended.\n * @param children The Nodes which shall be appended.\n */\nexport const appendChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, null, children);\n};\n\n/**\n * Prepends the given children at the start of the given Node.\n * @param node The Node to which the children shall be prepended.\n * @param children The Nodes which shall be prepended.\n */\nexport const prependChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, node && node.firstChild, children);\n};\n\n/**\n * Inserts the given Nodes before the given Node.\n * @param node The Node before which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertBefore: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node, insertedNodes);\n};\n\n/**\n * Inserts the given Nodes after the given Node.\n * @param node The Node after which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertAfter: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node && node.nextSibling, insertedNodes);\n};\n\n/**\n * Removes the given Nodes from their parent.\n * @param nodes The Nodes which shall be removed.\n */\nexport const removeElements: (nodes: NodeCollection) => void = (nodes) => {\n if (isArrayLike(nodes)) {\n each(Array.from(nodes), (e) => removeElements(e));\n } else if (nodes) {\n const { parentNode } = nodes;\n if (parentNode) {\n parentNode.removeChild(nodes);\n }\n }\n};\n","import { each } from 'core/utils/array';\nimport { contents } from 'core/dom/traversal';\nimport { removeElements } from 'core/dom/manipulation';\n\nexport const createDiv: () => HTMLDivElement = () => document.createElement('div');\n\nexport const createDOM: (html: string) => ReadonlyArray = (html) => {\n const createdDiv = createDiv();\n createdDiv.innerHTML = html.trim();\n\n return each(contents(createdDiv), (elm) => removeElements(elm));\n};\n","import { createDOM } from 'core/dom';\n\n/*\nexport * from 'core/compatibility';\nexport * from 'core/utils';\nexport * from 'core/dom';\nexport * from 'core/options';\nexport * from 'instances';\n*/\n\nconst abc = {\n a: 1,\n b: 1,\n c: 1,\n};\n\nexport default () => {\n const { a, b, c } = abc;\n return [\n createDOM(\n '\\\n
\\\n
\\\n
\\\n
\\\n
\\\n fdfhdfgh\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
',\n ),\n a,\n b,\n c,\n ];\n};\n\nexport const a = 1;\n"],"names":["isNumber","obj","isFunction","isArray","Array","isArrayLike","length","keys","Object","each","source","callback","i","key","contents","elm","from","childNodes","removeElements","nodes","e","parentNode","removeChild","createDiv","document","createElement","createDOM","html","createdDiv","innerHTML","trim","abc","a","b","c"],"mappings":"SAWgBA,SAASC;AACvB,SAAO,OAAOA,GAAP,KAAe,QAAtB;AACD;;SAUeC,WAAWD;AACzB,SAAO,OAAOA,GAAP,KAAe,UAAtB;AACD;;SAUeE,QAAQF;AACtB,SAAOG,KAAK,CAACD,OAAN,CAAcF,GAAd,CAAP;AACD;;SAUeI,YAAyCJ;AACvD,QAAMK,MAAM,GAAG,CAAC,CAACL,GAAF,IAASA,GAAG,CAACK,MAA5B;AACA,SAAOH,OAAO,CAACF,GAAD,CAAP,IAAiB,CAACC,UAAU,CAACD,GAAD,CAAX,IAAoBD,QAAQ,CAACM,MAAD,CAA5B,IAAwCA,MAAM,GAAG,CAAC,CAAlD,IAAuDA,MAAM,GAAG,CAAT,IAAc,CAA7F;;;ACrCK,MAAMC,IAAI,GAAiCN,GAAD,IAAeA,GAAG,GAAGO,MAAM,CAACD,IAAP,CAAYN,GAAZ,CAAH,GAAsB,EAAlF;;SCiBSQ,KACdC,QACAC;AAEA,MAAIN,WAAW,CAACK,MAAD,CAAf,EAAyB;AACvB,SAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,MAAM,CAACJ,MAA3B,EAAmCM,CAAC,EAApC,EAAwC;AACtC,UAAID,QAAQ,CAACD,MAAM,CAACE,CAAD,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EAAE;AAHO,CAAZ;;AAMA,YAAe;AACb,QAAM;AAAEF,IAAAA,CAAF;AAAKC,IAAAA,CAAL;AAAQC,IAAAA;AAAR,MAAcH,GAApB;AACA,SAAO,CACLL,SAAS,CACP;;;;;;;;;;;;;;;;;;;;;WADO,CADJ,EAyBLM,CAzBK,EA0BLC,CA1BK,EA2BLC,CA3BK,CAAP;AA6BD,CA/BD;;MAiCaF,CAAC,GAAG;;"} \ No newline at end of file diff --git a/packages/overlayscrollbars/dist/overlayscrollbars.esm.min.js b/packages/overlayscrollbars/dist/overlayscrollbars.esm.min.js index 525f80a..4587694 100644 --- a/packages/overlayscrollbars/dist/overlayscrollbars.esm.min.js +++ b/packages/overlayscrollbars/dist/overlayscrollbars.esm.min.js @@ -1 +1 @@ -function r(r){const s=!!r&&r.length;return function(r){return Array.isArray(r)}(r)||!function(r){return"function"==typeof r}(r)&&function(r){return"number"==typeof r}(s)&&s>-1&&s%1==0}function s(o,c){if(r(o))for(let r=0;rc(o[r],r,o));var i;return o}const o=c=>{if(r(c))s(Array.from(c),r=>o(r));else if(c){const{parentNode:r}=c;r&&r.removeChild(c)}},c=r=>{const c=document.createElement("div");return c.innerHTML=r.trim(),s((i=c)?Array.from(i.childNodes):[],r=>o(r));var i},i={a:1,b:1,c:1};const e=1;export default()=>{const{a:r,b:s,c:o}=i;return[c('
fdfhdfgh
'),r,s,o]};export{e as a}; \ No newline at end of file +function r(r){const s=!!r&&r.length;return function(r){return Array.isArray(r)}(r)||!function(r){return"function"==typeof r}(r)&&function(r){return"number"==typeof r}(s)&&s>-1&&s%1==0}function s(o,c){if(r(o))for(let r=0;rc(o[r],r,o));var i;return o}const o=c=>{if(r(c))s(Array.from(c),r=>o(r));else if(c){const{parentNode:r}=c;r&&r.removeChild(c)}},c=r=>{const c=document.createElement("div");return c.innerHTML=r.trim(),s((i=c)?Array.from(i.childNodes):[],r=>o(r));var i},i={a:1,b:1,c:1};const e=1;export default()=>{const{a:r,b:s,c:o}=i;return[c('
fdfhdfgh
'),r,s,o]};export{e as a}; \ No newline at end of file diff --git a/packages/overlayscrollbars/dist/overlayscrollbars.js b/packages/overlayscrollbars/dist/overlayscrollbars.js index 7e0bf90..05cb47d 100644 --- a/packages/overlayscrollbars/dist/overlayscrollbars.js +++ b/packages/overlayscrollbars/dist/overlayscrollbars.js @@ -19,7 +19,7 @@ var OverlayScrollbars = function (exports) { } var keys = function keys(obj) { - return Object.keys(obj); + return obj ? Object.keys(obj) : []; }; function each(source, callback) { diff --git a/packages/overlayscrollbars/dist/overlayscrollbars.js.map b/packages/overlayscrollbars/dist/overlayscrollbars.js.map index 2afa3f6..3f610aa 100644 --- a/packages/overlayscrollbars/dist/overlayscrollbars.js.map +++ b/packages/overlayscrollbars/dist/overlayscrollbars.js.map @@ -1 +1 @@ -{"version":3,"file":"overlayscrollbars.js","sources":["../src/core/utils/types.ts","../src/core/utils/object.ts","../src/core/utils/array.ts","../src/core/dom/traversal.ts","../src/core/dom/manipulation.ts","../src/core/dom/create.ts","../src/index.ts"],"sourcesContent":["import { PlainObject } from 'core/typings';\n\nexport const type: (obj: any) => string = (obj) => {\n if (obj === undefined) return `${obj}`;\n if (obj === null) return `${obj}`;\n return Object.prototype.toString\n .call(obj)\n .replace(/^\\[object (.+)\\]$/, '$1')\n .toLowerCase();\n};\n\nexport function isNumber(obj: any): obj is number {\n return typeof obj === 'number';\n}\n\nexport function isString(obj: any): obj is string {\n return typeof obj === 'string';\n}\n\nexport function isBoolean(obj: any): obj is boolean {\n return typeof obj === 'boolean';\n}\n\nexport function isFunction(obj: any): obj is (...args: Array) => unknown {\n return typeof obj === 'function';\n}\n\nexport function isUndefined(obj: any): obj is undefined {\n return obj === undefined;\n}\n\nexport function isNull(obj: any): obj is null {\n return obj === null;\n}\n\nexport function isArray(obj: any): obj is Array {\n return Array.isArray(obj);\n}\n\nexport function isObject(obj: any): boolean {\n return typeof obj === 'object' && !isArray(obj) && !isNull(obj);\n}\n\n/**\n * Returns true if the given object is array like, false otherwise.\n * @param obj The Object\n */\nexport function isArrayLike(obj: any): obj is ArrayLike {\n const length = !!obj && obj.length;\n return isArray(obj) || (!isFunction(obj) && isNumber(length) && length > -1 && length % 1 == 0); // eslint-disable-line eqeqeq\n}\n\n/**\n * Returns true if the given object is a \"plain\" (e.g. { key: value }) object, false otherwise.\n * @param obj The Object.\n */\nexport function isPlainObject(obj: any): obj is PlainObject {\n if (!obj || !isObject(obj) || type(obj) !== 'object') return false;\n\n let key;\n const proto = 'prototype';\n const { hasOwnProperty } = Object[proto];\n const hasOwnConstructor = hasOwnProperty.call(obj, 'constructor');\n const hasIsPrototypeOf = obj.constructor && obj.constructor[proto] && hasOwnProperty.call(obj.constructor[proto], 'isPrototypeOf');\n\n if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {\n return false;\n }\n\n /* eslint-disable no-restricted-syntax */\n for (key in obj) {\n /**/\n }\n /* eslint-enable */\n\n return isUndefined(key) || hasOwnProperty.call(obj, key);\n}\n\n/**\n * Checks whether the given object is a HTMLElement.\n * @param obj The object which shall be checked.\n */\nexport function isHTMLElement(obj: any): obj is HTMLElement {\n const instaceOfRightHandSide = window.HTMLElement;\n const doInstanceOf = isObject(instaceOfRightHandSide) || isFunction(instaceOfRightHandSide);\n return !!(doInstanceOf ? obj instanceof instaceOfRightHandSide : obj && isObject(obj) && obj.nodeType === 1 && isString(obj.nodeName));\n}\n\n/**\n * Returns true if the given object is empty, false otherwise.\n * @param obj The Object.\n */\nexport function isEmptyObject(obj: any): boolean {\n /* eslint-disable no-restricted-syntax, guard-for-in */\n for (const name in obj) return false;\n return true;\n /* eslint-enable */\n}\n","/**\r\n * Determines whether the passed object has a property with the passed name.\r\n * @param obj The object.\r\n * @param prop The name of the property.\r\n */\r\nexport const hasOwnProperty: (obj: any, prop: string | number | symbol) => boolean = (obj: any, prop: string | number | symbol) =>\r\n Object.prototype.hasOwnProperty.call(obj, prop);\r\n\r\n/**\r\n * Returns the names of the enumerable string properties and methods of an object.\r\n * @param obj The object of which the properties shall be returned.\r\n */\r\nexport const keys: (obj: any) => Array = (obj: any) => Object.keys(obj);\r\n","import { keys } from 'core/utils/object';\nimport { isArrayLike } from 'core/utils/types';\nimport { PlainObject } from 'core/typings';\n\n/**\n * Iterates through a array or object\n * @param arrayLikeOrObject The array or object through which shall be iterated.\n * @param callback The function which is responsible for the iteration.\n * If the function returns true its treated like a \"continue\" statement.\n * If the function returns false its treated like a \"break\" statement.\n */\nexport function each(\n array: Array | ReadonlyArray,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray;\nexport function each(\n array: Array | ReadonlyArray | null,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray | null;\nexport function each(\n arrayLikeObject: ArrayLike,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike;\nexport function each(\n arrayLikeObject: ArrayLike | null,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike | null;\nexport function each(obj: PlainObject, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject;\nexport function each(obj: PlainObject | null, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject | null;\nexport function each(\n source: ArrayLike | PlainObject | null,\n callback: (value: T | any, indexOrKey: any, source: any) => boolean | void,\n): Array | ReadonlyArray | ArrayLike | PlainObject | null {\n if (isArrayLike(source)) {\n for (let i = 0; i < source.length; i++) {\n if (callback(source[i], i, source) === false) {\n break;\n }\n }\n } else if (source) {\n each(keys(source), (key) => callback(source[key], key, source));\n }\n return source;\n}\n\n/**\n * Returns the index of the given inside the given array or -1 if the given item isn't part of the given array.\n * @param arr The array.\n * @param item The item.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\nexport const indexOf: (arr: Array, item: T, fromIndex?: number) => number = (arr, item, fromIndex) => arr.indexOf(item, fromIndex);\n","import { each } from 'core/utils/array';\n\nconst elementIsVisible: (elm: HTMLElement) => boolean = (elm) => !!(elm.offsetWidth || elm.offsetHeight || elm.getClientRects().length);\n\nexport const find: (selector: string, elm?: Element | null) => ReadonlyArray = (selector, elm?) => {\n const arr: Array = [];\n\n each((elm || document).querySelectorAll(selector), (e: Element) => {\n arr.push(e);\n });\n\n return arr;\n};\n\nexport const findFirst: (selector: string, elm?: Element | null) => Element | null = (selector, elm?) => (elm || document).querySelector(selector);\n\nexport const is: (elm: Element | null, selector: string) => boolean = (elm, selector) => {\n if (elm) {\n if (selector === ':visible') {\n return elementIsVisible(elm as HTMLElement);\n }\n if (selector === ':hidden') {\n return !elementIsVisible(elm as HTMLElement);\n }\n if (elm.matches(selector)) {\n return true;\n }\n }\n return false;\n};\n\nexport const children: (elm: Element | null, selector?: string) => ReadonlyArray = (elm, selector?) => {\n const childs: Array = [];\n\n each(elm && elm.children, (child: Element) => {\n if (selector) {\n if (child.matches(selector)) {\n childs.push(child);\n }\n } else {\n childs.push(child);\n }\n });\n\n return childs;\n};\n\nexport const contents: (elm: Element | null) => ReadonlyArray = (elm) => (elm ? Array.from(elm.childNodes) : []);\n\nexport const parent: (elm: Node | null) => Node | null = (elm) => (elm ? elm.parentElement : null);\n","import { isArrayLike } from 'core/utils/types';\nimport { each } from 'core/utils/array';\nimport { parent } from 'core/dom/traversal';\n\ntype NodeCollection = ArrayLike | Node | undefined | null;\n\n/**\n * Inserts Nodes before the given preferredAnchor element.\n * @param parentElm The parent of the preferredAnchor element or the element which shall be the parent of the inserted Nodes.\n * @param preferredAnchor The element before which the Nodes shall be inserted or null if the elements shall be appended at the end.\n * @param insertedElms The Nodes which shall be inserted.\n */\nconst before: (parentElm: Node | null, preferredAnchor: Node | null, insertedElms: NodeCollection) => void = (\n parentElm,\n preferredAnchor,\n insertedElms,\n) => {\n if (insertedElms) {\n let anchor: Node | null = preferredAnchor;\n let fragment: DocumentFragment | Node | undefined | null;\n\n // parent must be defined\n if (parentElm) {\n if (isArrayLike(insertedElms)) {\n fragment = document.createDocumentFragment();\n\n // append all insertedElms to the fragment and if one of these is the anchor, change the anchor\n each(insertedElms, (insertedElm) => {\n if (insertedElm === anchor) {\n anchor = insertedElm.previousSibling;\n }\n fragment!.appendChild(insertedElm);\n });\n } else {\n fragment = insertedElms;\n }\n\n // if the preferred anchor isn't null set it to a valid anchor\n if (preferredAnchor) {\n if (!anchor) {\n anchor = parentElm.firstChild;\n } else if (anchor !== preferredAnchor) {\n anchor = anchor.nextSibling;\n }\n }\n\n parentElm.insertBefore(fragment, anchor);\n }\n }\n};\n\n/**\n * Appends the given children at the end of the given Node.\n * @param node The Node to which the children shall be appended.\n * @param children The Nodes which shall be appended.\n */\nexport const appendChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, null, children);\n};\n\n/**\n * Prepends the given children at the start of the given Node.\n * @param node The Node to which the children shall be prepended.\n * @param children The Nodes which shall be prepended.\n */\nexport const prependChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, node && node.firstChild, children);\n};\n\n/**\n * Inserts the given Nodes before the given Node.\n * @param node The Node before which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertBefore: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node, insertedNodes);\n};\n\n/**\n * Inserts the given Nodes after the given Node.\n * @param node The Node after which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertAfter: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node && node.nextSibling, insertedNodes);\n};\n\n/**\n * Removes the given Nodes from their parent.\n * @param nodes The Nodes which shall be removed.\n */\nexport const removeElements: (nodes: NodeCollection) => void = (nodes) => {\n if (isArrayLike(nodes)) {\n each(Array.from(nodes), (e) => removeElements(e));\n } else if (nodes) {\n const { parentNode } = nodes;\n if (parentNode) {\n parentNode.removeChild(nodes);\n }\n }\n};\n","import { each } from 'core/utils/array';\nimport { contents } from 'core/dom/traversal';\nimport { removeElements } from 'core/dom/manipulation';\n\nexport const createDiv: () => HTMLDivElement = () => document.createElement('div');\n\nexport const createDOM: (html: string) => ReadonlyArray = (html) => {\n const createdDiv = createDiv();\n createdDiv.innerHTML = html.trim();\n\n return each(contents(createdDiv), (elm) => removeElements(elm));\n};\n","import { createDOM } from 'core/dom';\n\n/*\nexport * from 'core/compatibility';\nexport * from 'core/utils';\nexport * from 'core/dom';\nexport * from 'core/options';\nexport * from 'instances';\n*/\n\nconst abc = {\n a: 1,\n b: 1,\n c: 1,\n};\n\nexport default () => {\n const { a, b, c } = abc;\n return [\n createDOM(\n '\\\n
\\\n
\\\n
\\\n
\\\n
\\\n fdfhdfgh\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
',\n ),\n a,\n b,\n c,\n ];\n};\n\nexport const a = 1;\n"],"names":["isNumber","obj","isFunction","isArray","Array","isArrayLike","length","keys","Object","each","source","callback","i","key","contents","elm","from","childNodes","removeElements","nodes","e","parentNode","removeChild","createDiv","document","createElement","createDOM","html","createdDiv","innerHTML","trim","abc","a","b","c"],"mappings":";;;WAWgBA,SAASC;AACvB,WAAO,OAAOA,GAAP,KAAe,QAAtB;AACD;;WAUeC,WAAWD;AACzB,WAAO,OAAOA,GAAP,KAAe,UAAtB;AACD;;WAUeE,QAAQF;AACtB,WAAOG,KAAK,CAACD,OAAN,CAAcF,GAAd,CAAP;AACD;;WAUeI,YAAyCJ;AACvD,QAAMK,MAAM,GAAG,CAAC,CAACL,GAAF,IAASA,GAAG,CAACK,MAA5B;AACA,WAAOH,OAAO,CAACF,GAAD,CAAP,IAAiB,CAACC,UAAU,CAACD,GAAD,CAAX,IAAoBD,QAAQ,CAACM,MAAD,CAA5B,IAAwCA,MAAM,GAAG,CAAC,CAAlD,IAAuDA,MAAM,GAAG,CAAT,IAAc,CAA7F;;;ACrCK,MAAMC,IAAI,GAAgC,SAApCA,IAAoC,C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WAAMC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAAN;AAAA,GAAxC;;AAEA,MAAMC,SAAS,GAA0C,SAAnDA,SAAmD,CAACC,IAAD;AAC9D,QAAMC,UAAU,GAAGL,SAAS,EAA5B;AACAK,IAAAA,UAAU,CAACC,SAAX,GAAuBF,IAAI,CAACG,IAAL,EAAvB;AAEA,WAAOrB,IAAI,CAACK,QAAQ,CAACc,UAAD,CAAT,EAAuB,UAACb,GAAD;AAAA,aAASG,cAAc,CAACH,GAAD,CAAvB;AAAA,KAAvB,CAAX;AACD,GALM;;ACIP,MAAMgB,GAAG,GAAG;AACVC,IAAAA,CAAC,EAAE,CADO;AAEVC,IAAAA,CAAC,EAAE,CAFO;AAGVC,IAAAA,CAAC,EAAE;AAHO,GAAZ;;cAMe,cAAA;QACLF,IAAYD,IAAZC;QAAGC,IAASF,IAATE;QAAGC,IAAMH,IAANG;AACd,WAAO,CACLR,SAAS,CACP;;;;;;;;;;;;;;;;;;;;;WADO,CADJ,EAyBLM,CAzBK,EA0BLC,CA1BK,EA2BLC,CA3BK,CAAP;AA6BD;;MAEYF,CAAC,GAAG;;;;"} \ No newline at end of file +{"version":3,"file":"overlayscrollbars.js","sources":["../src/core/utils/types.ts","../src/core/utils/object.ts","../src/core/utils/array.ts","../src/core/dom/traversal.ts","../src/core/dom/manipulation.ts","../src/core/dom/create.ts","../src/index.ts"],"sourcesContent":["import { PlainObject } from 'core/typings';\n\nexport const type: (obj: any) => string = (obj) => {\n if (obj === undefined) return `${obj}`;\n if (obj === null) return `${obj}`;\n return Object.prototype.toString\n .call(obj)\n .replace(/^\\[object (.+)\\]$/, '$1')\n .toLowerCase();\n};\n\nexport function isNumber(obj: any): obj is number {\n return typeof obj === 'number';\n}\n\nexport function isString(obj: any): obj is string {\n return typeof obj === 'string';\n}\n\nexport function isBoolean(obj: any): obj is boolean {\n return typeof obj === 'boolean';\n}\n\nexport function isFunction(obj: any): obj is (...args: Array) => unknown {\n return typeof obj === 'function';\n}\n\nexport function isUndefined(obj: any): obj is undefined {\n return obj === undefined;\n}\n\nexport function isNull(obj: any): obj is null {\n return obj === null;\n}\n\nexport function isArray(obj: any): obj is Array {\n return Array.isArray(obj);\n}\n\nexport function isObject(obj: any): boolean {\n return typeof obj === 'object' && !isArray(obj) && !isNull(obj);\n}\n\n/**\n * Returns true if the given object is array like, false otherwise.\n * @param obj The Object\n */\nexport function isArrayLike(obj: any): obj is ArrayLike {\n const length = !!obj && obj.length;\n return isArray(obj) || (!isFunction(obj) && isNumber(length) && length > -1 && length % 1 == 0); // eslint-disable-line eqeqeq\n}\n\n/**\n * Returns true if the given object is a \"plain\" (e.g. { key: value }) object, false otherwise.\n * @param obj The Object.\n */\nexport function isPlainObject(obj: any): obj is PlainObject {\n if (!obj || !isObject(obj) || type(obj) !== 'object') return false;\n\n let key;\n const proto = 'prototype';\n const { hasOwnProperty } = Object[proto];\n const hasOwnConstructor = hasOwnProperty.call(obj, 'constructor');\n const hasIsPrototypeOf = obj.constructor && obj.constructor[proto] && hasOwnProperty.call(obj.constructor[proto], 'isPrototypeOf');\n\n if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {\n return false;\n }\n\n /* eslint-disable no-restricted-syntax */\n for (key in obj) {\n /**/\n }\n /* eslint-enable */\n\n return isUndefined(key) || hasOwnProperty.call(obj, key);\n}\n\n/**\n * Checks whether the given object is a HTMLElement.\n * @param obj The object which shall be checked.\n */\nexport function isHTMLElement(obj: any): obj is HTMLElement {\n const instaceOfRightHandSide = window.HTMLElement;\n const doInstanceOf = isObject(instaceOfRightHandSide) || isFunction(instaceOfRightHandSide);\n return !!(doInstanceOf ? obj instanceof instaceOfRightHandSide : obj && isObject(obj) && obj.nodeType === 1 && isString(obj.nodeName));\n}\n\n/**\n * Returns true if the given object is empty, false otherwise.\n * @param obj The Object.\n */\nexport function isEmptyObject(obj: any): boolean {\n /* eslint-disable no-restricted-syntax, guard-for-in */\n for (const name in obj) return false;\n return true;\n /* eslint-enable */\n}\n","/**\r\n * Determines whether the passed object has a property with the passed name.\r\n * @param obj The object.\r\n * @param prop The name of the property.\r\n */\r\nexport const hasOwnProperty: (obj: any, prop: string | number | symbol) => boolean = (obj: any, prop: string | number | symbol) =>\r\n Object.prototype.hasOwnProperty.call(obj, prop);\r\n\r\n/**\r\n * Returns the names of the enumerable string properties and methods of an object.\r\n * @param obj The object of which the properties shall be returned.\r\n */\r\nexport const keys: (obj: any) => Array = (obj: any) => (obj ? Object.keys(obj) : []);\r\n","import { keys } from 'core/utils/object';\nimport { isArrayLike } from 'core/utils/types';\nimport { PlainObject } from 'core/typings';\n\n/**\n * Iterates through a array or object\n * @param arrayLikeOrObject The array or object through which shall be iterated.\n * @param callback The function which is responsible for the iteration.\n * If the function returns true its treated like a \"continue\" statement.\n * If the function returns false its treated like a \"break\" statement.\n */\nexport function each(\n array: Array | ReadonlyArray,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray;\nexport function each(\n array: Array | ReadonlyArray | null,\n callback: (value: T, indexOrKey: number, source: Array) => boolean | void,\n): Array | ReadonlyArray | null;\nexport function each(\n arrayLikeObject: ArrayLike,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike;\nexport function each(\n arrayLikeObject: ArrayLike | null,\n callback: (value: T, indexOrKey: number, source: ArrayLike) => boolean | void,\n): ArrayLike | null;\nexport function each(obj: PlainObject, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject;\nexport function each(obj: PlainObject | null, callback: (value: any, indexOrKey: string, source: PlainObject) => boolean | void): PlainObject | null;\nexport function each(\n source: ArrayLike | PlainObject | null,\n callback: (value: T | any, indexOrKey: any, source: any) => boolean | void,\n): Array | ReadonlyArray | ArrayLike | PlainObject | null {\n if (isArrayLike(source)) {\n for (let i = 0; i < source.length; i++) {\n if (callback(source[i], i, source) === false) {\n break;\n }\n }\n } else if (source) {\n each(keys(source), (key) => callback(source[key], key, source));\n }\n return source;\n}\n\n/**\n * Returns the index of the given inside the given array or -1 if the given item isn't part of the given array.\n * @param arr The array.\n * @param item The item.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\nexport const indexOf: (arr: Array, item: T, fromIndex?: number) => number = (arr, item, fromIndex) => arr.indexOf(item, fromIndex);\n","import { each } from 'core/utils/array';\n\nconst elementIsVisible: (elm: HTMLElement) => boolean = (elm) => !!(elm.offsetWidth || elm.offsetHeight || elm.getClientRects().length);\n\nexport const find: (selector: string, elm?: Element | null) => ReadonlyArray = (selector, elm?) => {\n const arr: Array = [];\n\n each((elm || document).querySelectorAll(selector), (e: Element) => {\n arr.push(e);\n });\n\n return arr;\n};\n\nexport const findFirst: (selector: string, elm?: Element | null) => Element | null = (selector, elm?) => (elm || document).querySelector(selector);\n\nexport const is: (elm: Element | null, selector: string) => boolean = (elm, selector) => {\n if (elm) {\n if (selector === ':visible') {\n return elementIsVisible(elm as HTMLElement);\n }\n if (selector === ':hidden') {\n return !elementIsVisible(elm as HTMLElement);\n }\n if (elm.matches(selector)) {\n return true;\n }\n }\n return false;\n};\n\nexport const children: (elm: Element | null, selector?: string) => ReadonlyArray = (elm, selector?) => {\n const childs: Array = [];\n\n each(elm && elm.children, (child: Element) => {\n if (selector) {\n if (child.matches(selector)) {\n childs.push(child);\n }\n } else {\n childs.push(child);\n }\n });\n\n return childs;\n};\n\nexport const contents: (elm: Element | null) => ReadonlyArray = (elm) => (elm ? Array.from(elm.childNodes) : []);\n\nexport const parent: (elm: Node | null) => Node | null = (elm) => (elm ? elm.parentElement : null);\n","import { isArrayLike } from 'core/utils/types';\nimport { each } from 'core/utils/array';\nimport { parent } from 'core/dom/traversal';\n\ntype NodeCollection = ArrayLike | Node | undefined | null;\n\n/**\n * Inserts Nodes before the given preferredAnchor element.\n * @param parentElm The parent of the preferredAnchor element or the element which shall be the parent of the inserted Nodes.\n * @param preferredAnchor The element before which the Nodes shall be inserted or null if the elements shall be appended at the end.\n * @param insertedElms The Nodes which shall be inserted.\n */\nconst before: (parentElm: Node | null, preferredAnchor: Node | null, insertedElms: NodeCollection) => void = (\n parentElm,\n preferredAnchor,\n insertedElms,\n) => {\n if (insertedElms) {\n let anchor: Node | null = preferredAnchor;\n let fragment: DocumentFragment | Node | undefined | null;\n\n // parent must be defined\n if (parentElm) {\n if (isArrayLike(insertedElms)) {\n fragment = document.createDocumentFragment();\n\n // append all insertedElms to the fragment and if one of these is the anchor, change the anchor\n each(insertedElms, (insertedElm) => {\n if (insertedElm === anchor) {\n anchor = insertedElm.previousSibling;\n }\n fragment!.appendChild(insertedElm);\n });\n } else {\n fragment = insertedElms;\n }\n\n // if the preferred anchor isn't null set it to a valid anchor\n if (preferredAnchor) {\n if (!anchor) {\n anchor = parentElm.firstChild;\n } else if (anchor !== preferredAnchor) {\n anchor = anchor.nextSibling;\n }\n }\n\n parentElm.insertBefore(fragment, anchor);\n }\n }\n};\n\n/**\n * Appends the given children at the end of the given Node.\n * @param node The Node to which the children shall be appended.\n * @param children The Nodes which shall be appended.\n */\nexport const appendChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, null, children);\n};\n\n/**\n * Prepends the given children at the start of the given Node.\n * @param node The Node to which the children shall be prepended.\n * @param children The Nodes which shall be prepended.\n */\nexport const prependChildren: (node: Node | null, children: NodeCollection) => void = (node, children) => {\n before(node, node && node.firstChild, children);\n};\n\n/**\n * Inserts the given Nodes before the given Node.\n * @param node The Node before which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertBefore: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node, insertedNodes);\n};\n\n/**\n * Inserts the given Nodes after the given Node.\n * @param node The Node after which the given Nodes shall be inserted.\n * @param insertedNodes The Nodes which shall be inserted.\n */\nexport const insertAfter: (node: Node | null, insertedNodes: NodeCollection) => void = (node, insertedNodes) => {\n before(parent(node), node && node.nextSibling, insertedNodes);\n};\n\n/**\n * Removes the given Nodes from their parent.\n * @param nodes The Nodes which shall be removed.\n */\nexport const removeElements: (nodes: NodeCollection) => void = (nodes) => {\n if (isArrayLike(nodes)) {\n each(Array.from(nodes), (e) => removeElements(e));\n } else if (nodes) {\n const { parentNode } = nodes;\n if (parentNode) {\n parentNode.removeChild(nodes);\n }\n }\n};\n","import { each } from 'core/utils/array';\nimport { contents } from 'core/dom/traversal';\nimport { removeElements } from 'core/dom/manipulation';\n\nexport const createDiv: () => HTMLDivElement = () => document.createElement('div');\n\nexport const createDOM: (html: string) => ReadonlyArray = (html) => {\n const createdDiv = createDiv();\n createdDiv.innerHTML = html.trim();\n\n return each(contents(createdDiv), (elm) => removeElements(elm));\n};\n","import { createDOM } from 'core/dom';\n\n/*\nexport * from 'core/compatibility';\nexport * from 'core/utils';\nexport * from 'core/dom';\nexport * from 'core/options';\nexport * from 'instances';\n*/\n\nconst abc = {\n a: 1,\n b: 1,\n c: 1,\n};\n\nexport default () => {\n const { a, b, c } = abc;\n return [\n createDOM(\n '\\\n
\\\n
\\\n
\\\n
\\\n
\\\n fdfhdfgh\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
\\\n
',\n ),\n a,\n b,\n c,\n ];\n};\n\nexport const a = 1;\n"],"names":["isNumber","obj","isFunction","isArray","Array","isArrayLike","length","keys","Object","each","source","callback","i","key","contents","elm","from","childNodes","removeElements","nodes","e","parentNode","removeChild","createDiv","document","createElement","createDOM","html","createdDiv","innerHTML","trim","abc","a","b","c"],"mappings":";;;WAWgBA,SAASC;AACvB,WAAO,OAAOA,GAAP,KAAe,QAAtB;AACD;;WAUeC,WAAWD;AACzB,WAAO,OAAOA,GAAP,KAAe,UAAtB;AACD;;WAUeE,QAAQF;AACtB,WAAOG,KAAK,CAACD,OAAN,CAAcF,GAAd,CAAP;AACD;;WAUeI,YAAyCJ;AACvD,QAAMK,MAAM,GAAG,CAAC,CAACL,GAAF,IAASA,GAAG,CAAC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Ac,CAACE,CAAD,CAArB;AAAA,OAApB,CAAJ;AACD,KAFD,MAEO,IAAID,KAAJ,EAAW;AAAA,UACRE,UADQ,GACOF,KADP,CACRE,UADQ;;AAEhB,UAAIA,UAAJ,EAAgB;AACdA,QAAAA,UAAU,CAACC,WAAX,CAAuBH,KAAvB;AACD;AACF;AACF,GATM;;ACvFA,MAAMI,SAAS,GAAyB,SAAlCA,SAAkC;AAAA,WAAMC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAAN;AAAA,GAAxC;;AAEA,MAAMC,SAAS,GAA0C,SAAnDA,SAAmD,CAACC,IAAD;AAC9D,QAAMC,UAAU,GAAGL,SAAS,EAA5B;AACAK,IAAAA,UAAU,CAACC,SAAX,GAAuBF,IAAI,CAACG,IAAL,EAAvB;AAEA,WAAOrB,IAAI,CAACK,QAAQ,CAACc,UAAD,CAAT,EAAuB,UAACb,GAAD;AAAA,aAASG,cAAc,CAACH,GAAD,CAAvB;AAAA,KAAvB,CAAX;AACD,GALM;;ACIP,MAAMgB,GAAG,GAAG;AACVC,IAAAA,CAAC,EAAE,CADO;AAEVC,IAAAA,CAAC,EAAE,CAFO;AAGVC,IAAAA,CAAC,EAAE;AAHO,GAAZ;;cAMe,cAAA;QACLF,IAAYD,IAAZC;QAAGC,IAASF,IAATE;QAAGC,IAAMH,IAANG;AACd,WAAO,CACLR,SAAS,CACP;;;;;;;;;;;;;;;;;;;;;WADO,CADJ,EAyBLM,CAzBK,EA0BLC,CA1BK,EA2BLC,CA3BK,CAAP;AA6BD;;MAEYF,CAAC,GAAG;;;;"} \ No newline at end of file diff --git a/packages/overlayscrollbars/dist/overlayscrollbars.min.js b/packages/overlayscrollbars/dist/overlayscrollbars.min.js index e44fa07..d1a235d 100644 --- a/packages/overlayscrollbars/dist/overlayscrollbars.min.js +++ b/packages/overlayscrollbars/dist/overlayscrollbars.min.js @@ -1 +1 @@ -var OverlayScrollbars=function(r){"use strict";function s(r){var s=!!r&&r.length;return function(r){return Array.isArray(r)}(r)||!function(r){return"function"==typeof r}(r)&&function(r){return"number"==typeof r}(s)&&s>-1&&s%1==0}function o(r,i){if(s(r))for(var n=0;n
fdfhdfgh
'),r,s,o]},r}({}); \ No newline at end of file +var OverlayScrollbars=function(r){"use strict";function s(r){var s=!!r&&r.length;return function(r){return Array.isArray(r)}(r)||!function(r){return"function"==typeof r}(r)&&function(r){return"number"==typeof r}(s)&&s>-1&&s%1==0}function o(r,i){if(s(r))for(var n=0;n
fdfhdfgh
'),r,s,o]},r}({}); \ No newline at end of file diff --git a/packages/overlayscrollbars/src/core/dom/style.ts b/packages/overlayscrollbars/src/core/dom/style.ts index 4be18a5..1de467b 100644 --- a/packages/overlayscrollbars/src/core/dom/style.ts +++ b/packages/overlayscrollbars/src/core/dom/style.ts @@ -1,4 +1,4 @@ -import { keys } from 'core/utils/object'; +import { each, keys } from 'core/utils'; import { isString, isNumber, isUndefined } from 'core/utils/types'; type cssStyleObj = { [key: string]: string | number }; @@ -44,7 +44,7 @@ export function style(elm: HTMLElement, styles: string | cssStyleObj, val?: stri } setCSSVal(elm, styles, val); } else { - keys(styles).forEach((key) => setCSSVal(elm, key, styles[key])); + each(keys(styles), (key) => setCSSVal(elm, key, styles[key])); } } diff --git a/packages/overlayscrollbars/src/core/utils/extend.ts b/packages/overlayscrollbars/src/core/utils/extend.ts index 390bc89..a3ae067 100644 --- a/packages/overlayscrollbars/src/core/utils/extend.ts +++ b/packages/overlayscrollbars/src/core/utils/extend.ts @@ -1,5 +1,6 @@ import { isArray, isFunction, isPlainObject, isNull } from 'core/utils/types'; import { each } from 'core/utils/array'; +import { keys } from 'core/utils/object'; // https://github.com/jquery/jquery/blob/master/src/core.js#L116 export function extend(target: T, object1: U): T & U; @@ -14,9 +15,8 @@ export function extend( object3?: W, object4?: X, object5?: Y, - object6?: Z, + object6?: Z ): T & U & V & W & X & Y & Z { - /* eslint-disable no-restricted-syntax, guard-for-in */ const sources: Array = [object1, object2, object3, object4, object5, object6]; // Handle case when target is a string or something (possible in deep copy) @@ -25,44 +25,40 @@ export function extend( } each(sources, (source) => { - // Only deal with non-null/undefined values - if (source != null) { - // Extend the base object - for (const name in source) { - const copy: any = source[name]; + // Extend the base object + each(keys(source), (key) => { + const copy: any = source[key]; - // Prevent Object.prototype pollution - // Prevent never-ending loop - if (name === '__proto__' || target === copy) { - continue; - } - - const copyIsArray = isArray(copy); - - // Recurse if we're merging plain objects or arrays - if (copy && (isPlainObject(copy) || copyIsArray)) { - const src = target[name]; - let clone: any = src; - - // Ensure proper type for the source value - if (copyIsArray && !isArray(src)) { - clone = []; - } else if (!copyIsArray && !isPlainObject(src)) { - clone = {}; - } - - // Never move original objects, clone them - target[name] = extend(clone, copy) as any; - - // Don't bring in undefined values - } else if (copy !== undefined) { - target[name] = copy; - } + // Prevent Object.prototype pollution + // Prevent never-ending loop + if (target === copy) { + return true; } - } + + const copyIsArray = isArray(copy); + + // Recurse if we're merging plain objects or arrays + if (copy && (isPlainObject(copy) || copyIsArray)) { + const src = target[key]; + let clone: any = src; + + // Ensure proper type for the source value + if (copyIsArray && !isArray(src)) { + clone = []; + } else if (!copyIsArray && !isPlainObject(src)) { + clone = {}; + } + + // Never move original objects, clone them + target[key] = extend(clone, copy) as any; + + // Don't bring in undefined values + } else if (copy !== undefined) { + target[key] = copy; + } + }); }); // Return the modified object return target as any; - /* eslint-enable */ } diff --git a/packages/overlayscrollbars/src/core/utils/object.ts b/packages/overlayscrollbars/src/core/utils/object.ts index 7651d0b..fc9b170 100644 --- a/packages/overlayscrollbars/src/core/utils/object.ts +++ b/packages/overlayscrollbars/src/core/utils/object.ts @@ -10,4 +10,4 @@ export const hasOwnProperty: (obj: any, prop: string | number | symbol) => boole * Returns the names of the enumerable string properties and methods of an object. * @param obj The object of which the properties shall be returned. */ -export const keys: (obj: any) => Array = (obj: any) => Object.keys(obj); +export const keys: (obj: any) => Array = (obj: any) => (obj ? Object.keys(obj) : []); diff --git a/packages/overlayscrollbars/tests/core/utils/object.test.ts b/packages/overlayscrollbars/tests/core/utils/object.test.ts new file mode 100644 index 0000000..16019fc --- /dev/null +++ b/packages/overlayscrollbars/tests/core/utils/object.test.ts @@ -0,0 +1,31 @@ +import { keys, hasOwnProperty } from 'core/utils/object'; + +describe('object utilities', () => { + describe('keys', () => { + test('correct amount of keys', () => { + const obj = { + a: 1, + b: 2, + c: 3, + }; + expect(keys(obj)).toEqual(Object.keys(obj)); + }); + + test('empty array if object null or undefined', () => { + expect(keys(undefined)).toEqual([]); + expect(keys(null)).toEqual([]); + }); + }); + + test('hasOwnProperty', () => { + const obj = { + a: 1, + b: 2, + c: 3, + }; + expect(hasOwnProperty(obj, 'a')).toBe(true); + expect(hasOwnProperty(obj, 'b')).toBe(true); + expect(hasOwnProperty(obj, 'c')).toBe(true); + expect(hasOwnProperty(obj, 'd')).toBe(false); + }); +}); diff --git a/rollup.config.js b/rollup.config.js index 9563d1e..bc61315 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -53,6 +53,7 @@ export default async (config) => { src = './src', dist = './dist', types = './types', + tests = './tests', cache = [], minVersions = true, modules: { sourcemap: modulesSourceMap = true } = {}, @@ -64,6 +65,7 @@ export default async (config) => { const srcPath = path.resolve(projectPath, src); const distPath = path.resolve(projectPath, dist); const typesPath = path.resolve(projectPath, types); + const testsPath = path.resolve(projectPath, tests); const inputPath = path.resolve(projectPath, input); const mainOutputArray = [ @@ -101,7 +103,7 @@ export default async (config) => { }), ], })) - : [], + : [] ), external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies)], plugins: [ @@ -141,6 +143,7 @@ export default async (config) => { declaration: true, declarationDir: typesPath, }, + exclude: ((await import(tsconfigJSONPath)).exclude || []).concat(testsPath), }, }) : {}, diff --git a/tsconfig.base.json b/tsconfig.base.json index 5ccdda6..3cb15c0 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -13,5 +13,5 @@ "moduleResolution": "node", "removeComments": true }, - "exclude": ["tests", "**/tests/*", "node_modules", "**/node_modules/*"] + "exclude": ["node_modules", "**/node_modules/*"] }