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

@htmlacademy/ast-check

v1.0.57

Published

Check ast to match criterions

Downloads

12

Readme

ast-check

Сравнивает переданное ast-дерево с заранее описанным.

Build Status

Usage

var matcher = require('ast-check').matcher;

var m = matcher();

m.
  // We define goals to match some code
  goal('init.var').
    code('var i = "#var.value"'). // "#fragment.name" will be replaced
                                  //   with fragment's code on matching
    assign('var.value', 'value.answer').
  // Several goals may be defined to inherit code
  goal('init.var.parrots').
    // Just take another goal
    takes('init.var').
    // And reassign some of fragments
    assign('var.value', 'value.parrots').
  goal('init.var.variants').
    takes('init.var').
    // When several variants are possible..
    assign('var.value', 'value.variants').
  goal('init.var.anything').
    // When we need wildcard in init part
    assign('var.value', 'builtin.anything').
  fragment('value.answer').
    code('42').
  fragment('value.parrots').
    code('38').
  fragment('value.variants').
    code('38', '42'); // fragment's code may have several variants

m.match('init.var')('var i = 42'); // => true
m.match('init.var')('var i = 38'); // => false

m.match('init.var.parrots')('var i = 42'); // => false
m.match('init.var.parrots')('var i = 38'); // => true

m.match('init.var.variants')('var i = 38'); // => true
m.match('init.var.variants')('var i = 42'); // => true

m.match('init.var.anything')('var i = 404'); // => true

Ограничения

builtin.anything

Следует избегать использования builtin.anything в конце фрагмента, т.к. если фрагмент использован внутри цели и заканчивается на всё, что угодно, проверка не будет знать где остановиться.

Вот так сравнение работать НЕ будет:

m.
  goal('wrong.way').code('"#f.1"; "#f.2"').
  fragment('f.1').code('var a = 1; "#builtin.anything"').
  fragment('f.2').code('var b = 2; "#builtin.anything"');

m.match('wrong.way')('var a = 1; var b = 2'); // => false
m.match('wrong.way')('var a = 1; var c = 3; var b = 2;'); // => false

Правильно будет сделать вот так:

m.
  goal('right.way').code('"#f.1"; "#f.2"; "#builtin.anything"').
  fragment('f.1').code('var a = 1').
  fragment('f.2').code('"#builtin.anything"; var b = 2');

m.match('right.way')('var a = 1; var b = 2'); // => true
m.match('right.way')('var a = 1; var c = 3; var b = 2;'); // => true

Отладка

Начиная с версии 1.0.13 добавлена возможность посмотреть, в каком именно месте проверка проваливается. Используется пакет debug. Сообщения о создании фрагментов и целей можно вывести в консоль, присвоив localStorage.debug значение 'ast:create:*', для просмотра сообщений по поводу сравнения узлов, фрагментов и целей нужно использовать значение 'ast:compare:*'.

Зависимости