Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d804bd0
Initial plan
Copilot Dec 24, 2025
65391a5
Fix ESLint errors, package.json, and preinstall script
Copilot Dec 24, 2025
dbc837a
Revert dotest version to ^2 per requirement
Copilot Dec 24, 2025
0ce0aab
Fix version comparison logic in preinstall.js
Copilot Dec 24, 2025
8e06224
Add required eslint config dependencies (globals, @eslint/js)
Copilot Dec 24, 2025
91ea8f7
Remove eslint deps - provided by dotest, use npm test to lint
Copilot Dec 24, 2025
18ff331
Remove spacing in array/object refs and chained methods, use template…
Copilot Dec 24, 2025
a16c620
Replace var with const/let, apply ES2022 optimizations
Copilot Jan 2, 2026
a125b61
Fix spacing in negation operator
Copilot Jan 2, 2026
ecfdb15
Revert json to data variable change for memory efficiency
Copilot Jan 2, 2026
ec9ffb3
Update README examples with modern JavaScript style
Copilot Jan 2, 2026
5c24643
Test(github): Fixed optional env vars nodejs
fvdm Jan 2, 2026
1b8cf53
Test(github): Fixed conditional env vars for node
fvdm Jan 2, 2026
6d07aaf
Fix compatibility with vnStat 2.x (name vs id field)
Copilot Jan 2, 2026
628b158
Test(github): Install vnstat before test
fvdm Jan 2, 2026
286e623
Merge branch 'develop' into copilot/fix-broken-package-issues
fvdm Jan 2, 2026
1366989
Modernize testing and mock code with ES2022 features
Copilot Jan 2, 2026
7ec1de9
Rename fixtures to testing and generate-dummy-db.js to validate-dummy…
Copilot Jan 4, 2026
262f612
Modernize mock-vnstat with consistent style and spacing
Copilot Jan 4, 2026
e734125
Remove empty string arguments from console.log() calls
Copilot Jan 4, 2026
7d9abda
Test(github): Restore env vars and added app bin
fvdm Jan 4, 2026
271f59e
Test: Output testing config before script
fvdm Jan 4, 2026
4db68ac
Test: Refactor and fix config
fvdm Jan 4, 2026
5586fa1
Test: Fixed config defaults and info
fvdm Jan 4, 2026
8e45ee5
Test(github): Use mock-vnstat in the node action
fvdm Jan 4, 2026
0e90cb7
Test: Fixed config dump
fvdm Jan 4, 2026
17f961d
Fix test: pass false to getStats() to get all interfaces
Copilot Jan 4, 2026
7e02ee5
Fix getStats() to return all interfaces when called without iface par…
Copilot Jan 4, 2026
f7804f4
Set config default to return all interfaces (iface: false)
Copilot Jan 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@ jobs:
node-version: ${{ fromJson(needs.lts_versions.outputs.matrix) }}
steps:
- uses: actions/checkout@v6

- run: "sudo apt-get update && sudo apt-get install -y vnstat"

- name: Test on Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}

- run: npm install
env:
NODE_APP_BIN: ${{ secrets.NODE_APP_BIN }}

- run: npm test
env:
NODE_APP_IFACE: ${{ NODE_APP_IFACE }}
NODE_APP_BIN: './testing/mock-vnstat'
NODE_APP_IFACE: ${{ secrets.NODE_APP_IFACE }}
DOTEST_NOCOV: ${{ secrets.DOTEST_NOCOV }}
DOTEST_MINCOV: ${{ secrets.DOTEST_MINCOV }}
DOTEST_COVFUNCTIONS: 100

- name: Coveralls Parallel
uses: coverallsapp/github-action@master
if: always()
Expand Down
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ Example
-------

```js
var vnstat = require ('vnstat-dumpdb') ();
const vnstat = require( 'vnstat-dumpdb' )();

// Get traffic per day
vnstat.getStats ('eth0', function (err, data) {
if (err) {
console.log (err);
vnstat.getStats( 'eth0', ( err, data ) => {
if ( err ) {
console.log( err );
return;
}

console.log (data.traffic.days);
});
console.log( data.traffic.days );
} );

// Read config setting
vnstat.getConfig (function (err, config) {
if (err) {
console.log (err);
vnstat.getConfig( ( err, config ) => {
if ( err ) {
console.log( err );
return;
}

console.log ('Interfaces updating every ' + config.UpdateInterval + ' minutes');
});
console.log( `Interfaces updating every ${config.UpdateInterval} minutes` );
} );
```


