MakeEnum moved to Utils class

This commit is contained in:
sanex
2020-10-11 14:45:33 +03:00
parent 5b05f953ba
commit abb7f1656f
21 changed files with 44 additions and 94 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -10
View File
@@ -52,16 +52,16 @@ and limitations under the License.
***************************************************************************** */
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,10 +1,10 @@
import { MakeEnum } from '../utils/TsEnum';
import { Utils } from '../utils/Utils';
export const ObfuscationTarget: Readonly<{
Browser: 'browser';
BrowserNoEval: 'browser-no-eval';
Node: 'node';
}> = MakeEnum({
}> = Utils.makeEnum({
Browser: 'browser',
BrowserNoEval: 'browser-no-eval',
Node: 'node'
@@ -1,11 +1,11 @@
import { MakeEnum } from '../../../utils/TsEnum';
import { Utils } from '../../../utils/Utils';
export const IdentifierNamesGenerator: Readonly<{
DictionaryIdentifierNamesGenerator: 'dictionary';
HexadecimalIdentifierNamesGenerator: 'hexadecimal';
MangledIdentifierNamesGenerator: 'mangled';
MangledShuffledIdentifierNamesGenerator: 'mangled-shuffled';
}> = MakeEnum({
}> = Utils.makeEnum({
DictionaryIdentifierNamesGenerator: 'dictionary',
HexadecimalIdentifierNamesGenerator: 'hexadecimal',
MangledIdentifierNamesGenerator: 'mangled',
@@ -1,10 +1,10 @@
import { MakeEnum } from '../../../utils/TsEnum';
import { Utils } from '../../../utils/Utils';
export const StringArrayEncoding: Readonly<{
None: 'none';
Base64: 'base64';
Rc4: 'rc4';
}> = MakeEnum({
}> = Utils.makeEnum({
None: 'none',
Base64: 'base64',
Rc4: 'rc4'
@@ -1,9 +1,9 @@
import { MakeEnum } from '../../../utils/TsEnum';
import { Utils } from '../../../utils/Utils';
export const StringArrayWrappersType: Readonly<{
Variable: 'variable';
Function: 'function';
}> = MakeEnum({
}> = Utils.makeEnum({
Variable: 'variable',
Function: 'function',
});
+2 -2
View File
@@ -1,11 +1,11 @@
import { MakeEnum } from '../../../utils/TsEnum';
import { Utils } from '../../../utils/Utils';
export const OptionsPreset: Readonly<{
Default: 'default';
LowObfuscation: 'low-obfuscation';
MediumObfuscation: 'medium-obfuscation';
HighObfuscation: 'high-obfuscation';
}> = MakeEnum({
}> = Utils.makeEnum({
Default: 'default',
LowObfuscation: 'low-obfuscation',
MediumObfuscation: 'medium-obfuscation',
+2 -2
View File
@@ -1,9 +1,9 @@
import { MakeEnum } from '../../utils/TsEnum';
import { Utils } from '../../utils/Utils';
export const SourceMapMode: Readonly<{
Inline: 'inline';
Separate: 'separate';
}> = MakeEnum({
}> = Utils.makeEnum({
Inline: 'inline',
Separate: 'separate'
});
+1 -1
View File
@@ -1,7 +1,7 @@
import { TOptionsPreset } from '../../types/options/TOptionsPreset';
import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
import { TStringArrayWrappersType } from '../../types/options/TStringArrayWrappersType';
import { TTypeFromEnum } from '../../types/utils/TTypeFromEnym';
import { TTypeFromEnum } from '../../types/utils/TTypeFromEnum';
import { IdentifierNamesGenerator } from '../../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
+1 -1
View File
@@ -22,7 +22,7 @@ import { TInputOptions } from '../types/options/TInputOptions';
import { TOptionsPreset } from '../types/options/TOptionsPreset';
import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
import { TStringArrayWrappersType } from '../types/options/TStringArrayWrappersType';
import { TTypeFromEnum } from '../types/utils/TTypeFromEnym';
import { TTypeFromEnum } from '../types/utils/TTypeFromEnum';
import { IOptions } from '../interfaces/options/IOptions';
import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
@@ -1,7 +1,7 @@
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
import equal from 'fast-deep-equal';
import { TTypeFromEnum } from '../../types/utils/TTypeFromEnym';
import { TTypeFromEnum } from '../../types/utils/TTypeFromEnum';
import { IOptions } from '../../interfaces/options/IOptions';
+1 -1
View File
@@ -1,4 +1,4 @@
import { TTypeFromEnum } from '../utils/TTypeFromEnym';
import { TTypeFromEnum } from '../utils/TTypeFromEnum';
import { OptionsPreset } from '../../enums/options/presets/OptionsPreset';
+1 -1
View File
@@ -1,4 +1,4 @@
import { TTypeFromEnum } from '../utils/TTypeFromEnym';
import { TTypeFromEnum } from '../utils/TTypeFromEnum';
import { StringArrayEncoding } from '../../enums/node-transformers/string-array-transformers/StringArrayEncoding';
@@ -1,4 +1,4 @@
import { TTypeFromEnum } from '../utils/TTypeFromEnym';
import { TTypeFromEnum } from '../utils/TTypeFromEnum';
import { StringArrayWrappersType } from '../../enums/node-transformers/string-array-transformers/StringArrayWrappersType';
-61
View File
@@ -1,61 +0,0 @@
/* eslint-disable no-redeclare */
/**
* https://github.com/gradecam/tsenum
*/
export function MakeEnum<T1 extends {[index: string]: U}, U extends string> (x1: T1): Readonly<T1>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2): Readonly<T1 & T2>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3): Readonly<T1 & T2 & T3>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, T4 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3, x4: T4): Readonly<T1 & T2 & T3 & T4>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, T4 extends {[index: string]: U}
, T5 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3, x4: T4, x5: T5): Readonly<T1 & T2 & T3 & T4 & T5>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, T4 extends {[index: string]: U}
, T5 extends {[index: string]: U}
, T6 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3, x4: T4, x5: T5, x6: T6): Readonly<T1 & T2 & T3 & T4 & T5 & T6>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, T4 extends {[index: string]: U}
, T5 extends {[index: string]: U}
, T6 extends {[index: string]: U}
, T7 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3, x4: T4, x5: T5, x6: T6, x7: T7): Readonly<T1 & T2 & T3 & T4 & T5 & T6 & T7>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, T4 extends {[index: string]: U}
, T5 extends {[index: string]: U}
, T6 extends {[index: string]: U}
, T7 extends {[index: string]: U}
, T8 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3, x4: T4, x5: T5, x6: T6, x7: T7, x8: T8): Readonly<T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8>;
export function MakeEnum<T1 extends {[index: string]: U}
, T2 extends {[index: string]: U}
, T3 extends {[index: string]: U}
, T4 extends {[index: string]: U}
, T5 extends {[index: string]: U}
, T6 extends {[index: string]: U}
, T7 extends {[index: string]: U}
, T8 extends {[index: string]: U}
, T9 extends {[index: string]: U}
, U extends string> (x1: T1, x2: T2, x3: T3, x4: T4, x5: T5, x6: T6, x7: T7, x8: T8, x9: T9): Readonly<T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9>;
export function MakeEnum<T extends {[index: string]: U}, U extends string> (...x: T[]): Readonly<T> {
return Object.freeze(Object.assign({}, ...x));
}
+11
View File
@@ -57,4 +57,15 @@ export class Utils {
return `${baseIdentifiersPrefix}${sourceCodeIndex}`;
}
/**
* @param {TObject} enumLikeObject
* @returns {Readonly<TObject>}
*/
public static makeEnum<
TObject extends {[index: string]: TValue},
TValue extends string
> (enumLikeObject: TObject): Readonly<TObject> {
return Object.freeze({...enumLikeObject});
}
}
@@ -3,7 +3,7 @@ import { assert } from 'chai';
import { TDictionary } from '../../../src/types/TDictionary';
import { TInputOptions } from '../../../src/types/options/TInputOptions';
import { TOptionsPreset } from '../../../src/types/options/TOptionsPreset';
import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnym';
import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnum';
import { IObfuscatedCode } from '../../../src/interfaces/source-code/IObfuscatedCode';
@@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
import { assert } from 'chai';
import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnym';
import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnum';
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
import { IObfuscatedCode } from '../../../src/interfaces/source-code/IObfuscatedCode';