Skip to content

Commit

Permalink
feat: updates deps (& fixes Axios vulnerability), updates eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Aug 15, 2024
1 parent ecca549 commit ba49770
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 481 deletions.
17 changes: 0 additions & 17 deletions .eslintrc.cjs

This file was deleted.

23 changes: 23 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked, {
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname
}
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off'
}
});
2 changes: 1 addition & 1 deletion lib/elements/element-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ElementModels } from './element-models';

export type ElementResolver = (element: ElementModels.IElementWrapper) => any | undefined;
export type ElementResolver = (element: ElementModels.IElementWrapper) => any;
2 changes: 1 addition & 1 deletion lib/mappers/type.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class TypeMapper {
const typeElement = type.elements[elementName];

if (!typeElement) {
throw Error(`Cannot find element '${elementName}' on type '${type}'`);
throw Error(`Cannot find element '${elementName}' on type '${type.system.codename}'`);
}

// use json property as a codename of the type element
Expand Down
2 changes: 1 addition & 1 deletion lib/parser/implementation/async-browser-parser.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AsyncBrowserParser implements IAsyncParser<string> {
for (let i = 0; i < htmlCollection.length; i++) {
const element = htmlCollection[i];

resolvers.elementResolverAsync(parserHelper.convertToParserElement(element));
await resolvers.elementResolverAsync(parserHelper.convertToParserElement(element));

const typeAttribute = element.attributes ? element.attributes.getNamedItem('type') : undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { textHelper } from '../../utilities';
import { PropertyNameResolver } from '../../models';

export const camelCasePropertyNameResolver: PropertyNameResolver = (contentType, element) => {
return textHelper.addUnderscoreWhenStarsWithNumber(textHelper.removeZeroWidthCharacters(camelize(element)));
return textHelper.addUnderscoreWhenStarsWithNumber(textHelper.removeZeroWidthCharacters(toCamelCase(element)));
};

function camelize(str: string): string {
str = str.replace(textHelper.getPropertyNameRegex(), (_, c) => (c ? c.toUpperCase() : ''));
function toCamelCase(str: string): string {
str = str.replace(textHelper.getPropertyNameRegex(), (_, c: string) => (c ? c.toUpperCase() : ''));
return str.substring(0, 1).toLowerCase() + str.substring(1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { textHelper } from '../../utilities';
import { PropertyNameResolver } from '../../models';

export const pascalCasePropertyNameResolver: PropertyNameResolver = (contentType, element) => {
return textHelper.addUnderscoreWhenStarsWithNumber(textHelper.removeZeroWidthCharacters(camelize(element)));
return textHelper.addUnderscoreWhenStarsWithNumber(textHelper.removeZeroWidthCharacters(toPascalCase(element)));
};

function camelize(str: string): string {
str = str.replace(textHelper.getPropertyNameRegex(), (_, c) => (c ? c.toUpperCase() : ''));
function toPascalCase(str: string): string {
str = str.replace(textHelper.getPropertyNameRegex(), (_, c: string) => (c ? c.toUpperCase() : ''));
return str.substring(0, 1).toUpperCase() + str.substring(1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const snakeCasePropertyNameResolver: PropertyNameResolver = (contentType,
};

function toSnakeCase(str: string): string {
str = str.replace(textHelper.getPropertyNameRegex(), (_, c) => '_' + (c ? c.toLowerCase() : ''));
str = str.replace(textHelper.getPropertyNameRegex(), (_, c: string) => '_' + (c ? c.toLowerCase() : ''));
return removeEndUnderscore(removeStartUnderscore(str));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/services/base-delivery-query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export abstract class BaseDeliveryQueryService {
};
}

private mapDeliveryError(error: any): DeliveryError | any {
private mapDeliveryError(error: any): any {
let axiosError: AxiosError | undefined;

if (error.error) {
Expand Down
28 changes: 2 additions & 26 deletions lib/utilities/enum.helper.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
export class EnumHelper {
getAllNames(T: any): any[] {
const enumNames: any[] = [];

for (const key in T) {
if (T.hasOwnProperty(key)) {
enumNames.push(key);
}
}

return enumNames;
}

getAllValues(T: any): any[] {
const allEnumValues: any[] = Object.keys(T).map((key) => T[key]);

getAllValues(T: any): string[] {
const allEnumValues: string[] = Object.keys(T).map((key) => T[key]);
return allEnumValues;
}

Expand Down Expand Up @@ -43,17 +30,6 @@ export class EnumHelper {
}
}

getEnumFromName<T>(T: any, name: string): T | undefined {
const allNames = this.getAllNames(T);

for (const enumName of allNames) {
if (enumName.toLowerCase() === name.toLowerCase()) {
return T[enumName];
}
}
return undefined;
}

private isNumeric(value: any): boolean {
return !isNaN(parseFloat(value)) && isFinite(value);
}
Expand Down
Loading

0 comments on commit ba49770

Please sign in to comment.