mentie 0.0.8

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/.eslintrc.cjs ADDED
@@ -0,0 +1,7 @@
1
+ // const { eslint_config } = require( './index.cjs' )
2
+ const { eslint_config } = require( 'airier' )
3
+
4
+ // Export the default eslint config
5
+ module.exports = {
6
+ ...eslint_config
7
+ }
@@ -0,0 +1,17 @@
1
+ echo "\n🤖 [ precommit hook ] linting before committing..."
2
+
3
+ # If errors, make it clear they cannot commit
4
+ if ! lint_outcome=$(npm run lint); then
5
+ echo "🚨 [ precommit hook ] lint encountered blocking issues, fix them before committing\n"
6
+ echo "$lint_outcome"
7
+ exit 1
8
+ fi
9
+
10
+ # If warnings, suggest they fix them
11
+ if echo $lint_outcome | grep -q "warning"; then
12
+ echo "⚠️ [ precommit hook ] lint encountered warnings, consider fixing them before pushing\n"
13
+ echo "$lint_outcome"
14
+ exit 0
15
+ fi
16
+
17
+ echo "✅ [ precommit hook ] lint encountered no blocking issues\n"
package/.npmrc.bak ADDED
@@ -0,0 +1 @@
1
+ //registry.npmjs.org/:_authToken=${NPM_ACCESS_TOKEN}
@@ -0,0 +1,27 @@
1
+ {
2
+ "i18n-ally.localesPaths": [
3
+ "public/locales"
4
+ ],
5
+ "i18n-ally.keystyle": "nested",
6
+ "eslint.validate": [
7
+ "javascript",
8
+ "javascriptreact",
9
+ "typescript",
10
+ "typescriptreact"
11
+ ],
12
+ "editor.codeActionsOnSave": {
13
+ "source.fixAll.eslint": "explicit"
14
+ },
15
+ "editor.renderWhitespace": "all",
16
+ "editor.formatOnSave": true,
17
+ "eslint.format.enable": true,
18
+ "eslint.run": "onType",
19
+ "explorer.fileNesting.enabled": true,
20
+ "explorer.fileNesting.patterns": {
21
+ "vite.config.js": "*.js,.babelrc,.nvmrc,index.html,.gitignore",
22
+ ".env": ".env*,.*.json",
23
+ "firebase.json": "fire*,.fire*",
24
+ "package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml,.eslint*,config.*,.npm*,.nvm*,.ncu*",
25
+ "README.md": "*.md,LICENSE",
26
+ }
27
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Proof of Attendance Protocol
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,46 @@
1
+ # Opinionated ESLint and VSCode style guide
2
+
3
+ A shared set of standards and preferences, enforced through eslint and vscode. Priorities: minimalism, readability, documentation.
4
+
5
+ ## Quickstart
6
+
7
+ ```shell
8
+ # Install dependencies
9
+ npm install -D airier @babel/eslint-parser @babel/preset-react eslint eslint-plugin-react eslint-plugin-unused-imports husky
10
+ mkdir .vscode .husky || echo "Directories already exist"
11
+
12
+ # Create scripts
13
+ npm pkg set scripts.lint="eslint --fix src"
14
+
15
+ # Init husky
16
+ npx husky init
17
+
18
+ # Download files
19
+ curl https://raw.githubusercontent.com/actuallymentor/airier/main/.eslintrc.cjs --output .eslintrc.cjs
20
+ curl https://raw.githubusercontent.com/actuallymentor/airier/main/.vscode/settings.json --output .vscode/settings.json
21
+ curl https://raw.githubusercontent.com/actuallymentor/airier/main/.husky/pre-commit --output .husky/pre-commit
22
+ curl https://raw.githubusercontent.com/actuallymentor/airier/main/.babelrc --output .babelrc
23
+
24
+ # Add files to git
25
+ git add -f .eslintrc.cjs .babelrc .vscode/* .husky/*
26
+
27
+ # Make husky executable
28
+ chmod ug+x .husky/*
29
+ git add .husky/pre-commit
30
+ ```
31
+
32
+ ## Making changes
33
+
34
+ The relevant source files are in `modules/`. If you make a change, you can update the package by:
35
+
36
+ 1. Making the changes
37
+ 1. Updating the version number in `package.json`
38
+ 1. Pushing to the main branch of the repo or opening a pull request. Changes are deployed and published through github actions. Publishing requires a version bump in `package.json`.
39
+
40
+ ### Using this repo as a template
41
+
42
+ If you are cloning this repo and want to reuse it to create an npm package. These are the one-time setup instructions:
43
+
44
+ 1. You need to do the one-time first publishing manually by running `npm publish --access public` in the root of the project. This will create the package on npmjs and allow you to create a granular token. This requires you to rename `.npmrc` to `.npmrc.bak` temporatily.
45
+ 1. You need to obtain a NPM_ACCESS_TOKEN on npmjs (https://www.npmjs.com/settings/YOURUSERNAME/tokens/granular-access-tokens/new). Note that granular tokens expire!
46
+ # airier
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './modules/logging.js'
2
+ export * from './modules/time.js'
3
+ export * from './modules/environment.js'
@@ -0,0 +1,52 @@
1
+ // ///////////////////////////////
2
+ // Platform and environment detection
3
+ // ///////////////////////////////
4
+
5
+ /**
6
+ * Checks if the code is running in a web environment.
7
+ * @returns {boolean} Returns true if the code is running in a web environment, otherwise returns false.
8
+ */
9
+ export const is_web = typeof window !== 'undefined'
10
+ /**
11
+ * Checks if the code is running in a Node environment.
12
+ * @returns {boolean} Returns true if the code is running in a Node environment, otherwise returns false.
13
+ */
14
+ export const is_node = typeof process !== 'undefined' && process.versions && process.versions.node
15
+
16
+ /**
17
+ * Checks if the code is running in a Firebase functions emulator environment.
18
+ * @returns {boolean} Returns true if the code is running in a Firebase environment, otherwise returns false.
19
+ */
20
+ export const is_emulator = process.env.FUNCTIONS_EMULATOR === 'true'
21
+
22
+ // ///////////////////////////////
23
+ // Mode and loglevel detection
24
+ // ///////////////////////////////
25
+
26
+ const node_dev = process.env.NODE_ENV === 'development'
27
+ const web_dev = typeof location !== 'undefined' && ( `${ location.href }`.includes( 'debug=true' ) || `${ location.href }`.includes( 'debug=true' ) )
28
+
29
+ /**
30
+ * Represents the development environment.
31
+ * @type {boolean}
32
+ */
33
+ export const dev = node_dev || web_dev
34
+
35
+ /**
36
+ * The log level for web applications.
37
+ * @type {string}
38
+ */
39
+ export const web_loglevel = is_web && new URLSearchParams( location.search ).get( 'loglevel' )
40
+
41
+ /**
42
+ * The log level for the Node environment.
43
+ * @type {string}
44
+ */
45
+ export const node_loglevel = process.env.LOG_LEVEL
46
+
47
+
48
+ /**
49
+ * The log level used in the environment.
50
+ * @type {string}
51
+ */
52
+ export const loglevel = web_loglevel || node_loglevel || 'info'
@@ -0,0 +1,76 @@
1
+ // Import environment data
2
+ import { dev, loglevel } from "./environment.js"
3
+
4
+ /**
5
+ * Logs the provided messages to the console.
6
+ * Only logs in development mode OR if ?loglevel= or LOG_LEVEL= is set to one of the following: 'error', 'warn', 'info'.
7
+ * 🎯 Goal: log informational messages about the state of the application.
8
+ * @example log( `User state was updated to: `, user )
9
+ * @param {...any} messages - The messages to be logged.
10
+ */
11
+ export function log( ...messages ) {
12
+
13
+ // Check if the loglevel matches this call
14
+ const levels = [ 'error', 'warn', 'info' ]
15
+ const should_log = dev || levels.includes( loglevel )
16
+
17
+ // Log the messages if the loglevel matches
18
+ if( should_log ) console.log( ...messages )
19
+
20
+ }
21
+
22
+ /**
23
+ * Logs the provided info messages to the console.
24
+ * Only logs in development mode OR if ?loglevel= or LOG_LEVEL= is set to one of the following: 'error', 'warn'
25
+ * 🎯 Goal: log verbose trace messages used only for extremely granular debugging
26
+ * @example log.verbose( `Retreived key '${ key }' of type '${ typeof key }' from localstorage: `, cache )
27
+ * @param {...any} messages - The messages to be logged.
28
+ */
29
+ log.verbose = function( ...messages ) {
30
+
31
+ // Check if the loglevel matches this call
32
+ const levels = [ 'error', 'warn', 'info' ]
33
+ const should_log = dev || levels.includes( loglevel )
34
+
35
+ // Log the messages if the loglevel matches
36
+ if( should_log ) console.info( ...messages )
37
+
38
+ }
39
+
40
+ /**
41
+ * Logs the provided info messages to the console.
42
+ * Only logs in development mode OR if ?loglevel= or LOG_LEVEL= is set to one of the following: 'error', 'warn'
43
+ * 🎯 Goal: log warnings of things that should not happen, but do not break functionality
44
+ * @example log.warn( `Transaction history was empty, this should never happen: `, history )
45
+ * @param {...any} messages - The messages to be logged.
46
+ */
47
+ log.warn = function( ...messages ) {
48
+
49
+ // Check if the loglevel matches this call
50
+ const levels = [ 'error', 'warn' ]
51
+ const should_log = dev || levels.includes( loglevel )
52
+
53
+ // Log the messages if the loglevel matches
54
+ if( should_log ) console.warn( ...messages )
55
+
56
+ }
57
+
58
+ /**
59
+ * Logs the provided error messages to the console.
60
+ * Only logs in development mode OR if ?loglevel= or LOG_LEVEL= is set to one of the following: 'error'
61
+ * @scope log errors that impact proper functioning of the application
62
+ * @example log.error( `Error connecting to database: `, error )
63
+ * @param {...any} messages - The messages to be logged.
64
+ */
65
+ log.error = function( ...messages ) {
66
+
67
+ // Check if the loglevel matches this call
68
+ const levels = [ 'error' ]
69
+ const should_log = dev || levels.includes( loglevel )
70
+ if( !should_log ) return
71
+
72
+ // Log the messages if the loglevel matches
73
+ console.error( ...messages )
74
+ console.trace()
75
+
76
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Waits for the specified amount of time.
3
+ * @param {number} ms - The number of milliseconds to wait.
4
+ * @returns {Promise<void>} - A promise that resolves after the specified time.
5
+ */
6
+ export const wait = ( ms=0 ) => new Promise( resolve => setTimeout( resolve, ms ) )
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "mentie",
3
+ "version": "0.0.8",
4
+ "description": "Mentor's toolbelt",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "lint": "eslint --fix .",
9
+ "prepare": "husky"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/actuallymentor/mentie.git"
14
+ },
15
+ "author": "Mentor <mentor@palokaj.co> (http://github.com/actuallymentor)",
16
+ "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/actuallymentor/mentie/issues"
19
+ },
20
+ "homepage": "https://github.com/actuallymentor/mentie#readme",
21
+ "devDependencies": {
22
+ "@babel/eslint-parser": "^7.25.1",
23
+ "@babel/preset-react": "^7.24.7",
24
+ "airier": "^0.0.8",
25
+ "eslint": "^8.57.0",
26
+ "eslint-plugin-react": "^7.35.0",
27
+ "eslint-plugin-unused-imports": "^3.2.0",
28
+ "husky": "^9.1.3"
29
+ }
30
+ }