node-opcua-enum
Advanced tools
Comparing version 2.64.1 to 2.66.0
@@ -52,2 +52,6 @@ /** | ||
} | ||
export interface _TypescriptEnum { | ||
[key: string | number]: number | string; | ||
} | ||
export declare function adaptTypescriptEnum(map: _TypescriptEnum | string[]): _TypescriptEnum; | ||
/** | ||
@@ -62,3 +66,3 @@ * @class Enum | ||
private readonly _isFlaggable; | ||
constructor(map: any); | ||
constructor(map: _TypescriptEnum | string[]); | ||
get isFlaggable(): boolean; | ||
@@ -71,3 +75,3 @@ /** | ||
*/ | ||
get(key: EnumItem | string | number): (EnumItem | null); | ||
get(key: EnumItem | string | number): EnumItem | null; | ||
getDefaultValue(): EnumItem; | ||
@@ -74,0 +78,0 @@ toString(): string; |
@@ -9,3 +9,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Enum = exports.EnumItem = void 0; | ||
exports.Enum = exports.adaptTypescriptEnum = exports.EnumItem = void 0; | ||
/** | ||
@@ -87,3 +87,3 @@ * Represents an Item of an Enum. | ||
function powerOfTwo(n) { | ||
return n && (!(n & (n - 1))) ? true : false; | ||
return n && !(n & (n - 1)) ? true : false; | ||
} | ||
@@ -97,3 +97,3 @@ // check if enum is flaggable | ||
} | ||
if ((value !== 0 && value !== 1) && !powerOfTwo(value)) { | ||
if (value !== 0 && value !== 1 && !powerOfTwo(value)) { | ||
return false; | ||
@@ -104,2 +104,15 @@ } | ||
} | ||
function adaptTypescriptEnum(map) { | ||
if (Array.isArray(map)) { | ||
let mm = null; | ||
// create map as flaggable enum | ||
mm = {}; | ||
for (let i = 0; i < map.length; i++) { | ||
mm[map[i]] = 1 << i; | ||
} | ||
return mm; | ||
} | ||
return map; | ||
} | ||
exports.adaptTypescriptEnum = adaptTypescriptEnum; | ||
/** | ||
@@ -117,7 +130,3 @@ * @class Enum | ||
if (Array.isArray(map)) { | ||
// create map as flaggable enum | ||
mm = {}; | ||
for (let i = 0; i < map.length; i++) { | ||
mm[map[i]] = 1 << i; | ||
} | ||
mm = adaptTypescriptEnum(map); | ||
isFlaggable = true; | ||
@@ -129,2 +138,5 @@ } | ||
for (const key of Object.keys(mm)) { | ||
if (typeof key !== "string") { | ||
continue; | ||
} | ||
const val = mm[key]; | ||
@@ -131,0 +143,0 @@ if (undefined === val) { |
@@ -0,0 +0,0 @@ /** |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
{ | ||
"name": "node-opcua-enum", | ||
"version": "2.64.1", | ||
"version": "2.66.0", | ||
"description": "pure nodejs OPCUA SDK - module -enum", | ||
@@ -8,3 +8,3 @@ "scripts": { | ||
"lint": "eslint source/**/*.ts", | ||
"clean": "node -e \"require('rimraf').sync('dist');\"", | ||
"clean": "npx rimraf dist *.tsbuildinfo", | ||
"test": "mocha" | ||
@@ -15,7 +15,7 @@ }, | ||
"dependencies": { | ||
"node-opcua-assert": "2.64.1" | ||
"node-opcua-assert": "2.66.0" | ||
}, | ||
"devDependencies": { | ||
"enum": "3.0.4", | ||
"node-opcua-benchmarker": "2.64.1", | ||
"node-opcua-benchmarker": "2.66.0", | ||
"should": "^13.2.3" | ||
@@ -38,3 +38,3 @@ }, | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "b65b8738603cd475d7d99a2b20b0ae9d32b4110c" | ||
"gitHead": "97f47e2e242a1fd737495fd64cb65e8fb7a9964b" | ||
} |
@@ -33,3 +33,3 @@ /** | ||
*/ | ||
public is(item: EnumItem|string|number): boolean { | ||
public is(item: EnumItem | string | number): boolean { | ||
if (item instanceof EnumItem) { | ||
@@ -90,5 +90,4 @@ return this.value === item.value; | ||
function powerOfTwo(n: number): boolean | ||
{ | ||
return n && (!(n & (n-1))) ? true: false; | ||
function powerOfTwo(n: number): boolean { | ||
return n && !(n & (n - 1)) ? true : false; | ||
} | ||
@@ -98,7 +97,7 @@ // check if enum is flaggable | ||
for (const e of enums) { | ||
const value = +e.value; | ||
const value = +e.value; | ||
if (isNaN(value)) { | ||
continue; // skipping none number value | ||
} | ||
if ((value !== 0 && value !==1) && !powerOfTwo(value)) { | ||
if (value !== 0 && value !== 1 && !powerOfTwo(value)) { | ||
return false; | ||
@@ -110,2 +109,19 @@ } | ||
export interface _TypescriptEnum { | ||
[key: string | number]: number | string; | ||
} | ||
export function adaptTypescriptEnum(map: _TypescriptEnum | string[]) { | ||
if (Array.isArray(map)) { | ||
let mm: _TypescriptEnum | null = null; | ||
// create map as flaggable enum | ||
mm = {}; | ||
for (let i = 0; i < map.length; i++) { | ||
mm[map[i]] = 1 << i; | ||
} | ||
return mm; | ||
} | ||
return map as _TypescriptEnum; | ||
} | ||
/** | ||
@@ -118,17 +134,11 @@ * @class Enum | ||
export class Enum { | ||
private readonly enumItems: EnumItem[]; | ||
private readonly _isFlaggable: boolean; | ||
constructor(map: any) { | ||
constructor(map: _TypescriptEnum | string[]) { | ||
this.enumItems = []; | ||
let mm: any = null; | ||
let mm: _TypescriptEnum | null = null; | ||
let isFlaggable = null; | ||
if (Array.isArray(map)) { | ||
// create map as flaggable enum | ||
mm = {}; | ||
for (let i = 0; i < map.length; i++) { | ||
mm[map[i]] = 1 << i; | ||
} | ||
mm = adaptTypescriptEnum(map); | ||
isFlaggable = true; | ||
@@ -140,3 +150,6 @@ } else { | ||
for (const key of Object.keys(mm)) { | ||
const val = mm[key]; | ||
if (typeof key !== "string") { | ||
continue; | ||
} | ||
const val = mm[key] as number; | ||
if (undefined === val) { | ||
@@ -159,3 +172,3 @@ continue; | ||
} | ||
public get isFlaggable(): boolean { | ||
@@ -170,4 +183,3 @@ return this._isFlaggable; | ||
*/ | ||
public get(key: EnumItem | string | number): (EnumItem | null) { | ||
public get(key: EnumItem | string | number): EnumItem | null { | ||
const pThis = this as any; | ||
@@ -205,4 +217,3 @@ if (key instanceof EnumItem) { | ||
private _getByString(key: string): (EnumItem | null) { | ||
private _getByString(key: string): EnumItem | null { | ||
const pThis = this as any; | ||
@@ -233,4 +244,3 @@ const parts = key.split(" | "); | ||
private _getByNum(key: number): (EnumItem | null) { | ||
private _getByNum(key: number): EnumItem | null { | ||
if (key === 0) { | ||
@@ -263,4 +273,2 @@ return null; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23954
588
+ Addednode-opcua-assert@2.66.0(transitive)
- Removednode-opcua-assert@2.64.1(transitive)
Updatednode-opcua-assert@2.66.0