0.1.2 • Published 2 months ago

adamtools v0.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

adamtools

I have a couple of Vue3 apps, so I wanted to extract some code into this library, but I don't want to pay for private NPM. I'm not a frontend developer, I'm also not an expert of JavaScript, and this repo needs a LOT of tests. Constantly subject to change! DON'T EVER USE IT IN YOUR PRODUCTION APP!

Installation:

Vue version

  • Vue: 3.4.15

Add atconfig.js

import router from '@/router.js'
import i18n from '@/i18n.js'

export default {
    router,
    i18n,
    reporting: {
        sendgrid: {
            apikey: '..'
        }
    },
    googleAnalytics: {
        appName: '..',
        measurementId: '...'
    },
    fontawesome: {
        icons: [
            {
                name: 'faChevronDown',
                sources: ['solid']
            },
        ],
        componentName: 'font-awesome-icon'
    }
}

Import the plugin and your config file

import adamtools from 'adamtools'
import atconfig from '@/atconfig.js'

createApp({})
    ...
    .use(adamtools, atconfig)
    ...

Usage

Global objects:

  • $logger: custom logger, that logs to console in a predefined, lightweight format
  • $fmt: formatter utils for price, date formatting
  • $v: utils for field validation
  • $env: utils for checking NODE_ENV
  • $ga: wrapper for Google Analytics
  • $rest: wrapper for axios
  • Note: these can be used like so import { Libs } from 'adamtools' and then Libs.logger.info()

Global methods:

  • Router: $goToPage, $isPage and $getRouteMeta
  • Windows: $scrollTo
  • Reactive: $setupWindowWidth
  • VueI18n: $changeLanguageTo, $isLanguage

Classes:

  • AdamCookie: wrapper for js-cookie

Configurations:

  • setupVueErrorHandlers(): Global error handler. Catches error and reports them:
    • Vue error handler
    • Vue Router error handler
    • Window On-Error handler
    • Window UnhandledRejection handler
    • Axios error handler
  • reporting/reporting.js: In non-prod env, it simply uses the logger. Otherwise reports error event to Google Analtics, if it's set up, and uses the provided config from atconfig.js: currently it's not implemented. So far, thought about supporting SendGrid, but will provide a callback option too.