Expand Down Expand Up @@ -66,15 +66,15 @@ Each method below takes a callback _function_ which gets two arguments:
* `data` - Result `object` or not set when error

```js
function myCallback (err, data) {
if (err) {
console.log (err);
console.log (err.stack);
const myCallback = ( err, data ) => {
if ( err ) {
console.log( err );
console.log( err.stack );
return;
}

console.log (data);
}
console.log( data );
};
```


Expand All @@ -93,13 +93,13 @@ getStats ( [iface], callback )

Get statistics for one, multiple or all interfaces.

* One: `vnstat.getStats ('eth0', callback)`
* All: `vnstat.getStats (false, callback)`
* One: `vnstat.getStats( 'eth0', callback )`
* All: `vnstat.getStats( false, callback )`


```js
// Get traffic for interface en1
vnstat.getStats ('en1', console.log);
vnstat.getStats( 'en1', console.log );

// Output
{ id: 'en1',
Expand Down Expand Up @@ -157,14 +157,14 @@ getConfig ( callback )
Get vnStat configuration.

```js
vnstat.getConfig (function (err, config) {
if (err) {
console.log (err);
vnstat.getConfig( ( err, config ) => {
if ( err ) {
console.log( err );
return;
}

console.log ('Interfaces updating every ' + config.UpdateInterval + ' seconds');
});
console.log( `Interfaces updating every ${config.UpdateInterval} seconds` );
} );
```


Expand Down
22 changes: 11 additions & 11 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ The dummy database includes:

```js
// Set environment variable before running tests
NODE_APP_BIN=./fixtures/mock-vnstat npm test
NODE_APP_BIN=./testing/mock-vnstat npm test

// Or use it directly in your code
var vnstat = require('vnstat-dumpdb')({
bin: './fixtures/mock-vnstat'
});
const vnstat = require( 'vnstat-dumpdb' )( {
bin: './testing/mock-vnstat',
} );

vnstat.getStats('eth0', function(err, data) {
vnstat.getStats( 'eth0', ( err, data ) => {
// Test with dummy data
console.log(data);
});
console.log( data );
} );
```

**Managing the dummy database:**

```bash
# Display information about the dummy database
node generate-dummy-db.js info
node testing/validate-dummy-db.js info

# Validate the dummy data format
node generate-dummy-db.js validate
node testing/validate-dummy-db.js validate

# Run the example
cd fixtures && node example.js
cd testing && node example.js
```

For detailed information about the dummy database and testing, see [fixtures/README.md](fixtures/README.md).
For detailed information about the dummy database and testing, see [testing/README.md](testing/README.md).
12 changes: 11 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = [
'no-sequences': 'error',
'no-shadow': 'error',
'no-shadow-restricted-names': 'error',
'func-call-spacing': 'error',
'func-call-spacing': ['error', 'never'],
'no-sparse-arrays': 'warn',
'no-sync': 'warn',
'no-ternary': 'off',
Expand All @@ -118,6 +118,15 @@ module.exports = [
'no-unreachable': 'error',
'no-unused-vars': 'warn',
'no-use-before-define': 'error',
'no-var': 'error',
'prefer-const': 'error',
'prefer-arrow-callback': 'error',
'arrow-body-style': ['error', 'as-needed'],
'object-shorthand': ['error', 'always'],
'prefer-destructuring': ['error', {
array: false,
object: true,
}],
'no-useless-concat': 'error',
'no-warning-comments': 'warn',
'no-with': 'error',
Expand All @@ -129,6 +138,7 @@ module.exports = [
'operator-assignment': ['error', 'always'],
'operator-linebreak': ['error', 'before'],
'padded-blocks': 'off',
'prefer-template': 'error',
'quote-props': ['error', 'consistent'],
'quotes': ['error', 'single', 'avoid-escape'],
'radix': 'error',
Expand Down
64 changes: 0 additions & 64 deletions fixtures/example.js

This file was deleted.

51 changes: 0 additions & 51 deletions fixtures/mock-vnstat

This file was deleted.

Loading