帮酷LOGO
  • 显示原文与译文双语对照的内容
文章标签:JAVA  TERM  PIP  PIPE  RED  Javascript  终端  Reduce  
Pipeable javascript. Quickly filter, map, and reduce from the terminal

  • 源代码名称:pjs
  • 源代码网址:http://www.github.com/danielstjules/pjs
  • pjs源代码文档
  • pjs源代码下载
  • Git URL:
    git://www.github.com/danielstjules/pjs.git
  • Git Clone代码到本地:
    git clone http://www.github.com/danielstjules/pjs
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/danielstjules/pjs
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
  • pjs

    Pipeable JavaScript - 另一种实用工具,如 sed/awk/wc... 但使用 JS ! 从 命令行 中快速过滤。映射和缩小。 采用 pipeable ruby 激发的流式 API 。

    Build Status

    概述

    pyjamas是一个可以接受输入输入或者从文件列表中读取的cli工具。 它的过滤器。映射和reduce选项会以这个顺序运行表达式,并将它的应用到所提供的输入。 表达式本身可以包含字符串中键使用的标识符,prototype将自动绑定到给定的行。 这使你可以以使用一个窗口保存一点字符,而仍然允许你访问所有JS字符串函数。 查看 below的一些示例,看看它们是如何翻译的。

    # Return all lines longer than 5 chars# => lines.filter(function(line) { return line.length> 5; });ls -1 | pjs -f 'length> 5'# Count characters in each line# => lines.map(function(line) { return line.length; });ls -1 | pjs -m 'length'# Uppercase and pad each line# => lines.map(function(line) { return ' ' + line.toUpperCase()"; });ls -1 | pjs -m '"" + toUpperCase()'# Return lines longer than 5 chars, and remove any digits# => lines#. filter(function(line) { return line.length> 5; })#. map(function(line) { return line.replace(/d/g, ''); });ls -1 | pjs -f 'length> 5' -m 'replace(/d/g,"")'

    还可以通过 $ 变量访问当前行和值,并且该工具支持json输出。

    (echo 'foo'&&echo'foobar') | pjs -jm '{name: $, length: length}'[
    {"name":"foo","length":3},
    {"name":"foobar","length":6}
    ]

    pyjamas还包括lodash函数,可以通过 _ 对象访问,并使用 $$ 链接

    echo'hello'| pjs -m '_.upperFirst($)'# Helloecho'please-titleize-this-sentence'| 
    pjs -m '$$.lowerCase().split("").map(_.upperFirst).join("")'# Please Titleize This Sentence

    以及Ramda和点自由样式

    echo'please-titleize-this-sentence'| 
    pjs -m "R.compose(R.replace(/(^|s)w/g, R.toUpper), R.replace(/-/g, ' '))"# Please Titleize This Sentence

    安装

    它可以通过 npm 安装,使用:

    npm install -g pipeable-js

    用法

    Usage: pjs [options] [files.. .]
    Functions and expressions are invoked in the following order:
    filter, map, reduce
    All functions are passed the line ($) and index (i)
    Built-in reduce functions: length, min, max, sum, avg, concat
    Custom reduce expressions accept: prev, curr, i, array
    Includes lodash (_), and can be chained using $$
    Supports Ramda (R) and point-free style
    Options:
     -h, --help output usage information
     -V, --version output the version number
     -i, --ignore ignore empty lines
     -j, --json output as json
     -f, --filter <exp> filter by a boolean expression
     -m, --map <exp> map values using the expression
     -r, --reduce <func|exp> reduce using a function or expression

    示例

    滤波器

    # Print all odd lines# awk 'NR % 2 == 1' filepjs -f 'i % 2 == 0' file# Print all lines greater than 80 chars in length# awk 'length($0)> 80' filepjs -f 'length> 80' file

    映射

    # Remove all digits# tr -d 0-9 <filepjs -m "replace(/d/g, '')" file# Get second item of each line in csv# awk -F"," '{print $2}' filepjs -m 'split(",")[1]' file

    减少

    # Count lines in file# wc -l file# awk 'END { print NR }' filepjs -r length file# Sum all decimal numbers in a file# awk '{ sum += $1 } END { print sum }' file# perl -nle '$sum += $_ } END { print $sum' filepjs -r 'Number(prev) + Number(curr)' file
    pjs -r '(+prev) + (+curr)' file
    pjs -r sum file# Concatenate all lines in multiple files# awk '{printf $0;}' file1 file2# cat file1 file2 | tr -d 'n'pjs -r concat file1 file2

    混合

    # Print the length of the longest line# awk '{ if (length($0)> max) max = length($0) } END { print max }' filepjs -m 'length' -r max file

    比较

    pjs pythonpy pru功能
    语言JavascriptPythonRuby
    流式处理是的有限 [1 ]是的
    实现溪流Iterables生成器
    轻松JSON输出是的不是不是
    WebscaleTM是的不是不是

    [1] 无法执行"-f日志文件| py -x x"



    文章标签:JAVA  Javascript  RED  TERM  终端  PIP  PIPE  Reduce  

    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语