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

@presspage/common-js

v1.4.0

Published

A common library of javascript functions

Downloads

3

Readme

Installation

To install,

npm i @presspage/common-js

Getting Started

Tested for use with Electron. Create a preload.js and in your electron window definition add the following webPreferences,

mainWindow = new BrowserWindow({
    width: 1072,
    height: 910,
    webPreferences: {
		nodeIntegration: false,
		contextIsolation: true, // protect against prototype pollution
		enableRemoteModule: false, // turn off remote
	  	preload: path.join(__dirname, 'preload.js')
    }
})

Inside the preload.js,

const {contextBridge} = require("electron");

const {$, id, listener, show, hide, showParent, hideParent, showAlert, editable, http_post, wp_ajax, webdevencrypt, loadScript, getRSS, replaceText, setValue, replaceHTML, appendHTML, todayAsISO8601, Export2Doc} = require("@presspage/common-js");

contextBridge.exposeInMainWorld(
    "common", {
        $: $,
        id: id,
        listener: listener,
        show: show,
        hide: hide,
        showParent: showParent,
        hideParent: hideParent,
        showAlert: showAlert,
        editable: editable,
        http_post: http_post,
        wp_ajax: wp_ajax,
        webdevencrypt: webdevencrypt,
        loadScript: loadScript,
        getRSS: getRSS,
        replaceText: replaceText,
        setValue: setValue,
        replaceHTML: replaceHTML,
        appendHTML: appendHTML,
        todayAsISO8601: todayAsISO8301,
        Export2Doc: Export2Doc
    }
);

Then inside your views/index.html, just invoke the javascript functions on the window object,

window.common.listener("element_id","click",function(){ alert("It works!"); });

Common JavaScript Library Functions

$ - a jQuery-like representation for the object

id

Obtain the object reference of an element by the ID,

var button = id("button_id");
button.setAttribute("disabled","disabled");

listener

Use to add an action handler to an element,

listener('element_id','click',function(e){
    // event handling logic
});

show

Makes an element visible,

show('element_id');

hide

Makes an element invisible,

hide('element_id');

showParent

Make the parent of an element visible

showParent('element_id');

where element_id is the child of the parent to show

hideParent

Make the parent of an element invisible

hideParent('element_id');

where element_id is the child of the parent to be hidden

showAlert

Shows an modal div (see w3schools.com about W3.CSS Modal Dialogs)

showAlert(page, title, message);

editable

Makes an element editable,

editabled('element_id',edit_flag);

when edit_flag is true, the element specified by the element_id is made editable, otherwise it is made read only.

http_post

Invokes a HTTP POST request,

http_post(url, params, function(results){
    // handling results returned?
});

wp_ajax

Invokes an WordPress AJAX request without using jQuery,

wp_ajax(url, action, params, function(results){
    // handle return data, if any?
});

webdevencrypt

JavaScript encryption and decryption,

setEncrypt(plaintext, passcode);
setDecrypt(encrypted, passcode);

loadScript

Loads additional JavaScript files dynamically,

loadScript('<full url of the javascript file>');

getRSS

Retrieves an RSS feed and displays in a list element,

getRSS('<url of rss feed>','element_id of the list element');

replaceText

Replaces text in a specified element,

replaceText(selector, "text");

setValue

Set the value of a specified element,

setValue(selector, "new value");

replaceHTML

Replaces the element HTML content,

replaceHTML(selector, "<html>");

appendHTML

Appends additional HTML to an element HTML content,

appendHTML(selector, "<html>");

todayAsISO8601

Retrieves current date as ISO 8601 aka YYYY-MM-DD formant,

var today = todayAsISO8601();

Export2Doc

Saves a HTML div contents as a DOCX file,

Export2Doc('div element containing HTML content','filename.docx');

Contact Us

The best contact method is via email at [email protected]

License

Creative Commons Attribution 4.0