Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-enum

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-enum - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

6

package.json
{
"name": "node-opcua-enum",
"version": "0.2.3",
"version": "0.3.0",
"description": "pure nodejs OPCUA SDK - module -enum",

@@ -10,7 +10,7 @@ "scripts": {

"dependencies": {
"node-opcua-assert": "^0.2.0"
"node-opcua-assert": "^0.3.0"
},
"devDependencies": {
"enum": "^2.5.0",
"node-opcua-benchmarker": "^0.2.0",
"node-opcua-benchmarker": "^0.3.0",
"should": "13.2.1",

@@ -17,0 +17,0 @@ "underscore": "^1.8.3"

@@ -14,3 +14,3 @@ "use strict";

*/
var EnumItem = function (key, value) {
const EnumItem = function (key, value) {
this.key = key;

@@ -83,5 +83,5 @@ this.value = value;

// check if enum is flaggable
var check_is_flaggable = function (enums) {
for (var i in enums) {
var e = enums[i];
const check_is_flaggable = function (enums) {
for (const i in enums) {
const e = enums[i];
if (!(e.value !== 0 && !(e.value & e.value - 1))) {

@@ -99,12 +99,12 @@ return false;

*/
var Enum = function (map) {
var self = this;
const Enum = function (map) {
const self = this;
self.enums = [];
var mm = null;
let mm = null;
var is_flaggable = null;
let is_flaggable = null;
if (Array.isArray(map)) {
// create map as flaggable enum
mm = {};
for (var i = 0; i < map.length; i++) {
for (let i = 0; i < map.length; i++) {
mm[map[i]] = 1 << i;

@@ -117,6 +117,6 @@ }

for (var key in mm) {
var val = mm[key];
for (const key in mm) {
const val = mm[key];
if (undefined === val) { continue; }
var kv = new EnumItem(key, val);
const kv = new EnumItem(key, val);
self[key] = kv;

@@ -150,3 +150,3 @@ self[val] = kv;

}
var prop = this[key];
const prop = this[key];
if (prop) {

@@ -165,8 +165,8 @@ return prop;

var parts = key.split(' | ');
const parts = key.split(' | ');
var val = 0;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
var item = this[part];
let val = 0;
for (let i = 0; i < parts.length; i++) {
const part = parts[i];
const item = this[part];
if (undefined === item) {

@@ -177,6 +177,6 @@ return undefined;

}
var kv = new EnumItem(key, val);
const kv = new EnumItem(key, val);
// add in cache for later
var prop = this[val];
let prop = this[val];
if (prop === undefined) {

@@ -196,5 +196,5 @@ this[val] = kv;

var name;
var c = 1, item;
for (var i = 0; c < key; i++) {
let name;
let c = 1, item;
for (let i = 0; c < key; i++) {
if ((c & key) === c) {

@@ -213,3 +213,3 @@ item = this[c];

}
var kv = new EnumItem(name, key);
const kv = new EnumItem(name, key);
// add in cache for later

@@ -216,0 +216,0 @@ this[name] = kv;

"use strict";
var Enum = require("..");
var should = require("should");
var _ = require("underscore");
const Enum = require("..");
const should = require("should");
const _ = require("underscore");

@@ -10,3 +10,3 @@ describe("Test Enum", function () {

it("should create flaggable enum from string array", function () {
var e = new Enum(["e1", "e2", "e3"]);
const e = new Enum(["e1", "e2", "e3"]);
e.get("e1").value.should.equal(1);

@@ -23,3 +23,3 @@ e.get("e2").value.should.equal(2);

it("should create flaggable enum from flaggable map", function () {
var e = new Enum({"e1": 1, "e2": 2, "e3": 4});
const e = new Enum({"e1": 1, "e2": 2, "e3": 4});
e.get("e1").value.should.equal(1);

@@ -36,3 +36,3 @@ e.get("e2").value.should.equal(2);

it("should create non-flaggable enum from non-flaggable map", function () {
var e = new Enum({"e1": 1, "e2": 2, "e3": 3});
const e = new Enum({"e1": 1, "e2": 2, "e3": 3});
e.get("e1").value.should.equal(1);

@@ -50,3 +50,3 @@ e.get("e2").value.should.equal(2);

it("should access enum from enum item name", function () {
var e = new Enum({"e1": 1, "e2": 2, "e3": 4});
const e = new Enum({"e1": 1, "e2": 2, "e3": 4});
e.e1.value.should.equal(1);

@@ -61,4 +61,4 @@ e.e1.key.should.equal("e1");

it("EnumItem should function properly", function () {
var e = new Enum({"e1": 1, "e2": 2, "e3": 4});
var e1ore2 = e.get("e2 | e1");
const e = new Enum({"e1": 1, "e2": 2, "e3": 4});
const e1ore2 = e.get("e2 | e1");
e1ore2.value.should.equal(3);

@@ -90,7 +90,7 @@ e1ore2.is(e.get(3)).should.equal(true);

var Benchmarker = require("node-opcua-benchmarker").Benchmarker;
const Benchmarker = require("node-opcua-benchmarker").Benchmarker;
var EnumSlow = require("enum");
var EnumFast = require("..");
const EnumSlow = require("enum");
const EnumFast = require("..");

@@ -102,11 +102,11 @@ describe("Benchmarking Enums", function () {

var bench = new Benchmarker();
const bench = new Benchmarker();
var keys = _.isArray(params) ? params : Object.keys(params);
const keys = _.isArray(params) ? params : Object.keys(params);
function test_iteration(en) {
var e1 = en.SOMEDATA;
const e1 = en.SOMEDATA;
should.not.exist(e1);
var e2 = en.get("OTHERDATA");
const e2 = en.get("OTHERDATA");
should.not.exist(e2);

@@ -116,3 +116,3 @@

var item = en[keys[0]];
const item = en[keys[0]];
en.get(item).value.should.eql(item.value);

@@ -129,3 +129,3 @@

var en = new EnumSlow(params);
const en = new EnumSlow(params);
test_iteration(en);

@@ -136,3 +136,3 @@

var en = new EnumFast(params);
const en = new EnumFast(params);
test_iteration(en);

@@ -161,3 +161,3 @@ })

var AccessLevelFlag = {
const AccessLevelFlag = {
CurrentRead: 0x01,

@@ -170,3 +170,3 @@ CurrentWrite: 0x02,

var checks = [
const checks = [
{key: "CurrentWrite | HistoryWrite", value: 0x0A},

@@ -185,3 +185,3 @@ {key: "HistoryWrite | CurrentWrite", value: 0x0A},

it("should verify that our enums are faster than Enum 2.1.0 ( simple enum )", function (done) {
var ApplicationType = {
const ApplicationType = {
SERVER: 0, // The application is a Server

@@ -192,3 +192,3 @@ CLIENT: 1, // The application is a Client

};
var checks = [
const checks = [
{key: "SERVER", value: 0},

@@ -195,0 +195,0 @@ {key: "CLIENT", value: 1},

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc