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

require_once

v0.4.6

Published

A file loader for browser javascript and eventually node as well

Downloads

1

Readme

require-once

RequireOnce is mostly a browser library that is inspired by requirejs and adds additional code from other sources to the current app context.

What is it?

Require Once is a first and foremost a client (browser) javascipt library that is inspired by requirejs but loads modules off the network automatically and so your index page is not filled with <script src="path/to/dependency"></script>. As the name implies, it will require whatever your dependency once and if you require it again, it will just use whatever it got the first time around. This means that you can require your own dependencies from within the JS files that need them rather than from elsewhere. You can also use it in node so your browser and server can share some of the same code base if you so desire.

Install

Browser: <script src="path/to/require_once.min.js"></script>

node: npm install require_once --save

usage

the library creates a requireOnce and require_once (alias) function in your global scope and you can call them to require your libraries from URLs. Please be advised that the URLs should be absolute paths (aka starting with "http(s)://", "//", or "/"). All paths are relative to the HTML document that the app is ran and not the path of the file the includeOnce is called in. as a result, it's the best to just use absolute paths .

requireOnce(array url, function callback[, function failedCallback])

General usage example:

requireOnce([
    'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js',
    'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css',
    'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js',
    'https://ajax.googleapis.com/ajax/libs/hammerjs/2.0.8/hammer.min.js'
], function(jquery, uiCSS, jqueryUI, hammerjs){
    $("head")
        .append(
            $("<style></style>").text(uiCSS)
        )

    new Hammer($("body")[0])
        .on("tap", function(ev){
            console.log("Eeeww I've been touched");
        });
});

Licence?

MIT = free for all yay?

Changelog:

0.4.6

Should actually finally fix the bug that was causing the resolution function to resolve twice this time hopefully for real and forever.

0.4.5

Removed Debugging "console.log" from min file

0.4.4

Fixed a bug that made callbacks resolve twice sometimes.

0.4.3

Actually Fixed a bug that was supposed to be fixed in 0.4.2

0.4.2

Fixed a bug that made the require_once choke on null requires

0.4.1

Fixed a bug that caused the resolution order to be forwards instead of backwards

0.4.0

This update is yet another update that would cause potentially breaking changes to the code However it is for the best as it is a before the validation script for checking if we are able to use require once is

if (typeof requireOnce != "undefined") var requireOnce = require("require_once");

however because of hoisting this line actually become

var requireOnce;
if (typeof requireOnce != "undefined") requireOnce = require("require_once");

which means that in the case that you are loading require_once off the main script that's no big deal but if a script is being required the declaration above would override the global requireOnce function and as a result the workaround would be to declare a requireOnce AND require_once within the scope of the required script's execution scope. This is not the most ideal and would likely lead to more hacks down the line in order to make things work (eg: potential issues in Electrons dev environment if i ever get around to supporting that). In order to avoid this problem the code that checks for if requireOnce is useable or not should be modified to

var requireOnce = (typeof require_once == "function")? require_once : require("require_once");

this line declares a locally scoped version of requireOnce based on the globally scoped require_once or uses node's require function to get the function. This way it simplifies the need for require once being declared in the code execution scope just to have things work. If you are exclusively running require_once from within the browser then there should be no problem for you with this update.