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

@twodashes/browser

v0.4.12

Published

Utility functions for the browser. Querystring parsing, HTTP requests, promises, Retina display, operating system detection, etc.

Downloads

4

Readme

Browser-specific functions - to help with AJAX, URLs, Promises, Retina, OS, etc.

See also: 📙🚀 @twodashes/universal 📙🚀

That one has much more functionality. Any JavaScript functions that can be used in Node as well as the browser are stored in @twodashes/universal. This @twodashes/browser package has only functions that can NOT be used in Node.js, such as is_retina, http_ajax, http_get, querystring_from_object, etc. These can be used with a <script> tag, or import by Webpack/Babel.

⚠️ PLEASE NOTE: ⚠️

All names in this library (functions, files) will change. Currently figuring out what to call everything. This library will be stabled when released as version 1. These functions all check for typeof window === 'object', and should quit gracefully if used in server-side rendering, but don't rely on this until version 1. The "http" AJAX functions rely on a global fetch variable.

npm package Try it out in CodeSandbox.io

Installation

These are exported for your choice of environment. When importing, specify cjs/esm/__ format. The __ is meant to be used with the browser <script> tag. It creates a window.__ variable.

  <!-- download all functions into window.__ -->
  <script src="https://cdn.jsdelivr.net/npm/@twodashes/universal@latest/__/index.js"></script>
  <!-- download only the types of functions you need_ -->
  <script src="https://cdn.jsdelivr.net/npm/@twodashes/universal@latest/__/sort_strings.js"></script>

ES Modules

  import { sort_by_rating_and_position } from "@twodashes/universal/esm/sort_strings"

CommonJS

  const sort_strings = require("@twodashes/universal/esm/sort_strings")

Why not UMD modules standard? Code splitting. By specifying your choice "esm" (ES Modules), "cjs" (CommonJS) or "__" (window.__), you're able to download only the specific functions you actually need, not everthing else. Additionally on the browser, you can download multiple times using multiple<script>tags (for example both@twodashes/universaland@twodashes/browser, or/sort_stringsand/arrays). All downloaded scripts will be combined into one single flatwindow.__ dictionary/object. See code sandbox. Please do message (Paul) if this is unclear, or if may know a better way of accomplishing all this.

Documentation

Twodashes contents (documentation pages coming soon):

  • coming soon - for now please see "./src" folder which uses standard JsDoc comments

Develop:

Please try it, file an issue, add or fix some code, make a pull request. I'd love to make you an equal contributor. Contact Paul Shorey with any feaute requests or bugs. Thank you! Unit tests, code sandbox examples, and better documentation coming soon.

This project is built using ES Modules in ./esm. It is then compiled into CommonJS into ./cjs and for the browser (exported as window.**) in ./**. Read more about ES Modules.

npm run build:

npm run build runs these npm scripts, in this order:

  1. ignore_index - Copy ./esm/index.js to ./index.mjs (so it does not get converted in next step **)
  2. esm_cjs - Convert ./esm to ./cjs
  3. putback_index - Copy ./index.mjs back to ./esm/index.js
  4. esm_cjs_index - Convert ./esm/index.js to ./cjs/index.js (so it can get processed without reference to other files)
  5. browser - Convert ./esm to ./__

** Don't want to convert ./esm/index.js to ./cjs/index.js along with all the other modules in ./esm, because rollup breaks up the functions to prevent redundant code. But I actually want index.js to be redundant, to contain code that is already in the other module files. This way, index.js is self-contained, and other files are self-contained, not importing anything. I could not figure out how to configure rollup command to NOT build with require() commands. Can not have require() commands because the parcel command does convert to browser code well with require commands. Each file already needs to be self-contained before running parcel build.