npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adonisjs-extensions

v0.0.11

Published

An addon/plugin package to provide core extensions for AdonisJS 4.0+

Downloads

13

Readme

adonis-extensions

An addon/plugin package to provide core extensions for AdonisJS 4.x+

NPM Version Build Status Coveralls

Getting Started

Please ensure you read the instructions.md file to get the best information about how to setup this package for optimal use


  $ adonis install adonisjs-extensions

Usage

Using custom context routines for .edge files in resources/views


<!-- The http origin of the wep app is available as a global view variable in the .edge view file(s) -->
 <link rel="canonical" href="{{ origin }}/user/me">

 <div class="wrapper">
 {{ toButton('Send', { className:'btn-primary btn', id:'submit' }) }} <!-- <button  id="submit" class="btn-primary btn">Send</button> -->

 {{ toImage('images/category-one.jpg', { alt: 'ahoy everyone' }) }} 
 <!-- <img src="http:127.0.0.1:3333/public/images/category-one.jpg" alt="ahoy everyone"> -->

 {{ toBigTextBox({ name:'tagline', className:'form-box' }, 'Just Say Hi!') }}
 <!-- <textarea class="form-box" name="tagline">Just Say Hi!</textarea> -->

 {{ toTextBox({ type:'text', name:'description', placeholder:'Enter Text...', className:'border form-input' }, 'Always opened') }} 
 <!-- <input class="border form-input" name="description" type="text" placeholder="Enter Text..." value="Always opened"> -->

 {{ toComboBox({ name:'greetings' }, [{text:'Hello',value:'hello'}, {text:'World',value:'world',selected:true}]) }} 
 <!-- <select name="greeting"><option value="hello">Hello</option>
<option value="world" selected="selected">World</option></select> -->

 {{ toFrame('https://www.example.com', { scrolling:'no' }) }}  
 <!-- <iframe src="https://www.example.com" scrolling="no"></iframe> -->

 {{ favIcon('images/favicon.ico') }} 
 <!-- <link rel="shortcut icon" href="http://127.0.0.1:3333/public/images.favicon.ico" type="image/x-icon">  -->
 </div>

 <footer>
    <!-- The full year can be included for using the global view variable too -->
    <p> Copyright &copy; {{ full_year }}. All Rights Reserved </p>
 </footer>

Using a paramsMatch() custom method in routes for start/routes.js (to sanitize route parameters at the start of the request cycle). A Cache headers middleware is available for use to set caching prefereces for assets


'use strict'

/** @type {typeof import('@adonisjs/framework/src/Route/Manager')} */
const Route = use('Route')

 Route.get('/insights/stats/:category', 'AnalyticsController.getInsights')
    .as('analytics.stats')
    .paramsMatch({category:/^([a-f0-9]{19})$/})
    .middleware(['cache.headers:private,must-revalidate,max-age=6800'])

Use custom methods on the request and response object(s) of the HttpContext object in middlewares/controllers files


'use strict'

class RouteNameAndRequestChecker {

    async handle({ request, response }, next){
	    let isAjax = request.ajax()
      // get the origin of the adonisjs server
      let origin = request.origin()
      // get the request fingerprint of the adonisjs server (unique per request)
      let fingerprint = request.fingerprint()

      if (!origin.contains('.oaksearch.com.ng')
            && request.currentRoute().isNamed('analytics.*')) { // 'analytics.stats' route will pass here
 
        // set multiple headers safely in one go.
        response.setHeaders({
          'X-App-Recall-Count': '1',
          'X-Request-Fingerprint': fingerprint
        })

        const delay = function callback (time) {
          return new Promise((resolve) => {
            return setTimeout(resolve, time)
          })
        }

        // Transform the response so that it is streamed (NodeJS streams)
        /** @HINT: 
                
          setup HTTP (NodeJS streamed) response as chunked and HTTP "Content-Type: multipart/x-mixed-replace" 
          using utf-8 encoding 
        */
        response.transform('utf8', { chunked: true, multipart: true })

        if (isAjax) {
          for (let count = 0; count < 5; count++) {
            if (count === 4) {
              // EOF sentinel to signal to the NodeJS stream
              // to close and trigger and end to the response
              // write-stream
              response.sendToStream(null)
              break;
            }

            // delay with a promise using `setTimeout()`
            await delay(count * 1000)

            // send data to the NodeJS stream (read-stream)
            // first argument is the data you wish to send to the HTTP client
            // second argument is the content-type of the multipart section for "Content-Type: multipart/x-mixed-replace"
            response.sendToStream({ time: Date.now() }, 'application/json; charset=utf-8')
          }
          return;
        }
      }

      await next();
    }
}

module.exports = RouteNameAndRequestChecker

License

MIT

Running Tests


    npm i

    npm run lint
    
    npm run test

Credits

Contributing

See the CONTRIBUTING.md file for info

Support

Coolcodes is a non-profit software foundation (collective) created by Oparand - parent company of StitchNG, Synergixe based in Abuja, Nigeria. You'll find an overview of all our work and supported open source projects on our Facebook Page.

Follow us on facebook if you can to get the latest open source software/freeware news and infomation.

Does your business depend on our open projects? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.