@beauraines/node-helpers 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yaml +54 -0
- package/CHANGELOG.md +10 -0
- package/package.json +8 -3
- package/src/helpers.js +27 -0
- package/src/helpers.test.js +16 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: 'Publish to NPM'
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_run:
|
|
5
|
+
workflows: ['Node.js CI']
|
|
6
|
+
types: [completed]
|
|
7
|
+
branches: [master,main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish-new-version:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v3
|
|
15
|
+
with:
|
|
16
|
+
fetch-depth: '0'
|
|
17
|
+
- name: git setup
|
|
18
|
+
run: |
|
|
19
|
+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
20
|
+
git config --local user.name "github-actions[bot]"
|
|
21
|
+
- name: setup node
|
|
22
|
+
uses: actions/setup-node@v3
|
|
23
|
+
with:
|
|
24
|
+
node-version: 16.x
|
|
25
|
+
registry-url: 'https://registry.npmjs.org'
|
|
26
|
+
- name: npm install
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Should release
|
|
30
|
+
id: should_release
|
|
31
|
+
continue-on-error: true
|
|
32
|
+
run: npm run should-release -- -v
|
|
33
|
+
|
|
34
|
+
- name: No release
|
|
35
|
+
if: steps.should_release.outcome != 'success'
|
|
36
|
+
run: echo "No release required. Skipping publishing."
|
|
37
|
+
|
|
38
|
+
- name: Version bump
|
|
39
|
+
if: steps.should_release.outcome == 'success'
|
|
40
|
+
run: npm run release
|
|
41
|
+
|
|
42
|
+
- name: Publish to NPM
|
|
43
|
+
if: steps.should_release.outcome == 'success'
|
|
44
|
+
run: npm publish
|
|
45
|
+
env:
|
|
46
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
47
|
+
|
|
48
|
+
- name: Push commits to GitHub
|
|
49
|
+
if: steps.should_release.outcome == 'success'
|
|
50
|
+
uses: ad-m/github-push-action@master
|
|
51
|
+
with:
|
|
52
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
53
|
+
branch: ${{ github.ref }}
|
|
54
|
+
tags: true
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## [2.1.0](https://github.com/beauraines/node-helpers/compare/v1.1.0...v2.1.0) (2023-03-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* Adds sparkline helper ([#6](https://github.com/beauraines/node-helpers/issues/6)) ([74accc3](https://github.com/beauraines/node-helpers/commit/74accc3ef2731809987210f39e45d1fd1c71e6ba))
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beauraines/node-helpers",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Collection of node helpers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "jest"
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"release": "standard-version",
|
|
9
|
+
"should-release": "should-release"
|
|
8
10
|
},
|
|
9
11
|
"author": "beau.raines@gmail.com",
|
|
10
12
|
"license": "ISC",
|
|
@@ -12,12 +14,15 @@
|
|
|
12
14
|
"@azure/storage-queue": "^12.11.0",
|
|
13
15
|
"azure-storage": "^2.10.7",
|
|
14
16
|
"node-fetch": "^2.6.7",
|
|
17
|
+
"sparkly": "^5.0.0",
|
|
15
18
|
"sqlite": "^4.1.2",
|
|
16
19
|
"sqlite3": "^5.1.2"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
19
22
|
"eslint": "^8.27.0",
|
|
20
23
|
"eslint-plugin-jest": "^27.2.1",
|
|
21
|
-
"jest": "^29.3.1"
|
|
24
|
+
"jest": "^29.3.1",
|
|
25
|
+
"should-release": "^1.2.0",
|
|
26
|
+
"standard-version": "^9.5.0"
|
|
22
27
|
}
|
|
23
28
|
}
|
package/src/helpers.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const sparkly = require('sparkly')
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Converts a string to Title Case, using whitespace as the delimiter
|
|
@@ -95,12 +96,38 @@ function getEpochMillis() {
|
|
|
95
96
|
return Date.now()
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
// TODO Add unit test
|
|
100
|
+
// Expected output last 30 days [1,5] ▁▂▄▆█ 5 from [1,2,3,4,5]
|
|
101
|
+
/**
|
|
102
|
+
* Generates a sparkline with labels
|
|
103
|
+
*
|
|
104
|
+
* @param {array} data Array of values to plot in the sparkline
|
|
105
|
+
* @param {string} label Text to display before sparkline
|
|
106
|
+
* @param {object} options Optional options for display, e.g display min,max,last, range coercion
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
function sparkline(data,label,options) {
|
|
110
|
+
// TODO add handling if data is object
|
|
111
|
+
// let open = last30days.map( x=> x.open_count)
|
|
112
|
+
|
|
113
|
+
// Assuming data is array
|
|
114
|
+
const minValue = Math.min(...data)
|
|
115
|
+
const maxValue = Math.max(...data)
|
|
116
|
+
const lastValue = data.slice(-1)[0]
|
|
117
|
+
|
|
118
|
+
// coerces the minimum value to zero because the mimimum option is only used for range validation,
|
|
119
|
+
// not display https://github.com/sindresorhus/sparkly/blob/9e33eaff891c41e8fb8c8883f62e9821729a9882/index.js#L15
|
|
120
|
+
// sparkly(open,{minimum:27,maximum:50})
|
|
121
|
+
return `${label} [${minValue},${maxValue}] ${sparkly(data.map( x=> x- minValue))} ${lastValue}`
|
|
122
|
+
}
|
|
123
|
+
|
|
98
124
|
module.exports = {
|
|
99
125
|
getEpochMillis,
|
|
100
126
|
fileExists,
|
|
101
127
|
groupAndSum,
|
|
102
128
|
readFile,
|
|
103
129
|
listFiles,
|
|
130
|
+
sparkline,
|
|
104
131
|
stripNewLines,
|
|
105
132
|
toTitleCase,
|
|
106
133
|
unixTimestamp
|
package/src/helpers.test.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
const helper = require('./helpers');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
describe('helpers',()=> {
|
|
4
|
+
it('should return a title case string',() => {
|
|
5
|
+
const lowerString = 'a quick brown fox';
|
|
6
|
+
const titleString = 'A Quick Brown Fox';
|
|
7
|
+
|
|
8
|
+
expect(helper.toTitleCase(lowerString)).toBe(titleString);
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('should return the correctly sparkline',()=>{
|
|
12
|
+
const expectedOutput = 'last 30 days [1,5] ▁▂▄▆█ 5'
|
|
13
|
+
const input = [1,2,3,4,5]
|
|
14
|
+
const label = 'last 30 days'
|
|
15
|
+
expect(helper.sparkline(input,label)).toBe(expectedOutput)
|
|
16
|
+
|
|
17
|
+
})
|
|
18
|
+
|
|
6
19
|
|
|
7
|
-
expect(helper.toTitleCase(lowerString)).toBe(titleString);
|
|
8
20
|
})
|
|
9
21
|
|