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

angeldav-test-pageloader

v1.0.10-d

Published

this package uses angeldav-testpackage and express

Downloads

12

Readme

test-pageLoader package

This is a small package i made that handles all express's app.get requests, it uses angeldav-testpackage and expressjs.

Initalization variables for angeldav-testpackage

// import angeldav-testpackage
const page = require('angeldav-testpackage');

// set url of the website to replace __rooturl in the html files to the chosen url
page.url = "localhost:1234" 

// Page to show when a page is not found
page.default.notfound:`${__dirname}/notfound.html` 

// Base template for the pages
page.default.template = `${__dirname}/template.html` 

// OPTIONAL
// replaces tags like <¡foo> to the content inside this value in all pages
page.default.other = {
    "foo":"<input type='button' value='button'>" 
}

page loader

const express = require('express');
const app = express();

const pageloader = require(`angeldav-test-pageloader`)(page,{
    "app":app, // express app
    "path":`${__dirname}/view` // folder containing all pages to load
})

TAGS

404 error tags

<¡errortitle> <!-- Displays error title example: 404: Page not found -->
<¡errormessage> <!-- Displays error message ex: {page name} isn't a valid page -->
<¡errorcode> <!-- Displays error code ex: 404 -->

Other tags

__pagetitle  <!-- Displays the title chosen in the config table -->
__rooturl  <!-- Returns the website url stated in package.url -->

EXAMPLES

Example of index.js

const express = require('express');
const app = express();
const page = require('angeldav-testpackage');

page.url = "http://localhost:3000"
page.default.template = `${__dirname}/template.html`
page.default.notfound = `${__dirname}/view/404.html`

app.use('/public', express.static('public'));

const pageloader = require(`angeldav-test-pageloader`)(page,{
    "app":app,
    "path":`${__dirname}/view`
})

Example of template.html

<!DOCTYPE html>
<html lang="en">

    <head>
        <title>Website</title>
    </head>

    <body>
        <section class="<¿templatesectionclass>">
            <¿templatesectionmain> <!-- required for loader content to show -->
        </section>
    </body>

</html>

Example of index page

view/index.html

<p>Hello world!</p>

screenshot

Example of static page

view/test.html

<h2>Test</h2>
<p>Hello this is a test</p>

screenshot1

Example of dynamic page

view/codetest.js

const number1 = parseInt(req.query.a)
const number2 = parseInt(req.query.b)
var total = number1 + number2

new page.loader({
    "res": res,
    "req": req,
    "title": "Sum of numbers",
    "templatedir": `${__dirname}/../../pages/codetest.html`,
    "other": {
        "num1": number1,
        "num2": number2,
        "total": total
    }
}).load()

pages/codetest.html

<h2>__pagetitle</h2>
<p>The sum of <¡num1> and <¡num2> is <¡total></p>

screenshot

page.default.preload

angeldav-testpackage stuff.

page.default.preload sets javascript code to run before fully loading a page, it lets you modify the template page before any more changes with the base variable.

Useful when adding logged in username, custom themes and other stuff.

example usage of preload

index.js

const page = require('angeldav_testpackage');
page.preload = `${__dirname}/default_preload.js`

default_preload.js

function getCookie(cookie, name) {
    if (cookie.includes(name+"=") == false || name == "") return ""
    var result = cookie.slice(cookie.indexOf(name))
    if (result.includes(";")) result = result.slice(0, result.indexOf(";"))
    result = result.split("=")
    return result[result.length-1]
}

let theme = getCookie(req.headers.cookie, "theme")
if (theme == "special") base = fs.readFileSync(`${__dirname}/../../templates/special.html`).toString()