diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 7e74a5f..7be5db7 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -2,26 +2,6 @@ env: node: true es6: true mocha: true - es2020: true + es2023: true -plugins: - - haraka - -extends: - - eslint:recommended - - plugin:haraka/recommended - -root: true - -globals: - OK: true - CONT: true - DENY: true - DENYSOFT: true - DENYDISCONNECT: true - DENYSOFTDISCONNECT: true - -rules: - indent: [2, 4, { SwitchCase: 1 } ] - console: 0 - no-console: 0 \ No newline at end of file +extends: ['@haraka'] diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index afafec5..bd8fb43 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,12 @@ Fixes # Changes proposed in this pull request: -- -- + +- +- Checklist: + - [ ] docs updated - [ ] tests updated - [ ] Changes.md updated diff --git a/.github/dependabot.yml b/.github/dependabot.yml index feb90ba..c9826f9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,7 @@ version: 2 updates: - - package-ecosystem: "npm" - directory: "/" # Location of package manifests + - package-ecosystem: 'npm' + directory: '/' # Location of package manifests schedule: - interval: "weekly" + interval: 'weekly' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a03c787..435be73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,9 @@ jobs: secrets: inherit test: - needs: [ lint ] + needs: [lint] uses: haraka/.github/.github/workflows/ubuntu.yml@master windows: - needs: [ lint ] + needs: [lint] uses: haraka/.github/.github/workflows/windows.yml@master diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3627451..8314a66 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,10 +2,10 @@ name: CodeQL on: push: - branches: [ master ] + branches: [master] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [master] schedule: - cron: '18 7 * * 4' diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a8e94cb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".release"] + path = .release + url = git@github.com:msimerson/.release.git diff --git a/.npmignore b/.npmignore deleted file mode 100644 index a8ae795..0000000 --- a/.npmignore +++ /dev/null @@ -1,11 +0,0 @@ -.github -.DS_Store -.editorconfig -.gitignore -.gitmodules -.lgtm.yml -appveyor.yml -codecov.yml -.travis.yml -.eslintrc.yaml -.eslintrc.json diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..8ded5e0 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1,2 @@ +singleQuote: true +semi: false diff --git a/.release b/.release new file mode 160000 index 0000000..7cd5707 --- /dev/null +++ b/.release @@ -0,0 +1 @@ +Subproject commit 7cd5707f7d69f8d4dca1ec407ada911890e59d0a diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2227e4c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,44 @@ +# Changelog + +The format is based on [Keep a Changelog](https://keepachangelog.com/). + +### Unreleased + +### [1.0.7] - 2024-04-08 + +- use `[files]` in package.json. Delete .npmignore. +- doc: Changes -> CHANGELOG +- ci: more shared workflows +- lint: remove duplicate / stale rules from .eslintrc + +### [1.0.6] - 2022-05-27 + +- chore(ci): depend on shared GHA workflows + +### 1.0.5 - 2022-01-26 + +- feat: make it possible to set a false value +- chore(ci): bump lowest node.js version to 14 + +### [1.0.4] - 2021-02-04 + +- CI: replace Travis & AppVeyor with GitHub actions +- CI: automatically publish upon release. + +### 1.0.3 - 2020-03-23 + +- bump packaging versions +- remove package-lock.json +- codeclimate: moved functions out of constructor + +### 1.0.2 - 2017-09-07 + +- if an object is passed in, populate the notes with it + +### 1.0.1 - 2017-09-04 + +- initial release + +[1.0.4]: https://github.com/haraka/haraka-notes/releases/tag/1.0.4 +[1.0.6]: https://github.com/haraka/haraka-notes/releases/tag/1.0.6 +[1.0.7]: https://github.com/haraka/haraka-notes/releases/tag/v1.0.7 diff --git a/Changes.md b/Changes.md deleted file mode 100644 index b99aeaa..0000000 --- a/Changes.md +++ /dev/null @@ -1,33 +0,0 @@ - -### 1.0.6 - 2022-05-27 - -- chore(ci): depend on shared GHA workflows - - -### 1.0.5 - 2022-01-26 - -- feat: make it possible to set a false value -- chore(ci): bump lowest node.js version to 14 - - -### 1.0.4 - 2021-02-04 - -- CI: replace Travis & AppVeyor with GitHub actions -- CI: automatically publish upon release. - - -### 1.0.3 - 2020-03-23 - -- bump packaging versions -- remove package-lock.json -- codeclimate: moved functions out of constructor - - -### 1.0.2 - 2017-09-07 - -- if an object is passed in, populate the notes with it - - -### 1.0.1 - 2017-09-04 - -- initial release diff --git a/README.md b/README.md index d1b6231..ac35779 100644 --- a/README.md +++ b/README.md @@ -7,42 +7,38 @@ Notes are objects that exist on Haraka connections and transactions. Prior to the release of [haraka-notes](https://github.com/haraka/haraka-notes), notes was just an empty object. Now notes is an empty object with two functions: - ### set (path, value) Sets a note at a dot delimited path to the specified value. The path can be any number of levels deep and any missing objects in the path are [autovivified](https://en.wikipedia.org/wiki/Autovivification). Perl refugees, contain yourselves. ```js -connection.transaction.notes.set('queue.wants', 'smtp_forward'); +connection.transaction.notes.set('queue.wants', 'smtp_forward') ``` The above command sets `connection.transaction.notes.queue.wants` to the value 'smtp_forward'. - ### get (path) Fetches the value of a note from a given dot delimited path. ```js -connection.transaction.notes.get('queue.wants'); +connection.transaction.notes.get('queue.wants') ``` - ## Array Syntax The get and set functions support passing the path as an array of strings. This might be useful to the type of masochist that has dots in their JS/JSON keys. Example: ```js -connection.transaction.notes.get(['i.do','like','pa.in']); +connection.transaction.notes.get(['i.do', 'like', 'pa.in']) ``` - ## [Note Path Registry](https://github.com/haraka/haraka-notes/wiki) To reduce the likelihood of namespace collisions in Haraka notes, consider registering the note paths your plugins use [in the registry](https://github.com/haraka/haraka-notes/wiki). - + [ci-img]: https://github.com/haraka/haraka-notes/actions/workflows/ci.yml/badge.svg [ci-url]: https://github.com/haraka/haraka-notes/actions/workflows/ci.yml [cov-img]: https://codecov.io/github/haraka/haraka-notes/coverage.svg diff --git a/index.js b/index.js index 4700242..8ceacfc 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,5 @@ - class Notes { - - constructor (notes) { - + constructor(notes) { if (notes && typeof notes === 'object') { Object.assign(this, notes) } @@ -11,21 +8,21 @@ class Notes { configurable: false, enumerable: false, writable: false, - value: assignPathValue.bind(this) + value: assignPathValue.bind(this), }) Object.defineProperty(this, 'get', { configurable: false, enumerable: false, writable: false, - value: getPathValue.bind(this) + value: getPathValue.bind(this), }) } } module.exports = Notes -function getSegments (path) { +function getSegments(path) { // a dot.delimited.path if (typeof path === 'string') return path.split('.') @@ -33,14 +30,14 @@ function getSegments (path) { if (Array.isArray(path)) return path } -function assignPathValue (path, value) { +function assignPathValue(path, value) { if (path === undefined || value === undefined) return const segments = getSegments(path) let dest = this while (segments.length > 1) { - // create any missing paths + // create any missing paths if (!dest[segments[0]]) dest[segments[0]] = {} // set dest one path segment deeper dest = dest[segments.shift()] @@ -48,10 +45,10 @@ function assignPathValue (path, value) { dest[segments[0]] = value } -function getPathValue (path) { +function getPathValue(path) { if (!path) return const segments = getSegments(path) return segments.reduce((prev, curr) => { return prev ? prev[curr] : undefined }, this) -} \ No newline at end of file +} diff --git a/package.json b/package.json index 6f1e480..7189b26 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,20 @@ { "name": "haraka-notes", - "version": "1.0.6", + "version": "1.0.7", "description": "Haraka Notes", "main": "index.js", + "files": [ + "CHANGELOG.md" + ], "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 @msimerson/dependency-version-checker check", + "versions:fix": "npx @msimerson/dependency-version-checker update && npm run prettier:fix" }, "repository": { "type": "git", @@ -23,8 +31,6 @@ }, "homepage": "https://github.com/haraka/haraka-notes#readme", "devDependencies": { - "eslint": "^8.55.0", - "eslint-plugin-haraka": "*", - "mocha": "^10.2.0" + "@haraka/eslint-config": "^1.1.3" } } diff --git a/test/index.js b/test/index.js index de01f07..ebab3da 100644 --- a/test/index.js +++ b/test/index.js @@ -1,17 +1,15 @@ - const assert = require('assert') -const Notes = require('../index') +const Notes = require('../index') describe('notes', () => { - beforeEach((done) => { this.notes = new Notes() done() }) it('exports an object', (done) => { - // console.log(this.notes) + // console.log(this.notes) assert.ok(typeof this.notes === 'object') done() }) @@ -82,15 +80,14 @@ describe('notes', () => { }) describe('notes + object', () => { - it('assigns instantiation object', (done) => { const passIn = { one: true, - two: "false", - three: "floor", + two: 'false', + three: 'floor', } this.notes = this.notes = new Notes(passIn) assert.deepEqual(this.notes, passIn) done() }) -}) \ No newline at end of file +})