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

proxery

v1.0.6

Published

A proxy for easy DOM elements querying

Downloads

4

Readme

proxery

GitHub license David

Proxery is a very simple library for the browser that allows you to very easily get elements from the DOM using proxies. Given the following HTML:

<form>
  <input type="text" id="name">
  <input type="number" id="age">
<form>

You can get references to the <input> fields using:

let { name, age } = proxery.id;

Have fun !

Setup

Download

npm install proxery

Import / Require

// Create your proxery object with default options
const proxery = require('proxery')();

// Or specify them. These are the default values
const proxery = require('proxery')({
    cache: false, // Should results be cached (the same query won't be done twice)
    document: window.document // Which "document" object to use. Can be changed for testing purposes
});

You can also use the ES6/TypeScript syntax:

// With explicit options
import createProxery from 'proxery';
const proxery = createProxery({ /* Options */ });

// With default options (shorter thanks to a little helper file)
import proxery from 'proxery/default';

Usage

Once you have your proxery object, you can use 4 different proxies to do various queries:

  • proxery.class.*
  • proxery.id.*
  • proxery.name.*
  • proxery.tag.*

They all return a list of HTMLElement except for id which obviously returns a single element. Destructuring assignment is particularly useful here, especially with proxery.id:

Examples

// Classes
let buttons = proxery.class.btn;

// ID
let { id1, id2, id3 } = proxery.id;

// Names
// Because it returns an array, we destructure it
let [ firstEmailElement ] = proxery.name.email;

// Tag names
proxery.tag.form.forEach(form => form.submit());

If the query containes dashes (e.g. <a class="btn btn-primary">), you can use camelCase to refer to the element:

let [ a ] = proxery.class.btnPrimary;

Browser

This library is obviously made for the browser. You can bundle it using browserify, AMD or simply use it by including dist/proxery.min.js in a webpage, which will expose a global variable. You may also use the UNPKG CDN

Tests

Tests are created with mocha and asserted with chai.expect

You can run the suite using

npm test

License

proxery is licensed under the very permissive MIT License. You may use it for commercial projects.