semlog 0.6.10 → 0.8.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/.editorconfig +19 -12
- package/.github/workflows/ci.yml +54 -0
- package/.github/workflows/publish.yml +44 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +20 -0
- package/Makefile +18 -0
- package/README.md +8 -17
- package/eslint.config.js +31 -0
- package/index.js +75 -94
- package/package.json +56 -20
- package/test/test.spec.js +75 -62
- package/.eslintrc +0 -20
- package/.jscsrc +0 -61
- package/.npmignore +0 -4
- package/.travis.yml +0 -22
- package/.yo-rc.json +0 -3
- package/Gruntfile.js +0 -102
- /package/{API.md → api.md} +0 -0
package/.editorconfig
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = space
|
|
5
|
-
indent_size = 4
|
|
6
|
-
end_of_line = lf
|
|
7
|
-
charset = utf-8
|
|
8
|
-
trim_trailing_whitespace = true
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
|
|
11
|
-
[*.md]
|
|
12
|
-
trim_trailing_whitespace = false
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
indent_style = space
|
|
5
|
+
indent_size = 4
|
|
6
|
+
end_of_line = lf
|
|
7
|
+
charset = utf-8
|
|
8
|
+
trim_trailing_whitespace = true
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
|
|
11
|
+
[*.md]
|
|
12
|
+
trim_trailing_whitespace = false
|
|
13
|
+
|
|
14
|
+
[*.yml]
|
|
15
|
+
indent_style = space
|
|
16
|
+
indent_size = 2
|
|
17
|
+
|
|
18
|
+
[Makefile]
|
|
19
|
+
indent_style = tab
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
|
|
12
|
+
ci:
|
|
13
|
+
name: "Node ${{ matrix.node }}"
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
include:
|
|
19
|
+
- node: 20
|
|
20
|
+
- node: 22
|
|
21
|
+
coverage: true
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- name: Checkout
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
- name: Setup Node.js
|
|
28
|
+
uses: actions/setup-node@v4
|
|
29
|
+
with:
|
|
30
|
+
node-version: ${{ matrix.node }}
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: npm ci
|
|
34
|
+
|
|
35
|
+
- name: Lint
|
|
36
|
+
run: npm run lint
|
|
37
|
+
|
|
38
|
+
- name: Format check
|
|
39
|
+
run: npm run format:check
|
|
40
|
+
|
|
41
|
+
- name: Test
|
|
42
|
+
run: npm test
|
|
43
|
+
if: matrix.coverage != true
|
|
44
|
+
|
|
45
|
+
- name: Test with coverage
|
|
46
|
+
run: npm run test:coverage
|
|
47
|
+
if: matrix.coverage == true
|
|
48
|
+
|
|
49
|
+
- name: Upload code coverage
|
|
50
|
+
uses: codecov/codecov-action@v4
|
|
51
|
+
with:
|
|
52
|
+
files: coverage/clover.xml
|
|
53
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
54
|
+
if: matrix.coverage == true
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
## https://github.com/gesinn-it-pub/semlog
|
|
2
|
+
|
|
3
|
+
name: Publish to npm
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
release:
|
|
7
|
+
types:
|
|
8
|
+
- published
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
|
|
12
|
+
publish:
|
|
13
|
+
name: Publish to npmjs.org
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
id-token: write # Required for npm provenance (OIDC)
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Setup Node.js
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
|
+
with:
|
|
27
|
+
node-version: 22
|
|
28
|
+
registry-url: 'https://registry.npmjs.org'
|
|
29
|
+
|
|
30
|
+
- name: Upgrade npm (Trusted Publishing requires npm >= 11.5.1)
|
|
31
|
+
run: |
|
|
32
|
+
corepack enable npm
|
|
33
|
+
corepack prepare npm@^11 --activate
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: npm ci
|
|
37
|
+
|
|
38
|
+
- name: Test
|
|
39
|
+
run: npm test
|
|
40
|
+
|
|
41
|
+
- name: Publish
|
|
42
|
+
run: |
|
|
43
|
+
unset NODE_AUTH_TOKEN
|
|
44
|
+
npm publish --access public
|
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
This project adheres to [Semantic Versioning](https://semver.org/) and
|
|
5
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.8.0] - 2026-07-26
|
|
10
|
+
|
|
11
|
+
Adds a coverage report to CI and closes out a set of open dependency vulnerabilities.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- Add `format` npm script for auto-formatting with Prettier [`dbffe72`](https://github.com/gesinn-it-pub/semlog/commit/dbffe724b95dae9870e5114ed272c5df34ee7998)
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Bump mocha to 11.7.6 and override vulnerable transitive deps (brace-expansion, diff, js-yaml, serialize-javascript) [`39d2837`](https://github.com/gesinn-it-pub/semlog/commit/39d28378b0a21e5a9963392163961aa40b0ba68f)
|
|
18
|
+
|
|
19
|
+
[Unreleased]: https://github.com/gesinn-it-pub/semlog/compare/0.8.0...HEAD
|
|
20
|
+
[0.8.0]: https://github.com/gesinn-it-pub/semlog/compare/v0.6.11...0.8.0
|
package/Makefile
ADDED
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/semlog)
|
|
2
|
-
[](https://codeclimate.com/github/Fannon/semlog)
|
|
5
|
-
[](https://codeclimate.com/github/Fannon/semlog)
|
|
2
|
+
[](https://github.com/gesinn-it-pub/semlog/actions/workflows/ci.yml)
|
|
3
|
+
[](https://codecov.io/github/gesinn-it-pub/semlog)
|
|
6
4
|
> A semantic logger module, that colors / formats automatically
|
|
7
5
|
|
|
8
6
|
## About
|
|
@@ -22,8 +20,8 @@ $ npm install --save semlog
|
|
|
22
20
|
|
|
23
21
|
### Import
|
|
24
22
|
```javascript
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const semlog = require('semlog');
|
|
24
|
+
const log = semlog.log; // Optional shortcut for logging
|
|
27
25
|
```
|
|
28
26
|
|
|
29
27
|
### Logging
|
|
@@ -49,10 +47,10 @@ log('[TODO] todo log entry');
|
|
|
49
47
|
### Logger functions
|
|
50
48
|
```javascript
|
|
51
49
|
// Returns an array with the latest log messages (depending on the config.
|
|
52
|
-
|
|
50
|
+
const logArchive = semlog.getLogHistory();
|
|
53
51
|
|
|
54
52
|
// Get current logger config
|
|
55
|
-
|
|
53
|
+
const config = semlog.getConfig();
|
|
56
54
|
|
|
57
55
|
// Change default options:
|
|
58
56
|
// This will only update the option that are actually given
|
|
@@ -69,16 +67,9 @@ semlog.updateConfig({
|
|
|
69
67
|
### Helper Functions and more examples
|
|
70
68
|
semlog has some built in helper functions like returning nicely formatted dates.
|
|
71
69
|
|
|
72
|
-
For a complete API Doc, please view the [API docs](
|
|
70
|
+
For a complete API Doc, please view the [API docs](API.md).
|
|
73
71
|
|
|
74
|
-
More
|
|
72
|
+
More examples can be found in the [unit test](https://github.com/gesinn-it-pub/semlog/blob/master/test/test.spec.js) file.
|
|
75
73
|
|
|
76
74
|
## License
|
|
77
75
|
MIT © [Simon Heimler](http://www.fannon.de)
|
|
78
|
-
|
|
79
|
-
[npm-image]: https://badge.fury.io/js/semlog.svg
|
|
80
|
-
[npm-url]: https://npmjs.org/package/semlog
|
|
81
|
-
[travis-image]: https://travis-ci.org/Fannon/semlog.svg?branch=master
|
|
82
|
-
[travis-url]: https://travis-ci.org/Fannon/semlog
|
|
83
|
-
[daviddm-image]: https://david-dm.org/Fannon/semlog.svg?theme=shields.io
|
|
84
|
-
[daviddm-url]: https://david-dm.org/Fannon/semlog
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const js = require('@eslint/js');
|
|
4
|
+
const globals = require('globals');
|
|
5
|
+
const prettier = require('eslint-config-prettier');
|
|
6
|
+
|
|
7
|
+
module.exports = [
|
|
8
|
+
js.configs.recommended,
|
|
9
|
+
{
|
|
10
|
+
languageOptions: {
|
|
11
|
+
globals: globals.node,
|
|
12
|
+
ecmaVersion: 2022,
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
16
|
+
'no-console': 'off',
|
|
17
|
+
'no-var': 'error',
|
|
18
|
+
'prefer-const': 'error',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
files: ['test/**/*.js'],
|
|
23
|
+
languageOptions: {
|
|
24
|
+
globals: {
|
|
25
|
+
...globals.node,
|
|
26
|
+
...globals.mocha,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
prettier,
|
|
31
|
+
];
|
package/index.js
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
// Requirements //
|
|
12
12
|
//////////////////////////////////////////
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const chalk = require('chalk');
|
|
15
|
+
const prettyjson = require('prettyjson');
|
|
16
16
|
|
|
17
17
|
//////////////////////////////////////////
|
|
18
18
|
// Variables //
|
|
@@ -30,14 +30,14 @@ if (!global.githubFannonSemlog) {
|
|
|
30
30
|
printDateTime: false,
|
|
31
31
|
printDebug: true,
|
|
32
32
|
printVerbose: true,
|
|
33
|
-
historySize: 2048 // 0 for none
|
|
33
|
+
historySize: 2048, // 0 for none
|
|
34
34
|
},
|
|
35
35
|
statistics: {
|
|
36
36
|
debug: 0,
|
|
37
37
|
warning: 0,
|
|
38
38
|
error: 0,
|
|
39
|
-
total: 0
|
|
40
|
-
}
|
|
39
|
+
total: 0,
|
|
40
|
+
},
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -56,7 +56,7 @@ exports.chalk = chalk;
|
|
|
56
56
|
* @param {string|object} msg Message String or Object
|
|
57
57
|
* @param {boolean} [silent] Dot not print message to the console, but stores it to the log history.
|
|
58
58
|
*/
|
|
59
|
-
exports.log = function(obj, silent) {
|
|
59
|
+
exports.log = function (obj, silent) {
|
|
60
60
|
if (obj && obj instanceof Error) {
|
|
61
61
|
exports.error(obj, silent);
|
|
62
62
|
} else if (obj && typeof obj === 'object') {
|
|
@@ -66,8 +66,7 @@ exports.log = function(obj, silent) {
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
exports.message = function(msg, silent) {
|
|
70
|
-
|
|
69
|
+
exports.message = function (msg, silent) {
|
|
71
70
|
global.githubFannonSemlog.statistics.total += 1;
|
|
72
71
|
if (msg && msg.indexOf && (msg.indexOf('[V]') >= 0 || msg.indexOf('[D]') >= 0)) {
|
|
73
72
|
global.githubFannonSemlog.statistics.debug += 1;
|
|
@@ -77,13 +76,13 @@ exports.message = function(msg, silent) {
|
|
|
77
76
|
global.githubFannonSemlog.statistics.error += 1;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
const config = global.githubFannonSemlog.config;
|
|
81
80
|
silent = silent || config.silent;
|
|
82
81
|
|
|
83
82
|
if (typeof msg !== 'string') {
|
|
84
83
|
try {
|
|
85
84
|
msg = '' + JSON.stringify(msg);
|
|
86
|
-
} catch
|
|
85
|
+
} catch {
|
|
87
86
|
msg = '[E] [SEMLOG] Could not stringify given parameter';
|
|
88
87
|
}
|
|
89
88
|
}
|
|
@@ -91,12 +90,11 @@ exports.message = function(msg, silent) {
|
|
|
91
90
|
exports.addToHistory(msg);
|
|
92
91
|
|
|
93
92
|
if (!silent) {
|
|
94
|
-
|
|
95
93
|
if (config.colorize) {
|
|
96
94
|
msg = exports.colorize(msg);
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
if ((config.printTime || config.printDateTime) && msg.trim
|
|
97
|
+
if ((config.printTime || config.printDateTime) && msg.trim().length > 0) {
|
|
100
98
|
if (config.printDateTime) {
|
|
101
99
|
msg = chalk.gray('[' + exports.humanDate() + '] ') + msg;
|
|
102
100
|
} else {
|
|
@@ -104,11 +102,9 @@ exports.message = function(msg, silent) {
|
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Supressing output of debug message
|
|
111
|
-
} else {
|
|
105
|
+
const suppress =
|
|
106
|
+
(!config.printVerbose && msg.indexOf('[V]') >= 0) || (!config.printDebug && msg.indexOf('[D]') >= 0);
|
|
107
|
+
if (!suppress) {
|
|
112
108
|
console.log(msg);
|
|
113
109
|
}
|
|
114
110
|
}
|
|
@@ -119,32 +115,30 @@ exports.message = function(msg, silent) {
|
|
|
119
115
|
*
|
|
120
116
|
* @param {object} obj Object
|
|
121
117
|
*/
|
|
122
|
-
exports.debug = function(obj, silent) {
|
|
123
|
-
|
|
118
|
+
exports.debug = function (obj, silent) {
|
|
124
119
|
global.githubFannonSemlog.statistics.total += 1;
|
|
125
120
|
|
|
126
|
-
|
|
121
|
+
const config = global.githubFannonSemlog.config;
|
|
127
122
|
silent = silent || config.silent;
|
|
128
123
|
exports.addToHistory(obj);
|
|
129
124
|
|
|
130
125
|
if (!silent) {
|
|
131
126
|
if (global.githubFannonSemlog.config.printYaml) {
|
|
132
127
|
// Print YAML
|
|
133
|
-
|
|
128
|
+
const options = {
|
|
134
129
|
keysColor: 'white',
|
|
135
130
|
dashColor: 'white',
|
|
136
131
|
stringColor: 'yellow',
|
|
137
|
-
numberColor: 'blue'
|
|
132
|
+
numberColor: 'blue',
|
|
138
133
|
};
|
|
139
134
|
|
|
140
135
|
if (!global.githubFannonSemlog.config.colorize) {
|
|
141
136
|
options.noColor = true;
|
|
142
137
|
}
|
|
143
138
|
console.log(chalk.gray('---\n') + prettyjson.render(obj, options));
|
|
144
|
-
|
|
145
139
|
} else {
|
|
146
140
|
// Print indented JSON
|
|
147
|
-
|
|
141
|
+
const msg = JSON.stringify(obj, false, 4);
|
|
148
142
|
console.log(chalk.gray(msg));
|
|
149
143
|
}
|
|
150
144
|
}
|
|
@@ -155,12 +149,11 @@ exports.debug = function(obj, silent) {
|
|
|
155
149
|
*
|
|
156
150
|
* @param {object} obj Object
|
|
157
151
|
*/
|
|
158
|
-
exports.error = function(obj, silent) {
|
|
159
|
-
|
|
152
|
+
exports.error = function (obj, silent) {
|
|
160
153
|
global.githubFannonSemlog.statistics.total += 1;
|
|
161
154
|
global.githubFannonSemlog.statistics.error += 1;
|
|
162
155
|
|
|
163
|
-
|
|
156
|
+
const config = global.githubFannonSemlog.config;
|
|
164
157
|
silent = silent || config.silent;
|
|
165
158
|
exports.addToHistory(obj);
|
|
166
159
|
|
|
@@ -173,11 +166,9 @@ exports.error = function(obj, silent) {
|
|
|
173
166
|
}
|
|
174
167
|
};
|
|
175
168
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var config = global.githubFannonSemlog.config;
|
|
180
|
-
var msg = '';
|
|
169
|
+
exports.addToHistory = function (obj) {
|
|
170
|
+
const config = global.githubFannonSemlog.config;
|
|
171
|
+
let msg;
|
|
181
172
|
|
|
182
173
|
try {
|
|
183
174
|
msg = JSON.stringify(obj, null, 4);
|
|
@@ -190,8 +181,7 @@ exports.addToHistory = function(obj) {
|
|
|
190
181
|
if (config.logDateTime) {
|
|
191
182
|
msg = '[' + exports.humanDate() + '] ' + msg;
|
|
192
183
|
}
|
|
193
|
-
|
|
194
|
-
} catch (e) {
|
|
184
|
+
} catch {
|
|
195
185
|
msg = '[W] Internal semlog error: Could not push circular/invalid object into the history';
|
|
196
186
|
}
|
|
197
187
|
|
|
@@ -205,28 +195,26 @@ exports.addToHistory = function(obj) {
|
|
|
205
195
|
* @param {string} msg
|
|
206
196
|
* @returns {string}
|
|
207
197
|
*/
|
|
208
|
-
exports.colorize = function(msg) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
'[
|
|
212
|
-
'[
|
|
213
|
-
'[
|
|
214
|
-
'[
|
|
215
|
-
'[
|
|
216
|
-
'[
|
|
217
|
-
'[
|
|
218
|
-
'[
|
|
219
|
-
'[
|
|
220
|
-
'[
|
|
221
|
-
'[
|
|
222
|
-
'[
|
|
223
|
-
'[
|
|
224
|
-
'[
|
|
225
|
-
'[TODO]': 'magenta' // TO-DO
|
|
198
|
+
exports.colorize = function (msg) {
|
|
199
|
+
const colorMap = {
|
|
200
|
+
'[E]': 'red', // ERROR
|
|
201
|
+
'[W]': 'yellow', // WARNING
|
|
202
|
+
'[?]': 'yellow', // MISSING
|
|
203
|
+
'[S]': 'green', // SUCCESS
|
|
204
|
+
'[i]': 'blue', // INFO
|
|
205
|
+
'[+]': 'green', // ADDED
|
|
206
|
+
'[-]': 'red', // REMOVED
|
|
207
|
+
'[C]': 'cyan', // CHANGED
|
|
208
|
+
'[U]': 'grey', // UNCHANGED
|
|
209
|
+
'[=]': 'grey', // EQUAL
|
|
210
|
+
'[/]': 'grey', // SKIPPED
|
|
211
|
+
'[V]': 'magenta', // VERBOSE
|
|
212
|
+
'[D]': 'magenta', // DEBUG
|
|
213
|
+
'[T]': 'magenta', // TO-DO
|
|
214
|
+
'[TODO]': 'magenta', // TO-DO
|
|
226
215
|
};
|
|
227
216
|
|
|
228
|
-
for (
|
|
229
|
-
var color = colorMap[searchString];
|
|
217
|
+
for (const [searchString, color] of Object.entries(colorMap)) {
|
|
230
218
|
if (msg && msg.indexOf && msg.indexOf(searchString) > -1) {
|
|
231
219
|
return chalk[color](msg);
|
|
232
220
|
}
|
|
@@ -235,7 +223,6 @@ exports.colorize = function(msg) {
|
|
|
235
223
|
return msg;
|
|
236
224
|
};
|
|
237
225
|
|
|
238
|
-
|
|
239
226
|
//////////////////////////////////////////
|
|
240
227
|
// LOGGER FUNCTIONS //
|
|
241
228
|
//////////////////////////////////////////
|
|
@@ -243,15 +230,14 @@ exports.colorize = function(msg) {
|
|
|
243
230
|
/**
|
|
244
231
|
* Gets the current config
|
|
245
232
|
*/
|
|
246
|
-
exports.getConfig = function() {
|
|
233
|
+
exports.getConfig = function () {
|
|
247
234
|
return global.githubFannonSemlog.config;
|
|
248
235
|
};
|
|
249
236
|
|
|
250
|
-
|
|
251
237
|
/**
|
|
252
238
|
* Gets the current config
|
|
253
239
|
*/
|
|
254
|
-
exports.getStatistics = function() {
|
|
240
|
+
exports.getStatistics = function () {
|
|
255
241
|
return global.githubFannonSemlog.statistics;
|
|
256
242
|
};
|
|
257
243
|
|
|
@@ -261,24 +247,21 @@ exports.getStatistics = function() {
|
|
|
261
247
|
*
|
|
262
248
|
* @param {object} config
|
|
263
249
|
*/
|
|
264
|
-
exports.updateConfig = function(config) {
|
|
265
|
-
|
|
266
|
-
var value = config[key];
|
|
267
|
-
global.githubFannonSemlog.config[key] = value;
|
|
268
|
-
}
|
|
250
|
+
exports.updateConfig = function (config) {
|
|
251
|
+
Object.assign(global.githubFannonSemlog.config, config);
|
|
269
252
|
return global.githubFannonSemlog.config;
|
|
270
253
|
};
|
|
271
254
|
|
|
272
255
|
/**
|
|
273
256
|
* Clears (empties) the log object
|
|
274
257
|
*/
|
|
275
|
-
exports.clearLogHistory = function() {
|
|
258
|
+
exports.clearLogHistory = function () {
|
|
276
259
|
global.githubFannonSemlog.history = [];
|
|
277
260
|
global.githubFannonSemlog.statistics = {
|
|
278
261
|
debug: 0,
|
|
279
262
|
warning: 0,
|
|
280
263
|
error: 0,
|
|
281
|
-
total: 0
|
|
264
|
+
total: 0,
|
|
282
265
|
};
|
|
283
266
|
};
|
|
284
267
|
|
|
@@ -287,11 +270,10 @@ exports.clearLogHistory = function() {
|
|
|
287
270
|
*
|
|
288
271
|
* @returns {Array}
|
|
289
272
|
*/
|
|
290
|
-
exports.getLogHistory = function() {
|
|
273
|
+
exports.getLogHistory = function () {
|
|
291
274
|
return global.githubFannonSemlog.history;
|
|
292
275
|
};
|
|
293
276
|
|
|
294
|
-
|
|
295
277
|
//////////////////////////////////////////
|
|
296
278
|
// HELPER UTILITIES //
|
|
297
279
|
//////////////////////////////////////////
|
|
@@ -303,7 +285,7 @@ exports.getLogHistory = function() {
|
|
|
303
285
|
* @param {number} digits number of total digits
|
|
304
286
|
* @returns {string}
|
|
305
287
|
*/
|
|
306
|
-
exports.pad = function(number, digits) {
|
|
288
|
+
exports.pad = function (number, digits) {
|
|
307
289
|
return new Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
|
|
308
290
|
};
|
|
309
291
|
|
|
@@ -315,7 +297,7 @@ exports.pad = function(number, digits) {
|
|
|
315
297
|
* @param number
|
|
316
298
|
* @returns {string}
|
|
317
299
|
*/
|
|
318
|
-
exports.prettyNumber = function(number) {
|
|
300
|
+
exports.prettyNumber = function (number) {
|
|
319
301
|
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
320
302
|
};
|
|
321
303
|
|
|
@@ -328,12 +310,11 @@ exports.prettyNumber = function(number) {
|
|
|
328
310
|
|
|
329
311
|
* @returns {String}
|
|
330
312
|
*/
|
|
331
|
-
exports.cleanUrl = function(url) {
|
|
313
|
+
exports.cleanUrl = function (url) {
|
|
332
314
|
url = url.trim();
|
|
333
315
|
return url.replace(/^\/|\/$/g, '');
|
|
334
316
|
};
|
|
335
317
|
|
|
336
|
-
|
|
337
318
|
/**
|
|
338
319
|
* Strips trailing slashes from URL
|
|
339
320
|
*
|
|
@@ -342,7 +323,7 @@ exports.cleanUrl = function(url) {
|
|
|
342
323
|
* @param {String} url URL to cleanup
|
|
343
324
|
* @returns {String}
|
|
344
325
|
*/
|
|
345
|
-
exports.stripTrailingSlash = function(url) {
|
|
326
|
+
exports.stripTrailingSlash = function (url) {
|
|
346
327
|
if (url.substr(-1) === '/') {
|
|
347
328
|
url = url.substr(0, url.length - 1);
|
|
348
329
|
}
|
|
@@ -354,9 +335,8 @@ exports.stripTrailingSlash = function(url) {
|
|
|
354
335
|
*
|
|
355
336
|
* @see http://stackoverflow.com/a/23329386
|
|
356
337
|
*/
|
|
357
|
-
exports.byteSize = function(obj) {
|
|
358
|
-
|
|
359
|
-
var str = '';
|
|
338
|
+
exports.byteSize = function (obj) {
|
|
339
|
+
let str;
|
|
360
340
|
|
|
361
341
|
if (typeof obj === 'object') {
|
|
362
342
|
str = JSON.stringify(obj);
|
|
@@ -364,15 +344,15 @@ exports.byteSize = function(obj) {
|
|
|
364
344
|
str = obj.toString();
|
|
365
345
|
}
|
|
366
346
|
|
|
367
|
-
|
|
368
|
-
for (
|
|
369
|
-
|
|
347
|
+
let s = str.length;
|
|
348
|
+
for (let i = str.length - 1; i >= 0; i--) {
|
|
349
|
+
const code = str.charCodeAt(i);
|
|
370
350
|
if (code > 0x7f && code <= 0x7ff) {
|
|
371
351
|
s++;
|
|
372
352
|
} else if (code > 0x7ff && code <= 0xffff) {
|
|
373
353
|
s += 2;
|
|
374
354
|
}
|
|
375
|
-
if (code >=
|
|
355
|
+
if (code >= 0xdc00 && code <= 0xdfff) {
|
|
376
356
|
i--;
|
|
377
357
|
} //trail surrogate
|
|
378
358
|
}
|
|
@@ -387,13 +367,15 @@ exports.byteSize = function(obj) {
|
|
|
387
367
|
*
|
|
388
368
|
* @see http://stackoverflow.com/a/14919494
|
|
389
369
|
*/
|
|
390
|
-
exports.prettyBytes = function(bytes, si) {
|
|
391
|
-
|
|
370
|
+
exports.prettyBytes = function (bytes, si) {
|
|
371
|
+
const thresh = si ? 1000 : 1024;
|
|
392
372
|
if (bytes < thresh) {
|
|
393
373
|
return bytes + ' B';
|
|
394
374
|
}
|
|
395
|
-
|
|
396
|
-
|
|
375
|
+
const units = si
|
|
376
|
+
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
377
|
+
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
378
|
+
let u = -1;
|
|
397
379
|
do {
|
|
398
380
|
bytes /= thresh;
|
|
399
381
|
++u;
|
|
@@ -408,7 +390,7 @@ exports.prettyBytes = function(bytes, si) {
|
|
|
408
390
|
* @param {Date=} date Optional date object. If falsy, will take current time.
|
|
409
391
|
* @returns {Array}
|
|
410
392
|
*/
|
|
411
|
-
exports.getDateArray = function(date) {
|
|
393
|
+
exports.getDateArray = function (date) {
|
|
412
394
|
date = date || new Date();
|
|
413
395
|
return [
|
|
414
396
|
date.getFullYear(),
|
|
@@ -417,7 +399,7 @@ exports.getDateArray = function(date) {
|
|
|
417
399
|
exports.pad(date.getHours(), 2),
|
|
418
400
|
exports.pad(date.getMinutes(), 2),
|
|
419
401
|
exports.pad(date.getSeconds(), 2),
|
|
420
|
-
exports.pad(date.getMilliseconds(),
|
|
402
|
+
exports.pad(date.getMilliseconds(), 3),
|
|
421
403
|
];
|
|
422
404
|
};
|
|
423
405
|
|
|
@@ -428,9 +410,9 @@ exports.getDateArray = function(date) {
|
|
|
428
410
|
* @param {object} [date]
|
|
429
411
|
* @returns {string}
|
|
430
412
|
*/
|
|
431
|
-
exports.humanDate = function(date) {
|
|
413
|
+
exports.humanDate = function (date) {
|
|
432
414
|
date = date || new Date();
|
|
433
|
-
|
|
415
|
+
const d = exports.getDateArray(date);
|
|
434
416
|
return d[0] + '-' + d[1] + '-' + d[2] + ' ' + d[3] + ':' + d[4] + ':' + d[5];
|
|
435
417
|
};
|
|
436
418
|
|
|
@@ -441,9 +423,9 @@ exports.humanDate = function(date) {
|
|
|
441
423
|
* @param {object} [date]
|
|
442
424
|
* @returns {string}
|
|
443
425
|
*/
|
|
444
|
-
exports.roboDate = function(date) {
|
|
426
|
+
exports.roboDate = function (date) {
|
|
445
427
|
date = date || new Date();
|
|
446
|
-
|
|
428
|
+
const d = exports.getDateArray(date);
|
|
447
429
|
return d[0] + '-' + d[1] + '-' + d[2] + '_' + d[3] + '-' + d[4] + '-' + d[5];
|
|
448
430
|
};
|
|
449
431
|
|
|
@@ -454,9 +436,9 @@ exports.roboDate = function(date) {
|
|
|
454
436
|
* @param {object} [date]
|
|
455
437
|
* @returns {string}
|
|
456
438
|
*/
|
|
457
|
-
exports.humanTime = function(date) {
|
|
439
|
+
exports.humanTime = function (date) {
|
|
458
440
|
date = date || new Date();
|
|
459
|
-
|
|
441
|
+
const d = exports.getDateArray(date);
|
|
460
442
|
return d[3] + ':' + d[4] + ':' + d[5];
|
|
461
443
|
};
|
|
462
444
|
|
|
@@ -467,9 +449,8 @@ exports.humanTime = function(date) {
|
|
|
467
449
|
* @param {object} [date]
|
|
468
450
|
* @returns {string}
|
|
469
451
|
*/
|
|
470
|
-
exports.roboTime = function(date) {
|
|
452
|
+
exports.roboTime = function (date) {
|
|
471
453
|
date = date || new Date();
|
|
472
|
-
|
|
454
|
+
const d = exports.getDateArray(date);
|
|
473
455
|
return d[3] + '-' + d[4] + '-' + d[5];
|
|
474
456
|
};
|
|
475
|
-
|
package/package.json
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semlog",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A semantic logger module, that colors and formats automatically depending on the content",
|
|
5
|
-
"homepage": "https://github.com/
|
|
5
|
+
"homepage": "https://github.com/gesinn-it-pub/semlog",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Simon Heimler",
|
|
8
8
|
"email": "heimlersimon@gmail.com",
|
|
9
9
|
"url": "http://www.fannon.de"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "gesinn.it GmbH & Co. KG",
|
|
14
|
+
"email": "github@gesinn.it",
|
|
15
|
+
"url": "https://gesinn.it"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/gesinn-it-pub/semlog.git"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
12
25
|
"license": "MIT",
|
|
13
26
|
"main": "index.js",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20.0.0"
|
|
29
|
+
},
|
|
14
30
|
"keywords": [
|
|
15
31
|
"semlog",
|
|
16
32
|
"log",
|
|
@@ -19,26 +35,46 @@
|
|
|
19
35
|
"colors"
|
|
20
36
|
],
|
|
21
37
|
"dependencies": {
|
|
22
|
-
"chalk": "^
|
|
23
|
-
"prettyjson": "^1.1
|
|
38
|
+
"chalk": "^4.1.2",
|
|
39
|
+
"prettyjson": "^1.2.1"
|
|
24
40
|
},
|
|
25
41
|
"devDependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
"@eslint/js": "^10.0.0",
|
|
43
|
+
"c8": "^11.0.0",
|
|
44
|
+
"chai": "^4.3.7",
|
|
45
|
+
"eslint": "^10.0.0",
|
|
46
|
+
"eslint-config-prettier": "^10.0.0",
|
|
47
|
+
"globals": "^17.0.0",
|
|
48
|
+
"mocha": "^11.7.6",
|
|
49
|
+
"prettier": "^3.0.0"
|
|
50
|
+
},
|
|
51
|
+
"overrides": {
|
|
52
|
+
"mocha": {
|
|
53
|
+
"diff": "^8.0.4",
|
|
54
|
+
"js-yaml": "^4.3.0",
|
|
55
|
+
"serialize-javascript": "^7.0.7"
|
|
56
|
+
},
|
|
57
|
+
"brace-expansion": "^5.0.8"
|
|
40
58
|
},
|
|
41
59
|
"scripts": {
|
|
42
|
-
"
|
|
60
|
+
"lint": "eslint index.js test/",
|
|
61
|
+
"format": "prettier --write index.js test/",
|
|
62
|
+
"format:check": "prettier --check index.js test/",
|
|
63
|
+
"test": "mocha 'test/**/*.spec.js'",
|
|
64
|
+
"test:coverage": "c8 mocha 'test/**/*.spec.js'"
|
|
65
|
+
},
|
|
66
|
+
"mocha": {
|
|
67
|
+
"timeout": 16000,
|
|
68
|
+
"reporter": "spec"
|
|
69
|
+
},
|
|
70
|
+
"c8": {
|
|
71
|
+
"reporter": [
|
|
72
|
+
"lcov",
|
|
73
|
+
"text",
|
|
74
|
+
"clover"
|
|
75
|
+
],
|
|
76
|
+
"include": [
|
|
77
|
+
"index.js"
|
|
78
|
+
]
|
|
43
79
|
}
|
|
44
80
|
}
|
package/test/test.spec.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var log = semlog.log;
|
|
7
|
-
var expect = require('chai').expect;
|
|
8
|
-
|
|
9
|
-
describe('semlog logger', function() {
|
|
10
|
-
|
|
11
|
-
it('logs a string message to the console', function() {
|
|
3
|
+
const semlog = require('../');
|
|
4
|
+
const log = semlog.log;
|
|
5
|
+
const expect = require('chai').expect;
|
|
12
6
|
|
|
7
|
+
describe('semlog logger', function () {
|
|
8
|
+
it('logs a string message to the console', function () {
|
|
13
9
|
console.log('');
|
|
14
10
|
console.log('-------------------------------------------------------------');
|
|
15
11
|
console.log(' Testing Log Messages');
|
|
@@ -40,13 +36,12 @@ describe('semlog logger', function() {
|
|
|
40
36
|
log(null);
|
|
41
37
|
log(Infinity);
|
|
42
38
|
|
|
43
|
-
|
|
44
39
|
console.log('');
|
|
45
40
|
console.log('-------------------------------------------------------------');
|
|
46
41
|
console.log(' Testing Log Objects and Errors');
|
|
47
42
|
console.log('-------------------------------------------------------------');
|
|
48
43
|
|
|
49
|
-
// Create a new object, that
|
|
44
|
+
// Create a new object, that prototypical inherits from the Error constructor.
|
|
50
45
|
function MyError(message) {
|
|
51
46
|
this.name = 'MyError';
|
|
52
47
|
this.message = message || 'Default Message';
|
|
@@ -54,7 +49,7 @@ describe('semlog logger', function() {
|
|
|
54
49
|
MyError.prototype = Object.create(Error.prototype);
|
|
55
50
|
MyError.prototype.constructor = MyError;
|
|
56
51
|
|
|
57
|
-
log({title: 'Object log entry', number: 10});
|
|
52
|
+
log({ title: 'Object log entry', number: 10 });
|
|
58
53
|
log(new Error('error log entry'));
|
|
59
54
|
log(new TypeError('error log entry'));
|
|
60
55
|
log(new MyError('error log entry'));
|
|
@@ -63,132 +58,146 @@ describe('semlog logger', function() {
|
|
|
63
58
|
console.log('');
|
|
64
59
|
});
|
|
65
60
|
|
|
66
|
-
it('prints objects as colorized YAML', function() {
|
|
67
|
-
semlog.updateConfig({printYaml: true});
|
|
61
|
+
it('prints objects as colorized YAML', function () {
|
|
62
|
+
semlog.updateConfig({ printYaml: true });
|
|
68
63
|
log({
|
|
69
64
|
text: 'text',
|
|
70
65
|
number: 42,
|
|
71
66
|
array: [1, '2'],
|
|
72
67
|
object: {
|
|
73
|
-
key: 'value'
|
|
74
|
-
}
|
|
68
|
+
key: 'value',
|
|
69
|
+
},
|
|
75
70
|
});
|
|
76
|
-
semlog.updateConfig({printYaml: false});
|
|
71
|
+
semlog.updateConfig({ printYaml: false });
|
|
77
72
|
});
|
|
78
73
|
|
|
79
|
-
it('prints
|
|
74
|
+
it('prints objects as YAML without color when colorize is false', function () {
|
|
75
|
+
semlog.updateConfig({ printYaml: true, colorize: false });
|
|
76
|
+
log({ key: 'value' });
|
|
77
|
+
semlog.updateConfig({ printYaml: false, colorize: true });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('prints errors', function () {
|
|
80
81
|
semlog.error(new Error('Test Error'));
|
|
81
82
|
});
|
|
82
83
|
|
|
83
|
-
it('handles various invalid log objects', function() {
|
|
84
|
+
it('handles various invalid log objects', function () {
|
|
84
85
|
log(undefined);
|
|
85
86
|
log(null);
|
|
86
87
|
log(Error);
|
|
87
88
|
log(Infinity);
|
|
88
89
|
});
|
|
89
90
|
|
|
90
|
-
it('
|
|
91
|
-
|
|
91
|
+
it('suppresses verbose and debug messages when configured', function () {
|
|
92
|
+
semlog.updateConfig({ printVerbose: false, printDebug: false });
|
|
93
|
+
log('[V] suppressed verbose');
|
|
94
|
+
log('[D] suppressed debug');
|
|
95
|
+
semlog.updateConfig({ printVerbose: true, printDebug: true });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns the log history as an array', function () {
|
|
99
|
+
const logArchive = semlog.getLogHistory();
|
|
92
100
|
|
|
93
101
|
expect(logArchive).to.be.instanceof(Array);
|
|
94
102
|
expect(logArchive.length).to.be.least(1);
|
|
95
103
|
});
|
|
96
104
|
|
|
97
|
-
it('clears global log object', function() {
|
|
105
|
+
it('clears global log object', function () {
|
|
98
106
|
semlog.clearLogHistory();
|
|
99
|
-
|
|
107
|
+
const logArchive = semlog.getLogHistory();
|
|
100
108
|
|
|
101
109
|
expect(logArchive).to.be.instanceof(Array);
|
|
102
110
|
expect(logArchive.length).to.equal(0);
|
|
103
111
|
});
|
|
104
112
|
|
|
105
|
-
it('logs silently', function() {
|
|
113
|
+
it('logs silently', function () {
|
|
106
114
|
semlog.log(' [i] info log entry ', true);
|
|
107
115
|
semlog.log(' [W] warning log entry', true);
|
|
108
116
|
semlog.log(' [E] error log entry', true);
|
|
109
117
|
|
|
110
|
-
|
|
118
|
+
const logArchive = semlog.getLogHistory();
|
|
111
119
|
|
|
112
120
|
expect(logArchive).to.be.instanceof(Array);
|
|
113
121
|
expect(logArchive.length).to.equal(3);
|
|
114
122
|
});
|
|
115
123
|
|
|
116
|
-
it('gets config', function() {
|
|
117
|
-
|
|
124
|
+
it('gets config', function () {
|
|
125
|
+
const config = semlog.getConfig();
|
|
118
126
|
|
|
119
127
|
expect(config).to.be.instanceof(Object);
|
|
120
128
|
expect(Object.keys(config).length).to.be.least(3);
|
|
121
129
|
});
|
|
122
130
|
|
|
123
|
-
it('updates the config', function() {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var newConfig = semlog.updateConfig({printTime: false});
|
|
131
|
+
it('updates the config', function () {
|
|
132
|
+
const config = semlog.getConfig();
|
|
133
|
+
const newConfig = semlog.updateConfig({ printTime: false });
|
|
127
134
|
|
|
128
135
|
expect(newConfig).to.be.instanceof(Object);
|
|
129
136
|
expect(newConfig.printTime).to.equal(false);
|
|
130
137
|
expect(newConfig.historySize).to.equal(config.historySize);
|
|
131
138
|
});
|
|
132
139
|
|
|
133
|
-
it('keeps the log object at a specific size', function() {
|
|
140
|
+
it('keeps the log object at a specific size', function () {
|
|
141
|
+
const historySize = 7;
|
|
142
|
+
const newConfig = semlog.updateConfig({ historySize: historySize, logDateTime: true });
|
|
134
143
|
|
|
135
|
-
|
|
136
|
-
var newConfig = semlog.updateConfig({historySize: historySize, logDateTime: true});
|
|
137
|
-
|
|
138
|
-
for (var i = 0; i < 32; i++) {
|
|
144
|
+
for (let i = 0; i < 32; i++) {
|
|
139
145
|
log('[i] Index added: ' + i, true);
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
|
|
148
|
+
const logHistory = semlog.getLogHistory();
|
|
143
149
|
expect(newConfig.historySize).to.equal(logHistory.length);
|
|
144
150
|
expect(logHistory.length).to.equal(historySize);
|
|
145
151
|
});
|
|
146
152
|
|
|
147
|
-
it('
|
|
153
|
+
it('handles circular objects in history gracefully', function () {
|
|
154
|
+
const circular = {};
|
|
155
|
+
circular.self = circular;
|
|
156
|
+
semlog.addToHistory(circular);
|
|
157
|
+
const history = semlog.getLogHistory();
|
|
158
|
+
expect(history[history.length - 1]).to.include('[W]');
|
|
159
|
+
});
|
|
148
160
|
|
|
161
|
+
it('returns the log archive as non circular array', function () {
|
|
149
162
|
log(semlog.getLogHistory());
|
|
150
|
-
|
|
163
|
+
const logHistory = semlog.getLogHistory();
|
|
151
164
|
|
|
152
165
|
expect(JSON.stringify(logHistory)).to.be.a('string');
|
|
153
|
-
|
|
154
166
|
});
|
|
155
167
|
|
|
156
|
-
it('returns log statistics', function() {
|
|
157
|
-
|
|
168
|
+
it('returns log statistics', function () {
|
|
158
169
|
log(semlog.getStatistics());
|
|
159
|
-
|
|
170
|
+
const statistics = semlog.getStatistics();
|
|
160
171
|
|
|
161
172
|
expect(statistics.total).to.be.a('number');
|
|
162
|
-
|
|
163
173
|
});
|
|
164
|
-
|
|
165
174
|
});
|
|
166
175
|
|
|
167
|
-
describe('semlog utilities', function() {
|
|
168
|
-
|
|
169
|
-
it('pad numbers', function() {
|
|
176
|
+
describe('semlog utilities', function () {
|
|
177
|
+
it('pad numbers', function () {
|
|
170
178
|
expect(semlog.pad(7, 1)).to.equal('7');
|
|
171
179
|
expect(semlog.pad(7, 2)).to.equal('07');
|
|
172
180
|
expect(semlog.pad(7, 3)).to.equal('007');
|
|
173
181
|
});
|
|
174
182
|
|
|
175
|
-
it('pretty prints numbers', function() {
|
|
183
|
+
it('pretty prints numbers', function () {
|
|
176
184
|
expect(semlog.prettyNumber(1)).to.equal('1');
|
|
177
185
|
expect(semlog.prettyNumber(100000)).to.equal('100.000');
|
|
178
186
|
expect(semlog.prettyNumber(-100000)).to.equal('-100.000');
|
|
179
187
|
});
|
|
180
188
|
|
|
181
|
-
it('pretty prints bytes', function() {
|
|
189
|
+
it('pretty prints bytes', function () {
|
|
190
|
+
expect(semlog.prettyBytes(500)).to.equal('500 B');
|
|
182
191
|
expect(semlog.prettyBytes(1024)).to.be.a('string');
|
|
183
192
|
expect(semlog.prettyBytes(1024)).to.equal('1.0 KiB');
|
|
184
193
|
expect(semlog.prettyBytes(1024, true)).to.equal('1.0 kB');
|
|
185
194
|
});
|
|
186
195
|
|
|
187
|
-
it('strips trailing slashes from URLs', function() {
|
|
196
|
+
it('strips trailing slashes from URLs', function () {
|
|
188
197
|
expect(semlog.stripTrailingSlash('http://fannon.de/')).to.equal('http://fannon.de');
|
|
189
198
|
});
|
|
190
199
|
|
|
191
|
-
it('strips leading and ending slashes from URLs / URL paths', function() {
|
|
200
|
+
it('strips leading and ending slashes from URLs / URL paths', function () {
|
|
192
201
|
expect(semlog.cleanUrl('http://fannon.de/')).to.equal('http://fannon.de');
|
|
193
202
|
expect(semlog.cleanUrl('http://fannon.de ')).to.equal('http://fannon.de');
|
|
194
203
|
expect(semlog.cleanUrl('/test/')).to.equal('test');
|
|
@@ -196,40 +205,44 @@ describe('semlog utilities', function() {
|
|
|
196
205
|
expect(semlog.cleanUrl(' test/ ')).to.equal('test');
|
|
197
206
|
});
|
|
198
207
|
|
|
199
|
-
it('creates date arrays', function() {
|
|
208
|
+
it('creates date arrays', function () {
|
|
200
209
|
expect(semlog.getDateArray().length).to.equal(7);
|
|
201
210
|
expect(semlog.getDateArray()[0]).to.equal(new Date().getFullYear());
|
|
202
211
|
});
|
|
203
212
|
|
|
204
|
-
it('return human readable date-times', function() {
|
|
213
|
+
it('return human readable date-times', function () {
|
|
205
214
|
expect(semlog.humanDate().length).to.equal(19);
|
|
206
215
|
expect(semlog.humanDate(new Date('October 13, 2014 11:13:00'))).to.equal('2014-10-13 11:13:00');
|
|
207
216
|
});
|
|
208
217
|
|
|
209
|
-
it('return machine optimized date-times', function() {
|
|
218
|
+
it('return machine optimized date-times', function () {
|
|
210
219
|
expect(semlog.roboDate().length).to.equal(19);
|
|
211
220
|
expect(semlog.roboDate(new Date('October 13, 2014 11:13:00'))).to.equal('2014-10-13_11-13-00');
|
|
212
221
|
});
|
|
213
222
|
|
|
214
|
-
it('return human readable time', function() {
|
|
223
|
+
it('return human readable time', function () {
|
|
215
224
|
expect(semlog.humanTime().length).to.equal(8);
|
|
216
225
|
expect(semlog.humanTime(new Date('October 13, 2014 11:13:00'))).to.equal('11:13:00');
|
|
217
226
|
});
|
|
218
227
|
|
|
219
|
-
it('return machine optimized time', function() {
|
|
228
|
+
it('return machine optimized time', function () {
|
|
220
229
|
expect(semlog.roboTime().length).to.equal(8);
|
|
221
230
|
expect(semlog.roboTime(new Date('October 13, 2014 11:13:00'))).to.equal('11-13-00');
|
|
222
231
|
});
|
|
223
232
|
|
|
224
|
-
it('calculates the bytesize of strings', function() {
|
|
233
|
+
it('calculates the bytesize of strings', function () {
|
|
225
234
|
expect(semlog.byteSize('internationalization')).to.be.a('number');
|
|
226
235
|
expect(semlog.byteSize('internationalization')).to.equal(20);
|
|
227
236
|
});
|
|
228
237
|
|
|
229
|
-
it('calculates the bytesize of objects (parsed to JSON)', function() {
|
|
230
|
-
expect(semlog.byteSize({title: 'internationalization'})).to.be.a('number');
|
|
231
|
-
expect(semlog.byteSize({title: 'internationalization'})).to.equal(32);
|
|
238
|
+
it('calculates the bytesize of objects (parsed to JSON)', function () {
|
|
239
|
+
expect(semlog.byteSize({ title: 'internationalization' })).to.be.a('number');
|
|
240
|
+
expect(semlog.byteSize({ title: 'internationalization' })).to.equal(32);
|
|
232
241
|
});
|
|
233
242
|
|
|
234
|
-
|
|
243
|
+
it('calculates the bytesize of multibyte strings', function () {
|
|
244
|
+
expect(semlog.byteSize('\u00F1')).to.equal(2); // 2-byte UTF-8 (ñ)
|
|
245
|
+
expect(semlog.byteSize('\u20AC')).to.equal(3); // 3-byte UTF-8 (€)
|
|
246
|
+
expect(semlog.byteSize('\uD840\uDC00')).to.equal(4); // 4-byte UTF-8 surrogate pair (𠀀)
|
|
247
|
+
});
|
|
235
248
|
});
|
package/.eslintrc
DELETED
package/.jscsrc
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"disallowSpacesInNamedFunctionExpression": {
|
|
3
|
-
"beforeOpeningRoundBrace": true
|
|
4
|
-
},
|
|
5
|
-
"disallowSpacesInFunctionExpression": {
|
|
6
|
-
"beforeOpeningRoundBrace": true
|
|
7
|
-
},
|
|
8
|
-
"disallowSpacesInAnonymousFunctionExpression": {
|
|
9
|
-
"beforeOpeningRoundBrace": true
|
|
10
|
-
},
|
|
11
|
-
"disallowSpacesInFunctionDeclaration": {
|
|
12
|
-
"beforeOpeningRoundBrace": true
|
|
13
|
-
},
|
|
14
|
-
"disallowEmptyBlocks": true,
|
|
15
|
-
"disallowSpacesInsideArrayBrackets": true,
|
|
16
|
-
"disallowSpacesInsideParentheses": true,
|
|
17
|
-
"disallowSpaceAfterObjectKeys": true,
|
|
18
|
-
"disallowSpaceAfterPrefixUnaryOperators": true,
|
|
19
|
-
"disallowSpaceBeforePostfixUnaryOperators": true,
|
|
20
|
-
"disallowSpaceBeforeBinaryOperators": [
|
|
21
|
-
","
|
|
22
|
-
],
|
|
23
|
-
"disallowMixedSpacesAndTabs": true,
|
|
24
|
-
"disallowTrailingWhitespace": "ignoreEmptyLines",
|
|
25
|
-
"disallowTrailingComma": true,
|
|
26
|
-
"disallowYodaConditions": true,
|
|
27
|
-
"disallowKeywords": [ "with" ],
|
|
28
|
-
"disallowMultipleVarDecl": true,
|
|
29
|
-
"requireSpaceBeforeBlockStatements": true,
|
|
30
|
-
"requireParenthesesAroundIIFE": true,
|
|
31
|
-
"requireSpacesInConditionalExpression": true,
|
|
32
|
-
"requireBlocksOnNewline": 1,
|
|
33
|
-
"requireCommaBeforeLineBreak": true,
|
|
34
|
-
"requireSpaceBeforeBinaryOperators": true,
|
|
35
|
-
"requireSpaceAfterBinaryOperators": true,
|
|
36
|
-
"requireLineFeedAtFileEnd": true,
|
|
37
|
-
"requireCapitalizedConstructors": true,
|
|
38
|
-
"requireDotNotation": true,
|
|
39
|
-
"requireSpacesInForStatement": true,
|
|
40
|
-
"requireSpaceBetweenArguments": true,
|
|
41
|
-
"requireCurlyBraces": [
|
|
42
|
-
"do"
|
|
43
|
-
],
|
|
44
|
-
"requireSpaceAfterKeywords": [
|
|
45
|
-
"if",
|
|
46
|
-
"else",
|
|
47
|
-
"for",
|
|
48
|
-
"while",
|
|
49
|
-
"do",
|
|
50
|
-
"switch",
|
|
51
|
-
"case",
|
|
52
|
-
"return",
|
|
53
|
-
"try",
|
|
54
|
-
"catch",
|
|
55
|
-
"typeof"
|
|
56
|
-
],
|
|
57
|
-
"safeContextKeyword": "_this",
|
|
58
|
-
"validateLineBreaks": "LF",
|
|
59
|
-
"validateQuoteMarks": "'",
|
|
60
|
-
"validateIndentation": 4
|
|
61
|
-
}
|
package/.npmignore
DELETED
package/.travis.yml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
3
|
-
- '0.10'
|
|
4
|
-
- '0.12'
|
|
5
|
-
- '4.2'
|
|
6
|
-
- '5.1'
|
|
7
|
-
|
|
8
|
-
sudo: false
|
|
9
|
-
|
|
10
|
-
addons:
|
|
11
|
-
code_climate:
|
|
12
|
-
repo_token: d025e5a435157e5cf3b9573054d1c2777cc6c8eb2d4d6abb6a0c976e9c4b75f6
|
|
13
|
-
|
|
14
|
-
notifications:
|
|
15
|
-
email:
|
|
16
|
-
on_success: [never] # default: change
|
|
17
|
-
on_failure: [always] # default: always
|
|
18
|
-
recipients:
|
|
19
|
-
- info@fannon.de
|
|
20
|
-
|
|
21
|
-
after_script:
|
|
22
|
-
- cat coverage/lcov.info | codeclimate
|
package/.yo-rc.json
DELETED
package/Gruntfile.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
module.exports = function(grunt) {
|
|
3
|
-
|
|
4
|
-
// Show elapsed time at the end
|
|
5
|
-
require('time-grunt')(grunt);
|
|
6
|
-
|
|
7
|
-
// Load all grunt tasks
|
|
8
|
-
require('load-grunt-tasks')(grunt);
|
|
9
|
-
|
|
10
|
-
grunt.initConfig({
|
|
11
|
-
eslint: {
|
|
12
|
-
options: {
|
|
13
|
-
configFile: '.eslintrc'
|
|
14
|
-
},
|
|
15
|
-
js: {
|
|
16
|
-
src: ['*.js']
|
|
17
|
-
},
|
|
18
|
-
test: {
|
|
19
|
-
src: ['test/**/*.js']
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
jscs: {
|
|
23
|
-
options: {
|
|
24
|
-
config: '.jscsrc',
|
|
25
|
-
force: true
|
|
26
|
-
},
|
|
27
|
-
lib: {
|
|
28
|
-
src: ['lib/**/*.js']
|
|
29
|
-
},
|
|
30
|
-
test: {
|
|
31
|
-
src: ['test/**/*.js']
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
mochacli: {
|
|
35
|
-
options: {
|
|
36
|
-
reporter: 'spec',
|
|
37
|
-
bail: true,
|
|
38
|
-
force: true,
|
|
39
|
-
timeout: 16000
|
|
40
|
-
},
|
|
41
|
-
all: ['test/**/*.spec.js']
|
|
42
|
-
},
|
|
43
|
-
mocha_istanbul: {
|
|
44
|
-
coverage: {
|
|
45
|
-
src: ['test/'],
|
|
46
|
-
options: {
|
|
47
|
-
mask: '*.spec.js',
|
|
48
|
-
coverage: true,
|
|
49
|
-
reportFormats: ['lcov', 'text']
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
watch: {
|
|
54
|
-
gruntfile: {
|
|
55
|
-
files: '<%= jshint.gruntfile.src %>',
|
|
56
|
-
tasks: ['jshint:gruntfile']
|
|
57
|
-
},
|
|
58
|
-
js: {
|
|
59
|
-
files: '<%= jshint.js.src %>',
|
|
60
|
-
tasks: ['lint', 'test']
|
|
61
|
-
},
|
|
62
|
-
test: {
|
|
63
|
-
files: '<%= jshint.test.src %>',
|
|
64
|
-
tasks: ['lint', 'test']
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
documentation: {
|
|
68
|
-
md: {
|
|
69
|
-
files: [{
|
|
70
|
-
'src': ['index.js']
|
|
71
|
-
}],
|
|
72
|
-
options: {
|
|
73
|
-
format: 'md',
|
|
74
|
-
destination: 'doc'
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
html: {
|
|
78
|
-
files: [{
|
|
79
|
-
'src': ['index.js']
|
|
80
|
-
}],
|
|
81
|
-
options: {
|
|
82
|
-
destination: 'doc'
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
release: {
|
|
87
|
-
options: {
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Default task.
|
|
94
|
-
grunt.registerTask('lint', ['eslint', 'jscs']);
|
|
95
|
-
grunt.registerTask('test', ['mochacli']);
|
|
96
|
-
grunt.registerTask('coverage', ['mocha_istanbul:coverage']);
|
|
97
|
-
grunt.registerTask('default', ['lint', 'coverage', 'documentation']);
|
|
98
|
-
|
|
99
|
-
grunt.event.on('coverage', function(content, done) {
|
|
100
|
-
done();
|
|
101
|
-
});
|
|
102
|
-
};
|
/package/{API.md → api.md}
RENAMED
|
File without changes
|