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

fangs.js

v2.0.1

Published

## Status

Downloads

1

Readme

Fangs.js

Status

codecov

This is an update from Fangs, by Peter Krantz.

Fangs is a screenreader emulator. It basically turn any HTML mark up as a string and return a screenreader transcript.

This version supports:

  • CSS visibility
  • ARIA attributes
  • Role attribute
  • Multiple provider (although only VoiceOver is implemented)

Why fang.js

There are already a lot of tools to test your page's accessibility. I also use those tools a lot.

However there was a need to test if my projects were not just complient, but also meaningful to most screen readers.

This is why I had a look at Fangs.

This was, in my styleguide, I can review hown my component dispalys on screen, and also how it will read on a screenreader: Styleguide

Installation

  npm install fangs.js

Usage

What fangs does is to transform an HTML content into a screenreader transcript.

//ES6
import Fangs from 'fangs.js';

const content = `
  <div>
    <h1>H1 Title</h1>
    <h2>H2 Title</h2>
    <h3>H3 Title</h3>
    <h4>H4 Title</h4>
    <h5>H5 Title</h5>
    <h6>H6 Title</h6>
  </div>
`

const fangContent = new Fangs(content);

console.log(fangContent.getTranslated());

/* outputs:
   <span class="announce">Heading level one</span>   
    H1 Title
   <span class="announce">Heading level two</span>   
    H2 Title
   <span class="announce">Heading level three</span>   
    H3 Title
   <span class="announce">Heading level four</span>   
    H4 Title
   <span class="announce">Heading level five</span>   
    H5 Title
   <span class="announce">Heading level six</span>   
    H6 Title
*/

Aria-hidden

HTML can be hidden using aria-hidden as expected:

//ES6
import Fangs from 'fangs.js';

const content = `
  <p>To display</p>
  <p aria-hidden="true">aria-hidden</p>
  <p aria-hidden="false">To display too</p>
`

const fangContent = new Fangs(content);

console.log(fangContent.getTranslated());

/* outputs:
  <span class=\'announce\'>*pause*</span> To display
  <span class=\'announce\'>*pause*</span> To display too
*/

CSS support

Sometime, context can be hidden with CSS. It should not be displayed then. There is an option to pass the CSS of your site as a second paramater. Note that CSS is a string.

Behind the hood, we are using juice.js to apply CSS to the HTML.

const Fangs = require('./index.js');
const juice = require('juice');
const fs = require('fs');

// Getting the CSS
var style = `
  .to-hide {
    display: none;
  }
`;

content = `
  <div class="to-show">
   Displayed content
  </div>
  <div class="to-hide">
   Hidden content
  </div>
`;

const fangContent = new Fangs(content, style);
console.log(fangContent.render());
/* outputs:
  <div class="to-show">
   Displayed content
  </div>
  <div class="to-hide" style="display:none">
   Hidden content
  </div>
*/

console.log(fangContent.getTranslated());
/* outputs:
  Displayed content
*/

Contribute

Not all aria tags are supported at the moment. You are welcome to contribute to this project.

If you want to contribute, please use the generator provided in this project.

npm run plop

Run the test:

npm run test