1. 程式人生 > >《Nginx官方文件》關於nginScript

《Nginx官方文件》關於nginScript

關於nginScript

nginScript是允許在 httpstream 中實現位置和變數處理程式的JavaScript語言的子集 。nginScript建立符合 ECMAScript 5.1 和一些 ECMAScript 6 副檔名。合規性仍在不斷髮展。

目前支援的是什麼

  • 布林值,數字,字串,物件,陣列,函式和正則表示式
  • ES5.1運算子,ES7求冪運算子
  • ES5.1宣告:var,if, else,switch,for, for in,while, do while,break, continue,return,try, catch,throw,finally
  • ES6 Number及其 Math屬性和方法
  • String 方法:
    • ES5.1:fromCharCode,concat, slice,substring, substr,charAt, charCodeAt,indexOf, lastIndexOf,toLowerCase, toUpperCase,trim, search,match,split,replace
    • ES6:fromCodePoint,codePointAt, includes,startsWith, endsWith,repeat
    • 非標:fromUTF8,toUTF8, fromBytes,toBytes
  • Object 方法:
    • ES5.1: create(無屬性列表的支援), keys, defineProperty, defineProperties, getOwnPropertyDescriptor, getPrototypeOf, hasOwnProperty, isPrototypeOf, preventExtensions, isExtensible, freeze, isFrozen,seal,isSealed
  • Array 方法:
    • ES5.1: isArray,slice,splice, push,pop,unshift, shift,reverse,sort, join,concat,indexOf, lastIndexOf,forEach, some,every,filter,map,reduce,reduceRight
    • ES6: of,fill,find,findIndex
    • ES7: includes
  • ES5.1 Function方法: call,apply,bind
  • ES5.1 RegExp方法: test,exec
  • ES5.1 Date方法
  • ES5.1 全域性函式: isFinite,isNaN, parseFloat,parseInt, decodeURI,decodeURIComponent, encodeURI,encodeURIComponent

什麼還不支援

  • ES6 let和const宣告
  • 標籤
  • arguments 排列
  • eval 功能
  • JSON 目的
  • Error 目的
  • setTimeout,setInterval, setImmediate功能非整數分數(.235),二進位制(0b0101),八進位制(0o77)文字

下載並安裝

nginScript有兩個模組:

這兩個模組都不是預設構建的,它們應該是從原始檔中編譯的或者是作為一個Linux軟體包來安裝的。

安裝為Linux軟體包

對於Linux,可以使用nginScript模組

  • nginx-module-njs  —nginScript 動態 模組
  • nginx-module-njs-dbg — 除錯nginx-module-njs包的符號

從源頭建設

可以使用以下命令克隆具有nginScript源的儲存 :(需要 Mercurial 客戶端):

hg clone http://hg.nginx.org/njs

然後使用–add-module配置引數編譯模組 :

./configure --add-module=path-to-njs/nginx

模組也可以構建為 動態 的:

./configure --add-dynamic-module=path-to-njs/nginx