haraka-constants
Advanced tools
Comparing version 1.0.6 to 1.0.7
94
index.js
@@ -1,63 +0,63 @@ | ||
'use strict'; | ||
'use strict' | ||
// node.js class | ||
const node_const = require('constants'); | ||
const node_const = require('node:constants') | ||
const translationTable = {}; | ||
const translationTable = {} | ||
exports.cont = 900; | ||
exports.stop = 901; | ||
exports.deny = 902; | ||
exports.denysoft = 903; | ||
exports.denydisconnect = 904; | ||
exports.disconnect = 905; | ||
exports.ok = 906; | ||
exports.next_hook = 907; | ||
exports.delay = 908; | ||
exports.denysoftdisconnect = 909; | ||
exports.write_excl = node_const.O_CREAT | node_const.O_TRUNC | node_const.O_WRONLY | node_const.O_EXCL; | ||
exports.cont = 900 | ||
exports.stop = 901 | ||
exports.deny = 902 | ||
exports.denysoft = 903 | ||
exports.denydisconnect = 904 | ||
exports.disconnect = 905 | ||
exports.ok = 906 | ||
exports.next_hook = 907 | ||
exports.delay = 908 | ||
exports.denysoftdisconnect = 909 | ||
exports.write_excl = | ||
node_const.O_CREAT | | ||
node_const.O_TRUNC | | ||
node_const.O_WRONLY | | ||
node_const.O_EXCL | ||
exports.import = function (object) { | ||
for (const k in exports) { | ||
if (k === 'import') continue; | ||
if (k === 'translate') continue; | ||
if (k === 'connection') continue; | ||
if (Object.prototype.hasOwnProperty.call(exports, k)) { | ||
object[k.toUpperCase()] = exports[k]; | ||
} | ||
for (const k in exports) { | ||
if (['import', 'translate', 'connection'].includes(k)) continue | ||
if (Object.prototype.hasOwnProperty.call(exports, k)) { | ||
object[k.toUpperCase()] = exports[k] | ||
} | ||
}; | ||
} | ||
} | ||
exports.translate = function (value) { | ||
// cache the translationTable object | ||
if (Object.keys(translationTable).length === 0) { | ||
for (const k in exports) { | ||
if (typeof exports[k] === 'number') { | ||
translationTable[exports[k]] = k.toUpperCase(); | ||
} | ||
} | ||
// cache the translationTable object | ||
if (Object.keys(translationTable).length === 0) { | ||
for (const k in exports) { | ||
if (typeof exports[k] === 'number') { | ||
translationTable[exports[k]] = k.toUpperCase() | ||
} | ||
} | ||
} | ||
if (translationTable[value]) return translationTable[value]; | ||
return 'UNKNOWN'; | ||
}; | ||
return translationTable[value] || 'UNKNOWN' | ||
} | ||
exports.import(exports); | ||
exports.import(exports) | ||
exports.connection = { | ||
state: { | ||
CMD: 1, | ||
LOOP: 2, | ||
DATA: 3, | ||
PAUSE: 4, | ||
PAUSE_SMTP: 5, | ||
PAUSE_DATA: 6, | ||
DISCONNECTING: 99, | ||
DISCONNECTED: 100, | ||
} | ||
state: { | ||
CMD: 1, | ||
LOOP: 2, | ||
DATA: 3, | ||
PAUSE: 4, | ||
PAUSE_SMTP: 5, | ||
PAUSE_DATA: 6, | ||
DISCONNECTING: 99, | ||
DISCONNECTED: 100, | ||
}, | ||
} | ||
Object.keys(exports.connection.state).forEach((state) => { | ||
exports.connection.state[`STATE_${state}`] = exports.connection.state[state]; | ||
}) | ||
for (const state of Object.keys(exports.connection.state)) { | ||
exports.connection.state[`STATE_${state}`] = exports.connection.state[state] | ||
} |
@@ -6,3 +6,3 @@ { | ||
"description": "Haraka constants", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"homepage": "http://haraka.github.io", | ||
@@ -14,2 +14,5 @@ "repository": { | ||
"main": "index.js", | ||
"files": [ | ||
"CHANGELOG.md" | ||
], | ||
"engines": { | ||
@@ -21,5 +24,3 @@ "node": ">= 6" | ||
"devDependencies": { | ||
"eslint": ">=8", | ||
"eslint-plugin-haraka": ">=1.0.10", | ||
"mocha": "*" | ||
"@haraka/eslint-config": "^1.1.5" | ||
}, | ||
@@ -31,6 +32,11 @@ "bugs": { | ||
"scripts": { | ||
"lint": "npx eslint *.js test", | ||
"lintfix": "npx eslint --fix *.js test", | ||
"test": "npx mocha" | ||
"format": "npm run prettier:fix && npm run lint:fix", | ||
"lint": "npx eslint@^8 *.js test", | ||
"lint:fix": "npx eslint@^8 *.js test --fix", | ||
"prettier": "npx prettier . --check", | ||
"prettier:fix": "npx prettier . --write --log-level=warn", | ||
"test": "npx mocha@10", | ||
"versions": "npx dependency-version-checker check", | ||
"versions:fix": "npx dependency-version-checker update && npm run prettier:fix" | ||
} | ||
} |
@@ -29,5 +29,5 @@ [![Build Status][ci-img]][ci-url] | ||
```js | ||
const constants = require('haraka-constants'); | ||
const myObj = {}; | ||
constants.import(myObj); | ||
const constants = require('haraka-constants') | ||
const myObj = {} | ||
constants.import(myObj) | ||
@@ -42,7 +42,6 @@ // myObj.cont === 900 | ||
```js | ||
const constants = require('haraka-constants'); | ||
const constants = require('haraka-constants') | ||
// 'CONT' === constants.translate(900); | ||
``` | ||
[ci-img]: https://github.com/haraka/haraka-constants/actions/workflows/ci.yml/badge.svg | ||
@@ -56,2 +55,1 @@ [ci-url]: https://github.com/haraka/haraka-constants/actions/workflows/ci.yml | ||
[npm-url]: https://www.npmjs.com/package/haraka-constants | ||
1
5218
5
54
53