@turbowarp/nanolog 0.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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/index.js +52 -0
  4. package/package.json +11 -0
  5. package/test.js +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Thomas Weber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @turbowarp/nanolog
2
+
3
+ `minilog` replacement for TurboWarp.
4
+
5
+ - Extremely small: less than 1KB, no dependencies
6
+ - Does not use leading-zero octal literals (syntax error in strict mode)
7
+ - Does not interact with local storage, cookies, etc. (minilog does)
8
+ - Uses the default log styles from your browser; doesn't try to be smart
9
+
10
+ ```js
11
+ const nanolog = require('@turbowarp/nanolog');
12
+
13
+ const log = nanolog('renderer');
14
+ log.debug('debug');
15
+ log.info('info');
16
+ log.warn('warn');
17
+ log.error('error');
18
+ ```
package/index.js ADDED
@@ -0,0 +1,52 @@
1
+ // only use colors in non-browser environments
2
+ const addColors = typeof document === 'undefined';
3
+
4
+ const RESET = addColors ? '\u001b[0m' : '';
5
+ const GRAY = addColors ? '\u001b[90m' : '';
6
+ const BLUE = addColors ? '\u001b[34m' : '';
7
+ const CYAN = addColors ? '\u001b[36m' : '';
8
+ const YELLOW = addColors ? '\u001b[33m' : '';
9
+ const RED = addColors ? '\u001b[31m' : '';
10
+
11
+ const DEBUG = `${BLUE}debug${RESET}`;
12
+ const INFO = `${CYAN}info${RESET}`;
13
+ const WARN = `${YELLOW}warn${RESET}`;
14
+ const ERROR = `${RED}error${RESET}`;
15
+
16
+ let enabled = false;
17
+
18
+ const createLog = (namespace = '') => {
19
+ const log = (childNamespace) => createLog(namespace ? `${namespace} ${childNamespace}` : childNamespace);
20
+
21
+ const formattedNamespace = namespace ? [`${GRAY}${namespace}${RESET}`] : [];
22
+
23
+ log.debug = log.log = (...args) => {
24
+ if (enabled) console.debug(...formattedNamespace, DEBUG, ...args);
25
+ return log;
26
+ };
27
+ log.info = (...args) => {
28
+ if (enabled) console.info(...formattedNamespace, INFO, ...args);
29
+ return log;
30
+ };
31
+ log.warn = (...args) => {
32
+ if (enabled) console.warn(...formattedNamespace, WARN, ...args);
33
+ return log;
34
+ };
35
+ log.error = (...args) => {
36
+ if (enabled) console.error(...formattedNamespace, ERROR, ...args);
37
+ return log;
38
+ };
39
+
40
+ return log;
41
+ };
42
+
43
+ createLog.enable = () => {
44
+ enabled = true;
45
+ return createLog;
46
+ };
47
+ createLog.disable = () => {
48
+ enabled = false;
49
+ return createLog;
50
+ };
51
+
52
+ module.exports = createLog;
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@turbowarp/nanolog",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test"
8
+ },
9
+ "author": "GarboMuffin",
10
+ "license": "MIT"
11
+ }
package/test.js ADDED
@@ -0,0 +1,24 @@
1
+ const nanolog = require('./index');
2
+
3
+ nanolog.enable();
4
+
5
+ const root = nanolog();
6
+ root.debug('debug');
7
+ root.info('info');
8
+ root.log('log');
9
+ root.warn('warn');
10
+ root.error('error');
11
+
12
+ const child1 = root('abc');
13
+ child1.debug('debug');
14
+ child1.info('info');
15
+ child1.log('log');
16
+ child1.warn('warn');
17
+ child1.error('error');
18
+
19
+ const child2 = child1('def');
20
+ child2.debug('debug');
21
+ child2.info('info');
22
+ child2.log('log');
23
+ child2.warn('warn');
24
+ child2.error('error');