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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bem-history

v4.0.0

Published

BEM wrap for History API

Readme

bem-history Library

What is this?

BEM wrap for History API:

  • supports browsers with native History API and hashchange event;
  • provides manipulations with url, browser location and history in the terms of BEM (http://bem.info/).

Components

  • uri block for an url parsing;
  • history block provides work with browser History with two modificators:
  • provider_history-api supports native History API;
  • provider_hashchange supports fallback on hashchange event;
  • location high-level block for a window.location change.

Usage

#####uri Parse url:

u = BEM.blocks.uri.parse('http://127.0.0.1:8080/desktop.bundles/index/index.html?test=1&test=2&param2=22');

Change port:

u.port(80);

Change query params:

u.deleteParam('test', '2');
u.replaceParam('param2', 2);

Serialize url:

u.toString(); // "http://127.0.0.1:80/desktop.bundles/index/index.html?test=1&param2=2"

#####history Get history block instance:

h = BEM.blocks.history.getInstance();

Push new or replace history state:

h.pushState({}, 'Title', 'http://127.0.0.1:8080/desktop.bundles/index/index.html');
h.replaceState({}, 'Title', 'http://127.0.0.1:8080/desktop.bundles/index/index.html');

#####location Get location block instance:

l = BEM.blocks.location.getInstance();

Change window.location using a full url:

l.change({ url: 'http://127.0.0.1:8080/desktop.bundles/index/index.html' });

Change current location using only the new query params:

l.change({ params: { param1: [11,12], param2: 'ololo' } });
window.location.href; // "http://127.0.0.1:8080/desktop.bundles/index/index.html?param1=11&param1=12&param2=ololo"

Что это?

БЭМ-обертка над браузерным History API:

  • поддержка браузеров с history API (provider_history-api);
  • деградация до #! для браузеров без history API (provider_hashchange);
  • работа с блоком в терминах БЭМ.

Требования

  • единое событие при появление новой записи в истории и при переходе к предыдущему;
  • поддержка браузеров с hashchange для плавной деградации;
  • поддержать возможность изменения document.title, state object без изменения URL;
  • предоставить хелперы для манипуляции с URL.

URL

  • автоматическое исправление адреса /search?query на #!/search?query при загрузке в браузере с реализацией provider_hashchange;
  • автоматическое исправление адреса #!/search?query на /search?query для браузеров с provider_history-api;
  • получение всех значимых частей URL (path, query), в том числе работа с множественными значениями queryParams;
  • возможность изменения всех значимых частей URL;
  • использована в качестве основы и сильно переписана библиотека https://github.com/derek-watson/jsUri.

Документация и другие полифилы

  • https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries
  • https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills#html5-history-api-pushstate-replacestate-popstate

Реализация

  • Блок uri для работы с URL;
  • Блок history с двумя модификаторами для работы с историей:
  • provider_history-api с поддержкой history api;
  • provider_hashchange с поддержкой hashchange;
  • Блок location в качестве дополнительного уровня абстракции над history.