-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updates deps, migrates to eslint, adds migrate related code fixes
- Loading branch information
Showing
8 changed files
with
2,714 additions
and
9,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./tsconfig.json'] | ||
}, | ||
rules: { | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-unused-vars': 'off', | ||
'@typescript-eslint/no-namespace': 'off' | ||
}, | ||
root: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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]); | ||
|
||
return allEnumValues; | ||
} | ||
|
||
getEnumFromValue<T>(T: any, value: string | number): T | undefined { | ||
try { | ||
if (!value) { | ||
return undefined; | ||
} | ||
|
||
// we can map back from index number directly | ||
if (this.isNumeric(value)) { | ||
return <T>T[value]; | ||
} | ||
|
||
// for strings, we need to compare each value separately | ||
const allEnumValues = this.getAllValues(T); | ||
|
||
const result = allEnumValues.find((m) => m.toLowerCase() === value.toString().toLowerCase()); | ||
|
||
if (!result) { | ||
return undefined; | ||
} | ||
|
||
return result as T; | ||
} catch (err) { | ||
return undefined; | ||
} | ||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
export const enumHelper = new EnumHelper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './linked-items.helper'; | ||
export * from './guid.helper'; | ||
export * from './delivery-url.helper'; | ||
export * from './text-helper'; | ||
export * from './text.helper'; | ||
export * from './enum.helper'; |
File renamed without changes.
Oops, something went wrong.