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

@ltd/acorn-globals

v3.0.0

Published

Global references detection tool adapted from acorn-globals. Belong to "Plan J"./改编自 acorn-globals 的全局引用检测工具。从属于“简计划”。

Downloads

22

Readme

@ltd/acorn-globals

English | 简体中文 

Important Notes

This package is adapted from acorn-globals.

When I found improvable things in use, I submitted some PR for to improve it together.

But there's one thing I think it's not a defect, but a requirement for most people, but not for me, so I can only publish a modified package.

The major difference is that acorn-globals automatically ignores references to global variable undefined, while @ltd/acorn-globals reserves it to decide in user land.

At the same time, if the input is not a Program node whose sourceType is not module, the variable names declared at top-level will also be included in the output.

Other differences

  1. License: From MIT to LGPL-3.0, almost same unlimited for using, while the difference is that if the package itself is modified, it must be released as open source with the same license.

  2. Host Requirement: Because it is a back-end package, it uses ES 6+ feature.

  3. Reduce the API: The the main export function only accepts the parsed AST object as argument, not the code string and options arguments, and no parse method exported. Because users may use different versions and grammar plug-ins with different options in different cases, I don't want too much coupling.

  4. Parameter Read-Only: No modification of AST argument (acorn-globals modified the locals and parents properties of nodes).

  5. Return Value: The return value is changed from { name :string, nodes :Node[] }[] to Map<string, Node[]> & { names (): string[], nodes () :Node[] }.

const find = require('@ltd/acorn-globals');
const AST = require('acorn')/*.Parser.extend(plugin)*/.parse(code/*, options*/);
const globals = find(AST);
console.log(globals.names());

English | 简体中文 

重要说明

这个包改编自 acorn-globals

我在使用中发现可以改进的地方时,都第一时间提交了 PR 以共同完善。

但是其中有一处我认为是它的功能而非缺陷,也是多数人的需求,但不是我的需求,因而只能单独发布一个修改后的包。

这个最重要的差异就是,acorn-globals 会自动忽略对于全局变量 undefined 的引用,而 @ltd/acorn-globals 会保留,供用户自行取舍。

同时,如果传入的不是 sourceType 属性为 "module"Program 节点,那么顶层声明的变量名也会列入全局名录。

其它不同

  1. 许可协议:从 MIT 变为 LGPL-3.0,使用上一样,几乎就是没限制,主要区别是如果对包本身进行了改造,则必须以同样许可协议开源发布。

  2. 宿主要求:由于是后端用包,使用了 ES 6 以上的特性。

  3. 缩小接口:模块主导出函数只接受解析后的 AST 对象作为参数,而不接受 code 字符串和 options,同时取消导出 parse 方法函数,以尽可能解除耦合,满足用户对不同 acorn 版本、语法插件、options 的需求。

  4. 参数只读:不对 AST 参数作修改(acorn-globals 中修改了节点的 localsparents 属性)。

  5. 返回形式:返回值从 { name :string, nodes :Node[] }[] 改为 Map<string, Node[]> & { names () :string[], nodes () :Node[] }

const find = require('@ltd/acorn-globals');
const AST = require('acorn')/*.Parser.extend(plugin)*/.parse(code/*, options*/);
const globals = find(AST);
console.log(globals.names());