improvements

This commit is contained in:
Rene
2020-07-25 14:26:22 +02:00
parent 4d58eb5e3a
commit f935a23185
15 changed files with 96 additions and 51 deletions
-1
View File
@@ -49,7 +49,6 @@ module.exports = {
'no-restricted-syntax': 'off', 'no-restricted-syntax': 'off',
'no-param-reassign': 'off', 'no-param-reassign': 'off',
'@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-types': 'off', '@typescript-eslint/ban-types': 'off',
'no-console': 'off', 'no-console': 'off',
+18 -2
View File
@@ -2,6 +2,22 @@
"printWidth": 150, "printWidth": 150,
"tabWidth": 2, "tabWidth": 2,
"singleQuote": true, "singleQuote": true,
"trailingComma": "all", "trailingComma": "es5",
"jsxBracketSameLine": true "jsxBracketSameLine": true,
"arrowParens": "always",
"endOfLine": "lf",
"overrides": [
{
"files": "*.vue",
"options": { "parser": "vue" }
},
{
"files": "*.component.html",
"options": { "parser": "angular" }
},
{
"files": ".prettierrc",
"options": { "parser": "json" }
}
]
} }
+1 -1
View File
@@ -9,6 +9,6 @@ module.exports = {
coverageDirectory: 'coverage', coverageDirectory: 'coverage',
moduleDirectories: resolve.directories, moduleDirectories: resolve.directories,
moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')), moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')),
testPathIgnorePatterns: ['\\\\node_modules\\\\', 'src/', 'dist/'], testPathIgnorePatterns: ['\\\\node_modules\\\\'],
verbose: true, verbose: true,
}; };
+1 -1
View File
@@ -15,7 +15,7 @@ function isArrayLike(obj) {
return isArray(obj) || !isFunction(obj) && isNumber(length) && length > -1 && length % 1 == 0; 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) { function each(source, callback) {
if (isArrayLike(source)) { if (isArrayLike(source)) {
File diff suppressed because one or more lines are too long
@@ -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;r<o.length&&!1!==c(o[r],r,o);r++);else o&&s((i=o,Object.keys(i)),r=>c(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(' <div class="os-host"> <div class="os-resize-observer-host"></div> <div class="os-padding"> <div class="os-viewport"> <div class="os-content"> fdfhdfgh </div> </div> </div> <div class="os-scrollbar os-scrollbar-horizontal"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar os-scrollbar-vertical"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar-corner"></div> </div>'),r,s,o]};export{e as a}; 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;r<o.length&&!1!==c(o[r],r,o);r++);else o&&s((i=o)?Object.keys(i):[],r=>c(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(' <div class="os-host"> <div class="os-resize-observer-host"></div> <div class="os-padding"> <div class="os-viewport"> <div class="os-content"> fdfhdfgh </div> </div> </div> <div class="os-scrollbar os-scrollbar-horizontal"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar os-scrollbar-vertical"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar-corner"></div> </div>'),r,s,o]};export{e as a};
+1 -1
View File
@@ -19,7 +19,7 @@ var OverlayScrollbars = function (exports) {
} }
var keys = function keys(obj) { var keys = function keys(obj) {
return Object.keys(obj); return obj ? Object.keys(obj) : [];
}; };
function each(source, callback) { function each(source, callback) {
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -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<r.length&&!1!==i(r[n],n,r);n++);else r&&o((a=r,Object.keys(a)),(function(s){return i(r[s],s,r)}));var a;return r}var i=function(r){var i,n=document.createElement("div");return n.innerHTML=r.trim(),o((i=n)?Array.from(i.childNodes):[],(function(r){return function r(i){if(s(i))o(Array.from(i),(function(s){return r(s)}));else if(i){var n=i.parentNode;n&&n.removeChild(i)}}(r)}))},n=1,a=1,e=1;return r.a=1,r.default=function(){var r=n,s=a,o=e;return[i(' <div class="os-host"> <div class="os-resize-observer-host"></div> <div class="os-padding"> <div class="os-viewport"> <div class="os-content"> fdfhdfgh </div> </div> </div> <div class="os-scrollbar os-scrollbar-horizontal"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar os-scrollbar-vertical"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar-corner"></div> </div>'),r,s,o]},r}({}); 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<r.length&&!1!==i(r[n],n,r);n++);else r&&o((a=r)?Object.keys(a):[],(function(s){return i(r[s],s,r)}));var a;return r}var i=function(r){var i,n=document.createElement("div");return n.innerHTML=r.trim(),o((i=n)?Array.from(i.childNodes):[],(function(r){return function r(i){if(s(i))o(Array.from(i),(function(s){return r(s)}));else if(i){var n=i.parentNode;n&&n.removeChild(i)}}(r)}))},n=1,a=1,e=1;return r.a=1,r.default=function(){var r=n,s=a,o=e;return[i(' <div class="os-host"> <div class="os-resize-observer-host"></div> <div class="os-padding"> <div class="os-viewport"> <div class="os-content"> fdfhdfgh </div> </div> </div> <div class="os-scrollbar os-scrollbar-horizontal"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar os-scrollbar-vertical"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar-corner"></div> </div>'),r,s,o]},r}({});
@@ -1,4 +1,4 @@
import { keys } from 'core/utils/object'; import { each, keys } from 'core/utils';
import { isString, isNumber, isUndefined } from 'core/utils/types'; import { isString, isNumber, isUndefined } from 'core/utils/types';
type cssStyleObj = { [key: string]: string | number }; type cssStyleObj = { [key: string]: string | number };
@@ -44,7 +44,7 @@ export function style(elm: HTMLElement, styles: string | cssStyleObj, val?: stri
} }
setCSSVal(elm, styles, val); setCSSVal(elm, styles, val);
} else { } else {
keys(styles).forEach((key) => setCSSVal(elm, key, styles[key])); each(keys(styles), (key) => setCSSVal(elm, key, styles[key]));
} }
} }
@@ -1,5 +1,6 @@
import { isArray, isFunction, isPlainObject, isNull } from 'core/utils/types'; import { isArray, isFunction, isPlainObject, isNull } from 'core/utils/types';
import { each } from 'core/utils/array'; import { each } from 'core/utils/array';
import { keys } from 'core/utils/object';
// https://github.com/jquery/jquery/blob/master/src/core.js#L116 // https://github.com/jquery/jquery/blob/master/src/core.js#L116
export function extend<T, U>(target: T, object1: U): T & U; export function extend<T, U>(target: T, object1: U): T & U;
@@ -14,9 +15,8 @@ export function extend<T, U, V, W, X, Y, Z>(
object3?: W, object3?: W,
object4?: X, object4?: X,
object5?: Y, object5?: Y,
object6?: Z, object6?: Z
): T & U & V & W & X & Y & Z { ): T & U & V & W & X & Y & Z {
/* eslint-disable no-restricted-syntax, guard-for-in */
const sources: Array<any> = [object1, object2, object3, object4, object5, object6]; const sources: Array<any> = [object1, object2, object3, object4, object5, object6];
// Handle case when target is a string or something (possible in deep copy) // Handle case when target is a string or something (possible in deep copy)
@@ -25,44 +25,40 @@ export function extend<T, U, V, W, X, Y, Z>(
} }
each(sources, (source) => { each(sources, (source) => {
// Only deal with non-null/undefined values // Extend the base object
if (source != null) { each(keys(source), (key) => {
// Extend the base object const copy: any = source[key];
for (const name in source) {
const copy: any = source[name];
// Prevent Object.prototype pollution // Prevent Object.prototype pollution
// Prevent never-ending loop // Prevent never-ending loop
if (name === '__proto__' || target === copy) { if (target === copy) {
continue; return true;
}
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;
}
} }
}
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 the modified object
return target as any; return target as any;
/* eslint-enable */
} }
@@ -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. * Returns the names of the enumerable string properties and methods of an object.
* @param obj The object of which the properties shall be returned. * @param obj The object of which the properties shall be returned.
*/ */
export const keys: (obj: any) => Array<string> = (obj: any) => Object.keys(obj); export const keys: (obj: any) => Array<string> = (obj: any) => (obj ? Object.keys(obj) : []);
@@ -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);
});
});
+4 -1
View File
@@ -53,6 +53,7 @@ export default async (config) => {
src = './src', src = './src',
dist = './dist', dist = './dist',
types = './types', types = './types',
tests = './tests',
cache = [], cache = [],
minVersions = true, minVersions = true,
modules: { sourcemap: modulesSourceMap = true } = {}, modules: { sourcemap: modulesSourceMap = true } = {},
@@ -64,6 +65,7 @@ export default async (config) => {
const srcPath = path.resolve(projectPath, src); const srcPath = path.resolve(projectPath, src);
const distPath = path.resolve(projectPath, dist); const distPath = path.resolve(projectPath, dist);
const typesPath = path.resolve(projectPath, types); const typesPath = path.resolve(projectPath, types);
const testsPath = path.resolve(projectPath, tests);
const inputPath = path.resolve(projectPath, input); const inputPath = path.resolve(projectPath, input);
const mainOutputArray = [ const mainOutputArray = [
@@ -101,7 +103,7 @@ export default async (config) => {
}), }),
], ],
})) }))
: [], : []
), ),
external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies)], external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies)],
plugins: [ plugins: [
@@ -141,6 +143,7 @@ export default async (config) => {
declaration: true, declaration: true,
declarationDir: typesPath, declarationDir: typesPath,
}, },
exclude: ((await import(tsconfigJSONPath)).exclude || []).concat(testsPath),
}, },
}) })
: {}, : {},
+1 -1
View File
@@ -13,5 +13,5 @@
"moduleResolution": "node", "moduleResolution": "node",
"removeComments": true "removeComments": true
}, },
"exclude": ["tests", "**/tests/*", "node_modules", "**/node_modules/*"] "exclude": ["node_modules", "**/node_modules/*"]
} }