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

logregnginxconfig

v1.0.0

Published

generate Regex From Nginx Config

Downloads

2

Readme

nginx配置正则验证

安装

npm install logregnginxconfig

配置

var  logregnginxconfig = require ('logregnginxconfig');
var logregnginxconfig = function (logFormat) {}

/* @Params: logFormat参数就是标准NGINX配置文件中对应log_format内容 通过logFormat.match() 提取实际配置部分; 优先提取多行NGINX配置 通过单引号提取实际KEY列表 */

if (logFormat == undefined || logFormat == null)
    return null;

示例

const logregnginxconfig = require('logregnginxconfig')//引入logregnginxconfig

const log_sample = `42.110.55.127 - - [17/Jan/2019:16:52:17 +0800] "GET /favicon.ico HTTP/1.1" 45.16.35.141 404 404 570 "http://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" 0.000 -`  //配置 日志样例

const log_format = `log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$status $request_length '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent"';`   //配置推荐的log_format日志格式
const result = logregnginxconfig(log_format)

const generateRegex = new RegExp(result.regex) //生成一个正则

console.log(result);

console.log(log_sample.match(generateRegex))//对正则进行macth操作,分割枚举

/*
console.log(result);运行生成的正则如下:
{ space_err: false,
  err_list: [],
  regex:
   '(\\S*)\\s*-\\s*(\\S*)\\s*\\[(\\d+/\\S+/\\d+:\\d+:\\d+:\\d+)\\s+\\S+\\]\\s*"(\\S+)\\s+(\\S+)\\s+\\S+"\\s*(\\S*)\\s*(\\S*)\\s*(\\S*)\\s*(\\S*)\\s*"(\\S*)"\\s*"([\\S ]*)".*',
  keys:
   [ 'remote_addr',
     'remote_user',
     'time_local',
     'request_method',
     'request_uri',
     'status',
     'request_length',
     'status',
     'body_bytes_sent',
     'http_referer',
     'http_user_agent' ] }

console.log(log_sample.match(generateRegex));代码运行结果如下:
[ '42.110.55.127 - - [17/Jan/2019:16:52:17 +0800] "GET /favicon.ico HTTP/1.1" 45.16.35.141 404 404 570 "http://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" 0.000 -',
  '42.110.55.127',
  '-',
  '17/Jan/2019:16:52:17',
  'GET',
  '/favicon.ico',
  '45.16.35.141',
  '404',
  '404',
  '570',
  'http://example.com/',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
  index: 0,
  input: '42.110.55.127 - - [17/Jan/2019:16:52:17 +0800] "GET /favicon.ico HTTP/1.1" 45.16.35.141 404 404 570 "http://example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" 0.000 -',
  groups: undefined ]
*/