diff --git a/.github/node.js.yml b/.github/node.js.yml new file mode 100644 index 0000000..5f6c339 --- /dev/null +++ b/.github/node.js.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x, 14.x, 16.x, 18.x, 20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: node ./test.js + # - run: npm run build --if-present + # - run: npm run test \ No newline at end of file diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..aa13ca9 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 16.x, 18.x, 20.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: node ./test.js diff --git a/README.md b/README.md index 80fc346..f15b9ee 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,12 @@ npm install murmurhash ``` ```js -murmurhash = require('murmurhash') +const murmurhash = require('murmurhash'); +``` +or + +```js +import murmurhash from 'murmurhash'; ``` Both version 2 and 3 of the MurmurHash algorithm are supported: diff --git a/murmurhash.js b/murmurhash.js index 6a73210..1705d2e 100644 --- a/murmurhash.js +++ b/murmurhash.js @@ -1,5 +1,5 @@ (function(){ - var _global = this; + const _global = this; const createBuffer = (val) => new TextEncoder().encode(val) @@ -17,7 +17,7 @@ */ function MurmurHashV2(str, seed) { if (typeof str === 'string') str = createBuffer(str); - var + let l = str.length, h = seed ^ l, i = 0, @@ -54,7 +54,7 @@ return h >>> 0; }; - /** + /* * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011) * * @author Gary Court @@ -69,7 +69,7 @@ function MurmurHashV3(key, seed) { if (typeof key === 'string') key = createBuffer(key); - var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i; + let remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i; remainder = key.length & 3; // key.length % 4 bytes = key.length - remainder; @@ -120,14 +120,14 @@ return h1 >>> 0; } - var murmur = MurmurHashV3; + const murmur = MurmurHashV3; murmur.v2 = MurmurHashV2; murmur.v3 = MurmurHashV3; if (typeof(module) != 'undefined') { module.exports = murmur; } else { - var _previousRoot = _global.murmur; + const _previousRoot = _global.murmur; murmur.noConflict = function() { _global.murmur = _previousRoot; return murmur; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..2b41109 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "murmurhash", + "version": "2.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "murmurhash", + "version": "2.0.1", + "license": "MIT" + } + } +} diff --git a/package.json b/package.json index abcff74..2ad0eff 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name" : "murmurhash", "version" : "1.0.0", "description" : "A Node.js module for the optimized JavaScript implementation of the MurmurHash algorithms.", - "author": { + "authors": { "Gary Court": "gary.court@gmail.com", "Derek Perez": "derek@derekperez.com" }, diff --git a/test.js b/test.js index bda6baf..e4672fb 100644 --- a/test.js +++ b/test.js @@ -10,4 +10,4 @@ if ( fromStr !== 3017643002 ) { throw new Error(`Wrong output`); -} +} else console.dir('Test ended with cought 0 errors');