mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Renamed getAsDictionary method of IMapStorage to the getStorageAsDictionary. Added tests.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
|
||||
|
||||
import { IFileData } from '../../interfaces/cli/IFileData';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
|
||||
import { TOptionsPreset } from '../../types/options/TOptionsPreset';
|
||||
import { TStringArrayIndexesType } from '../../types/options/TStringArrayIndexesType';
|
||||
import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
|
||||
import { IInitializable } from '../IInitializable';
|
||||
|
||||
export interface IObfuscationResult extends IInitializable <[string, string]> {
|
||||
|
||||
@@ -9,11 +9,6 @@ export interface IMapStorage <K, V> extends IInitializable {
|
||||
*/
|
||||
get (key: K): V | undefined;
|
||||
|
||||
/**
|
||||
* @returns {TDictionary<V>}
|
||||
*/
|
||||
getAsDictionary (): TDictionary<V>;
|
||||
|
||||
/**
|
||||
* @param {K} key
|
||||
* @returns {V}
|
||||
@@ -36,6 +31,11 @@ export interface IMapStorage <K, V> extends IInitializable {
|
||||
*/
|
||||
getStorage (): Map <K, V>;
|
||||
|
||||
/**
|
||||
* @returns {TDictionary<V>}
|
||||
*/
|
||||
getStorageAsDictionary (): TDictionary<V>;
|
||||
|
||||
/**
|
||||
* @returns string
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TIdentifierNamesCache } from '../../../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../../../types/storages/TIdentifierNamesCache';
|
||||
|
||||
import { IMapStorage } from '../IMapStorage';
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
ValidatorOptions
|
||||
} from 'class-validator';
|
||||
|
||||
import { TIdentifierNamesCache } from '../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../types/storages/TIdentifierNamesCache';
|
||||
import { TInputOptions } from '../types/options/TInputOptions';
|
||||
import { TOptionsPreset } from '../types/options/TOptionsPreset';
|
||||
import { TRenamePropertiesMode } from '../types/options/TRenamePropertiesMode';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
|
||||
|
||||
import { TIdentifierNamesCache } from '../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../types/storages/TIdentifierNamesCache';
|
||||
|
||||
import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
|
||||
import { IIdentifierNamesCacheStorage } from '../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
|
||||
|
||||
@@ -58,13 +58,6 @@ export abstract class MapStorage <K, V> implements IMapStorage <K, V> {
|
||||
return this.storage.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {TDictionary<V>}
|
||||
*/
|
||||
public getAsDictionary (): TDictionary<V> {
|
||||
return Object.fromEntries(this.storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {K} key
|
||||
* @returns {V}
|
||||
@@ -107,6 +100,13 @@ export abstract class MapStorage <K, V> implements IMapStorage <K, V> {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {TDictionary<V>}
|
||||
*/
|
||||
public getStorageAsDictionary (): TDictionary<V> {
|
||||
return Object.fromEntries(this.storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { inject, injectable, postConstruct } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
|
||||
|
||||
import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
|
||||
import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
|
||||
|
||||
import { IIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
@@ -82,6 +82,6 @@ export class IdentifierNamesCacheStorage extends MapStorage <string, string> imp
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getAsDictionary();
|
||||
return this.getStorageAsDictionary();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import { assert } from 'chai';
|
||||
|
||||
import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
|
||||
|
||||
import { TDictionary } from '../../../src/types/TDictionary';
|
||||
|
||||
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
|
||||
import { IMapStorage } from '../../../src/interfaces/storages/IMapStorage';
|
||||
import { IOptions } from '../../../src/interfaces/options/IOptions';
|
||||
@@ -212,6 +214,25 @@ describe('MapStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStorageAsDictionary', () => {
|
||||
const expectedDictionary: TDictionary<string> = {
|
||||
[storageKey]: storageValue
|
||||
};
|
||||
|
||||
let storageAsDictionary: TDictionary<string>;
|
||||
|
||||
before(() => {
|
||||
storage = getStorageInstance<string>();
|
||||
storage.set(storageKey, storageValue);
|
||||
|
||||
storageAsDictionary = storage.getStorageAsDictionary();
|
||||
});
|
||||
|
||||
it('should return storage as dictionary', () => {
|
||||
assert.deepEqual(storageAsDictionary, expectedDictionary);
|
||||
});
|
||||
});
|
||||
|
||||
describe('has', () => {
|
||||
describe('Variant #1: item is presenting in storage', () => {
|
||||
const expectedItemExistence: boolean = true;
|
||||
|
||||
Reference in New Issue
Block a user