Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate project to eslint #360

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"root": true,
"env": {
"es2020": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:security/recommended",
"plugin:sonarjs/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "security", "sonarjs"],
"rules": {
"max-len": [
"error",
{
"code": 80,
"ignoreComments": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}
],
"no-constant-condition": "off",
"no-empty": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"security/detect-object-injection": "off",
"sonarjs/cognitive-complexity": "off",
"sonarjs/no-duplicate-string": "off"
}
}
30 changes: 14 additions & 16 deletions cdn/radash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const isPromise = (value) => {
return false;
if (!value.then)
return false;
if (!isFunction(value.then))
return false;
return true;
return isFunction(value.then);
};
const isEmpty = (value) => {
if (value === true || value === false)
Expand Down Expand Up @@ -132,7 +130,7 @@ const sort = (array, getter, desc = false) => {
return [];
const asc = (a, b) => getter(a) - getter(b);
const dsc = (a, b) => getter(b) - getter(a);
return array.slice().sort(desc === true ? dsc : asc);
return array.slice().sort(desc ? dsc : asc);
};
const alphabetical = (array, getter, dir = "asc") => {
if (!array)
Expand Down Expand Up @@ -351,7 +349,7 @@ const reduce = async (array, asyncReducer, initValue) => {
const map = async (array, asyncMapFunc) => {
if (!array)
return [];
let result = [];
const result = [];
let index = 0;
for (const value of array) {
const newValue = await asyncMapFunc(value, index++);
Expand Down Expand Up @@ -699,7 +697,7 @@ const omit = (obj, keys2) => {
);
};
const get = (value, path, defaultValue) => {
const segments = path.split(/[\.\[\]]/g);
const segments = path.split(/[.[\]]/g);
let current = value;
for (const key of segments) {
if (current === null)
Expand All @@ -719,11 +717,11 @@ const set = (initial, path, value) => {
return {};
if (!path || value === void 0)
return initial;
const segments = path.split(/[\.\[\]]/g).filter((x) => !!x.trim());
const segments = path.split(/[.[\]]/g).filter((x) => !!x.trim());
const _set = (node) => {
if (segments.length > 1) {
const key = segments.shift();
const nextIsNum = toInt(segments[0], null) === null ? false : true;
const nextIsNum = toInt(segments[0], null) !== null;
node[key] = node[key] === void 0 ? nextIsNum ? [] : {} : node[key];
_set(node[key]);
} else {
Expand Down Expand Up @@ -872,7 +870,7 @@ const capitalize = (str) => {
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
};
const camel = (str) => {
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
if (parts.length === 1)
Expand All @@ -882,18 +880,18 @@ const camel = (str) => {
});
};
const snake = (str, options) => {
const parts = str?.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
if (parts.length === 1)
return parts[0];
const result = parts.reduce((acc, part) => {
return `${acc}_${part.toLowerCase()}`;
});
return options?.splitOnNumber === false ? result : result.replace(/([A-Za-z]{1}[0-9]{1})/, (val) => `${val[0]}_${val[1]}`);
return options?.splitOnNumber === false ? result : result.replace(/([A-Za-z][0-9])/, (val) => `${val[0]}_${val[1]}`);
};
const dash = (str) => {
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
if (parts.length === 1)
Expand All @@ -903,25 +901,25 @@ const dash = (str) => {
});
};
const pascal = (str) => {
const parts = str?.split(/[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.split(/[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
return parts.map((str2) => str2.charAt(0).toUpperCase() + str2.slice(1)).join("");
};
const title = (str) => {
if (!str)
return "";
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
return str.split(/(?=[A-Z])|[.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
};
const template = (str, data, regex = /\{\{(.+?)\}\}/g) => {
const template = (str, data, regex = /\{\{(.+?)}}/g) => {
return Array.from(str.matchAll(regex)).reduce((acc, match) => {
return acc.replace(match[0], data[match[1]]);
}, str);
};
const trim = (str, charsToTrim = " ") => {
if (!str)
return "";
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
const toTrim = charsToTrim.replace(/\W/g, "\\$&");
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
return str.replace(regex, "");
};
Expand Down
30 changes: 14 additions & 16 deletions cdn/radash.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ var radash = (function (exports) {
return false;
if (!value.then)
return false;
if (!isFunction(value.then))
return false;
return true;
return isFunction(value.then);
};
const isEmpty = (value) => {
if (value === true || value === false)
Expand Down Expand Up @@ -135,7 +133,7 @@ var radash = (function (exports) {
return [];
const asc = (a, b) => getter(a) - getter(b);
const dsc = (a, b) => getter(b) - getter(a);
return array.slice().sort(desc === true ? dsc : asc);
return array.slice().sort(desc ? dsc : asc);
};
const alphabetical = (array, getter, dir = "asc") => {
if (!array)
Expand Down Expand Up @@ -354,7 +352,7 @@ var radash = (function (exports) {
const map = async (array, asyncMapFunc) => {
if (!array)
return [];
let result = [];
const result = [];
let index = 0;
for (const value of array) {
const newValue = await asyncMapFunc(value, index++);
Expand Down Expand Up @@ -702,7 +700,7 @@ var radash = (function (exports) {
);
};
const get = (value, path, defaultValue) => {
const segments = path.split(/[\.\[\]]/g);
const segments = path.split(/[.[\]]/g);
let current = value;
for (const key of segments) {
if (current === null)
Expand All @@ -722,11 +720,11 @@ var radash = (function (exports) {
return {};
if (!path || value === void 0)
return initial;
const segments = path.split(/[\.\[\]]/g).filter((x) => !!x.trim());
const segments = path.split(/[.[\]]/g).filter((x) => !!x.trim());
const _set = (node) => {
if (segments.length > 1) {
const key = segments.shift();
const nextIsNum = toInt(segments[0], null) === null ? false : true;
const nextIsNum = toInt(segments[0], null) !== null;
node[key] = node[key] === void 0 ? nextIsNum ? [] : {} : node[key];
_set(node[key]);
} else {
Expand Down Expand Up @@ -875,7 +873,7 @@ var radash = (function (exports) {
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
};
const camel = (str) => {
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
if (parts.length === 1)
Expand All @@ -885,18 +883,18 @@ var radash = (function (exports) {
});
};
const snake = (str, options) => {
const parts = str?.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
if (parts.length === 1)
return parts[0];
const result = parts.reduce((acc, part) => {
return `${acc}_${part.toLowerCase()}`;
});
return options?.splitOnNumber === false ? result : result.replace(/([A-Za-z]{1}[0-9]{1})/, (val) => `${val[0]}_${val[1]}`);
return options?.splitOnNumber === false ? result : result.replace(/([A-Za-z][0-9])/, (val) => `${val[0]}_${val[1]}`);
};
const dash = (str) => {
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
if (parts.length === 1)
Expand All @@ -906,25 +904,25 @@ var radash = (function (exports) {
});
};
const pascal = (str) => {
const parts = str?.split(/[\.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
const parts = str?.split(/[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
if (parts.length === 0)
return "";
return parts.map((str2) => str2.charAt(0).toUpperCase() + str2.slice(1)).join("");
};
const title = (str) => {
if (!str)
return "";
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
return str.split(/(?=[A-Z])|[.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
};
const template = (str, data, regex = /\{\{(.+?)\}\}/g) => {
const template = (str, data, regex = /\{\{(.+?)}}/g) => {
return Array.from(str.matchAll(regex)).reduce((acc, match) => {
return acc.replace(match[0], data[match[1]]);
}, str);
};
const trim = (str, charsToTrim = " ") => {
if (!str)
return "";
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
const toTrim = charsToTrim.replace(/\W/g, "\\$&");
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
return str.replace(regex, "");
};
Expand Down
Loading