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

hascan

v0.0.10

Published

Build tools for has.js.

Downloads

711

Readme

hascan

Build slim versions of has.js or use has.js on the server to optimize your code.

Slimming has.js

has.js adds a non-trival amount of code to your pages. With hascan, you can build a version of has.js that includes only the feature tests you actually use in your code.

hascan --build svg canvas audio-mp3

This will output a concatenation of the core of has.js and only the individual tests you call for.

hascan --build < /path/to/file.js

This will read the given file to find out which has('feature') tests are used and output a build of has.js for only those features.

Slimming Your Code

Give Hascan a user-agent string and it will build a version of your code which eliminates has('feature') branches intended for other browsers. Using data from Browserscope, Hascan can determine which features a browser supports, statically analyze your code using Uglify, and safely remove branches not intended for that browser.

hascan --eliminate -a "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.803.0 Safari/535.1" < /path/to/file.js

Installation

$ npm install hascan

Usage (command line)

Usage: hascan [options] [features]

Options:
    -b, --build              builds has.js with only the tests you want
                                Use [features] arguments to specify feature tests to include
                                Use --file or stdin to include only features tested in JS source
    -e, --eliminate          eliminates has() branches for unavailable features
                                Use [features] arguments to specify available features
                                Use --agent to look up the features available for a user-agent
                                Use --file option or stdin to provide JavaScript to process
    -s, --features           shows a list of features supported by a user agent
                                Use --agent to specify the user-agent to query
                                Use [features] arguments to limit list to a set of features
    -t, --tests              shows the names of all tests supported
    -u, --update             downloads the latest data from Browserscope to has.json

    -a, --agent              user agent string
    -f, --file               path of a file to read in
    -m, --minify             minify generated source code

    -h, --help               output help information     

Usage (from Node.js)

Eliminating code:

var hascan = require('hascan');    
var sourceCode = 'if (has("svg")) { a() } else if (has("canvas")) { b() } else { c() }';
var featureMap = {svg: false, canvas: true};
var smallerCode = hascan.eliminateFeatureTests(sourceCode, featureMap);
console.log(smallerCode);

...

{b()}

    

Getting features supported by a user-agent:

var hascan = require('hascan');
var userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.803.0 Safari/535.1";
hascan.getFeatureDB(['canvas', 'svg', 'activex'], function(err, featureDB) {
    var featureMap = featureDB.getFeatureMap(userAgent);
    console.log(featureMap);
});

...

{ canvas: true, svg: true, activex: false }

Browserscope

Hascan uses data posted to Browserscope here:

http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnINCxIEVGVzdBiG3-0GDA?v=3

This data may not yet cover all browsers. If there is a browser missing, go here and post test results for that browser.

License

Copyright 2011 Joe Hewitt

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.