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

dependenceparser

v0.0.2

Published

A dependence parser.

Downloads

1

Readme

dependenceParser

  • DependenceParser是一个简单的文件依赖解析器,它专注与处理依赖关系,根据文件之间的关系,构造出一个文件顺序列表。

  • DependenceParser不关心如何从一个文件中解析出这个文件对于其他文件的依赖,这块工作通过给定不同的parser来实现,DependenceParser不提供文件内容解析的具体实现。

  • DependenceParser的初衷是为其他的模块解析器提供底层支持。你需要做的,就是专注于如何从一个文件中提取出你需要的依赖信息。

使用

具体例子可以参考example/parse.js.下面的例子先是构造了一个用于解析使用dependenceRequire( ['a.js', 'b.js']);这样的语法的解析器,然后使用dependenceParser完成文件的依赖关系解析.

下面为parser的定义,唯一需要注意的是,parser是一个function,它接受一个参数,也就是需要解析的文件字符串,最后返回一个依赖文件列表数组。

// Dependence parser for `dependenceRequire(['a.js','b.js'])` like.
var Fs = require( 'fs' );

module.exports = function( filePath ){

    var data = Fs.readFileSync( filePath).toString();
    var Ex = /^dependenceRequire\s*\(\s*(\[?\s*[\w'"\.\/,\-]+\s*\]?)\s*\)/g;
    var dependenceList = [];
    var testResult;
    var depArrStr;
    var depArr;

    while( ( testResult = Ex.exec( data ) ) !== null ){

        depArrStr = testResult[ 1 ];
        if( depArrStr ){
            try{
                depArr = eval( '(' + depArrStr + ')' );
            }
            catch(e){
                // Just leave it..
            }
            dependenceList = dependenceList.concat( depArr );
        }
    }

    return dependenceList;
};

利用上面的解析器,我们可以用来解析我们的文件(见example).

// 引入`DependenceParser`
var dependenceParser = require( '../lib/dependenceParser.js' );
// 引入我们定义好的解析器
var parser = require( './dependenceRequire.parser.js' );
// 需要解析的文件路径
var target = 'foo/index.js';
// 解析文件的依赖关系,并输出
console.log( dependenceParser.parse( target, parser ) );

最终会输出:

    { list:
       [ '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/index.js',
         '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_a.js',
         '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_b.js',
         '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_c.js' ],
      info:
       { '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/index.js': [ '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_a.js' ],
         '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_a.js':
          [ '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_b.js',
            '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_c.js' ],
         '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_b.js': [],
         '/users/neekey/Dropbox/nodejs/app/dependanceParser/example/foo/mod_c.js': [] } }

其中list为根据文件间的依赖关系构造的文件顺序列表,info为每个文件对应的直接依赖文件列表。

That'all!

License

(The MIT License)

Copyright (c) 2012 Neekey [email protected];

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.