JavaScript 函數的執行階段 2.0 CloudFront 功能 - Amazon CloudFront

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

JavaScript 函數的執行階段 2.0 CloudFront 功能

CloudFront 功能 JavaScript 運行時環境與 ECMAScript(ES)5.1 版兼容,並且還支持 ES 版本 6 到 12 的某些功能。它還提供了一些不屬於 ES 規格的非標準方法。以下主題列出此執行期支援的所有功能。

核心功能

支援 ES 的以下核心功能。

類型

支援所有 ES 5.1 類型。這包括布林值、數字、字串、物件、陣列、函數和常規表達式。

運算子

支援所有 ES 5.1 運算子。

支援 ES 7 指數運算子 (**)。

陳述式

支援下列 ES 5.1 陳述式:

  • break

  • catch

  • continue

  • do-while

  • else

  • finally

  • for

  • for-in

  • if

  • label

  • return

  • switch

  • throw

  • try

  • var

  • while

支援以下 ES 6 陳述式:

  • async

  • await

  • const

  • let

    注意

    asyncawaitconst、和let是 JavaScript 執行階段 2.0 中的新功能。

文字

支援 ES 6 範本文字:多行字串、表達式插補和巢狀範本。

函數

支援所有 ES 5.1 函數功能。

支援 ES 6 箭頭函數,支援 ES 6 剩餘參數語法。

Unicode

來源文字和字串常值可以包含 Unicode 編碼的字元。也支援由六個字元 (例如 \uXXXX) 組成的 Unicode 字碼指標逸出序列。

嚴格模式

函數按預設會在嚴格模式下運作,因此您不需要在函數程式碼中新增 use strict 陳述式。無法對此進行變更。

基本物件

支援 ES 的以下基本物件。

物件

支援物件上的以下 ES 5.1 方法:

  • Object.create()( 不含屬性清單)

  • Object.defineProperties()

  • Object.defineProperty()

  • Object.freeze()

  • Object.getOwnPropertyDescriptor()

  • Object.getOwnPropertyDescriptors()

  • Object.getOwnPropertyNames()

  • Object.getPrototypeOf()

  • Object.isExtensible()

  • Object.isFrozen()

  • Object.isSealed()

  • Object.keys()

  • Object.preventExtensions()

  • Object.seal()

支援物件上的以下 ES 6 方法:

  • Object.assign()

支援物件上的以下 ES 8 方法:

  • Object.entries()

  • Object.values()

支援以下針對物件的 ES 5.1 原型方法:

  • Object.prototype.hasOwnProperty()

  • Object.prototype.isPrototypeOf()

  • Object.prototype.propertyIsEnumerable()

  • Object.prototype.toString()

  • Object.prototype.valueOf()

支援以下針對物件的 ES 6 原型方法:

  • Object.prototype.is()

  • Object.prototype.setPrototypeOf()

字串

支援以下針對字串的 ES 5.1 方法:

  • String.fromCharCode()

支援以下針對字串的 ES 6 方法:

  • String.fromCodePoint()

支援以下針對字串的 ES 5.1 原型方法:

  • String.prototype.charAt()

  • String.prototype.concat()

  • String.prototype.indexOf()

  • String.prototype.lastIndexOf()

  • String.prototype.match()

  • String.prototype.replace()

  • String.prototype.search()

  • String.prototype.slice()

  • String.prototype.split()

  • String.prototype.substr()

  • String.prototype.substring()

  • String.prototype.toLowerCase()

  • String.prototype.trim()

  • String.prototype.toUpperCase()

支援以下針對字串的 ES 6 原型方法:

  • String.prototype.codePointAt()

  • String.prototype.endsWith()

  • String.prototype.includes()

  • String.prototype.repeat()

  • String.prototype.startsWith()

支援以下針對字串的 ES 8 原型方法:

  • String.prototype.padStart()

  • String.prototype.padEnd()

支援以下針對字串的 ES 9 原型方法:

  • String.prototype.trimStart()

  • String.prototype.trimEnd()

支援以下針對字串的 ES 12 原型方法:

  • String.prototype.replaceAll()

    注意

    String.prototype.replaceAll()在 JavaScript 執行階段 2.0 中是新的。

Number

ALLES 支持 5 個數字。

支援以下 ES 6 數字屬性:

  • Number.EPSILON

  • Number.MAX_SAFE_INTEGER

  • Number.MIN_SAFE_INTEGER

  • Number.MAX_VALUE

  • Number.MIN_VALUE

  • Number.NaN

  • Number.NEGATIVE_INFINITY

  • Number.POSITIVE_INFINITY

支援數字上的以下 ES 6 方法:

  • Number.isFinite()

  • Number.isInteger()

  • Number.isNaN()

  • Number.isSafeInteger()

  • Number.parseInt()

  • Number.parseFloat()

支援以下針對數字的 ES 5.1 原型方法:

  • Number.prototype.toExponential()

  • Number.prototype.toFixed()

  • Number.prototype.toPrecision()

支援 ES 12 數字分隔符號。

注意

ES 12 數字分隔符是 JavaScript 運行時 2.0 中的新功能。

內建物件

支援 ES 的以下內建物件。

數學

支援所有 ES 5.1 數學方法。

注意

在 CloudFront Functions 執行階段環境中,Math.random()導入會使用BSDarc4random內建的「開啟」與函數執行時的時間戳記。

支援以下 ES 6 數學屬性:

  • Math.E

  • Math.LN10

  • Math.LN2

  • Math.LOG10E

  • Math.LOG2E

  • Math.PI

  • Math.SQRT1_2

  • Math.SQRT2

支援以下 ES 6 數學方法:

  • Math.abs()

  • Math.acos()

  • Math.acosh()

  • Math.asin()

  • Math.asinh()

  • Math.atan()

  • Math.atan2()

  • Math.atanh()

  • Math.cbrt()

  • Math.ceil()

  • Math.clz32()

  • Math.cos()

  • Math.cosh()

  • Math.exp()

  • Math.expm1()

  • Math.floor()

  • Math.fround()

  • Math.hypot()

  • Math.imul()

  • Math.log()

  • Math.log1p()

  • Math.log2()

  • Math.log10()

  • Math.max()

  • Math.min()

  • Math.pow()

  • Math.random()

  • Math.round()

  • Math.sign()

  • Math.sinh()

  • Math.sin()

  • Math.sqrt()

  • Math.tan()

  • Math.tanh()

  • Math.trunc()

日期

支援所有 ES 5.1 Date 功能。

注意

基於安全考量,在單一函數執行的生命週期內,Date 始終返回相同的值 (函數的開始時間)。如需詳細資訊,請參閱 限制功能

函數

支援以下 ES 5.1 原型方法:

  • Function.prototype.apply()

  • Function.prototype.bind()

  • Function.prototype.call()

不支援函數建構子。

常規表達式

支援所有 ES 5.1 常規表達式功能。常規表達式語言與 Perl 相容。

支援以下 ES 5.1 原型存取子屬性:

  • RegExp.prototype.global

  • RegExp.prototype.ignoreCase

  • RegExp.protoype.multiline

  • RegExp.protoype.source

  • RegExp.prototype.sticky

  • RegExp.prototype.flags

    注意

    RegExp.prototype.sticky並且RegExp.prototype.flags是 JavaScript運行時 2.0 中的新功能。

支援以下 ES 5.1 原型方法:

  • RegExp.prototype.exec()

  • RegExp.prototype.test()

  • RegExp.prototype.toString()

  • RegExp.prototype[@@replace]()

  • RegExp.prototype[@@split]()

    注意

    RegExp.prototype[@@split]()在 JavaScript執行階段 2.0 中是新的。

支援以下 ES 5.1 執行個體屬性:

  • lastIndex

支援 ES 9 命名的擷取群組。

JSON

支援以下 ES 5.1 方法:

  • JSON.parse()

  • JSON.stringify()

陣列

支援陣列上的以下 ES 5.1 方法:

  • Array.isArray()

支援陣列上的以下 ES 6 方法:

  • Array.of()

支援以下 ES 5.1 原型方法:

  • Array.prototype.concat()

  • Array.prototype.every()

  • Array.prototype.filter()

  • Array.prototype.forEach()

  • Array.prototype.indexOf()

  • Array.prototype.join()

  • Array.prototype.lastIndexOf()

  • Array.prototype.map()

  • Array.prototype.pop()

  • Array.prototype.push()

  • Array.prototype.reduce()

  • Array.prototype.reduceRight()

  • Array.prototype.reverse()

  • Array.prototype.shift()

  • Array.prototype.slice()

  • Array.prototype.some()

  • Array.prototype.sort()

  • Array.prototype.splice()

  • Array.prototype.unshift()

支援以下 ES 6 原型方法

  • Array.prototype.copyWithin()

  • Array.prototype.fill()

  • Array.prototype.find()

  • Array.prototype.findIndex()

支援以下 ES 7 原型方法:

  • Array.prototype.includes()

類型陣列

支援以下 ES 6 類型陣列建構子:

  • Float32Array

  • Float64Array

  • Int8Array

  • Int16Array

  • Int32Array

  • Uint8Array

  • Uint8ClampedArray

  • Uint16Array

  • Uint32Array

支援以下 ES 6 方法:

  • TypedArray.from()

  • TypedArray.of()

    注意

    TypedArray.from()並且TypedArray.of()是 JavaScript 運行時 2.0 中的新功能。

支援以下 ES 6 原型方法:

  • TypedArray.prototype.copyWithin()

  • TypedArray.prototype.every()

  • TypedArray.prototype.fill()

  • TypedArray.prototype.filter()

  • TypedArray.prototype.find()

  • TypedArray.prototype.findIndex()

  • TypedArray.prototype.forEach()

  • TypedArray.prototype.includes()

  • TypedArray.prototype.indexOf()

  • TypedArray.prototype.join()

  • TypedArray.prototype.lastIndexOf()

  • TypedArray.prototype.map()

  • TypedArray.prototype.reduce()

  • TypedArray.prototype.reduceRight()

  • TypedArray.prototype.reverse()

  • TypedArray.prototype.some()

  • TypedArray.prototype.set()

  • TypedArray.prototype.slice()

  • TypedArray.prototype.sort()

  • TypedArray.prototype.subarray()

  • TypedArray.prototype.toString()

    注意

    TypedArray.prototype.every()、、TypedArray.prototype.fill()TypedArray.prototype.filter()TypedArray.prototype.find()、、TypedArray.prototype.findIndex()TypedArray.prototype.forEach()TypedArray.prototype.includes()、、TypedArray.prototype.indexOf()TypedArray.prototype.join()、、TypedArray.prototype.lastIndexOf()TypedArray.prototype.map()TypedArray.prototype.reduce()TypedArray.prototype.reduceRight()TypedArray.prototype.reverse()、和TypedArray.prototype.some()是 JavaScript 執行階段 2.0 中的新功能。

ArrayBuffer

支援下列 ES 6 方法: ArrayBuffer

  • isView()

支持以下 ES 6 原型方法: ArrayBuffer

  • ArrayBuffer.prototype.slice()

Promise

支援以下針對 Promise 的 ES 6 方法:

  • Promise.all()

  • Promise.allSettled()

  • Promise.any()

  • Promise.reject()

  • Promise.resolve()

  • Promise.race()

    注意

    Promise.all()Promise.allSettled()Promise.any()、和Promise.race()是 JavaScript 執行階段 2.0 中的新功能。

支援以下針對 Promise 的 ES 6 原型方法:

  • Promise.prototype.catch()

  • Promise.prototype.finally()

  • Promise.prototype.then()

DataView

支援以下 ES 6 原型方法:

  • DataView.prototype.getFloat32()

  • DataView.prototype.getFloat64()

  • DataView.prototype.getInt16()

  • DataView.prototype.getInt32()

  • DataView.prototype.getInt8()

  • DataView.prototype.getUint16()

  • DataView.prototype.getUint32()

  • DataView.prototype.getUint8()

  • DataView.prototype.setFloat32()

  • DataView.prototype.setFloat64()

  • DataView.prototype.setInt16()

  • DataView.prototype.setInt32()

  • DataView.prototype.setInt8()

  • DataView.prototype.setUint16()

  • DataView.prototype.setUint32()

  • DataView.prototype.setUint8()

    注意

    所有數據視圖 ES 6 原型方法在 JavaScript運行時 2.0 中都是新的。

符號

支援以下 ES 6 方法:

  • Symbol.for()

  • Symbol.keyfor()

    注意

    所有符號 ES 6 方法在 JavaScript 運行時 2.0 中都是新的。

文字解碼器

支援以下原型方法:

  • TextDecoder.prototype.decode()

支援以下原型存取子屬性:

  • TextDecoder.prototype.encoding

  • TextDecoder.prototype.fatal

  • TextDecoder.prototype.ignoreBOM

文字編碼器

支援以下原型方法:

  • TextEncoder.prototype.encode()

  • TextEncoder.prototype.encodeInto()

錯誤類型

支援以下錯誤物件:

  • Error

  • EvalError

  • InternalError

  • RangeError

  • ReferenceError

  • SyntaxError

  • TypeError

  • URIError

全域變數

支援 globalThis 物件。

支援以下 ES 5.1 全局函數:

  • decodeURI()

  • decodeURIComponent()

  • encodeURI()

  • encodeURIComponent()

  • isFinite()

  • isNaN()

  • parseFloat()

  • parseInt()

支援以下 ES 6 全域函數:

  • atob()

  • btoa()

    注意

    atob()並且btoa()是 JavaScript 運行時 2.0 中的新功能。

支援以下全局常數:

  • NaN

  • Infinity

  • undefined

  • arguments

內建模組

支援以下內建模組:

緩衝區

此模組提供以下方法:

  • Buffer.alloc(size[, fill[, encoding]])

    配置 Buffer

    • size:緩衝區大小。輸入整數。

    • fill:選用。輸入字串、Buffer、Uint8Array 或整數。預設值為 0

    • encoding:選用。當 fill 為字串,請輸入以下其中一項:utf8hexbase64base64url。預設值為 utf8

  • Buffer.allocUnsafe(size)

    配置一個未初始化的 Buffer

    • size:輸入整數。

  • Buffer.byteLength(value[, encoding])

    返回值的長度,以位元組為單位。

    • value:字串、、Buffer TypedArray、資料檢視或陣列緩衝區。

    • encoding:選用。當 value 為字串,請輸入以下其中一項:utf8hexbase64base64url。預設值為 utf8

  • Buffer.compare(buffer1, buffer2)

    比較兩個 Buffer 以協助對陣列進行排序。如果兩者相同則傳回 0,如果 buffer1 在前面則傳回 -1,或如果 buffer2 在前面則傳回 1

    • buffer1:輸入 Buffer

    • buffer2:輸入不同的 Buffer

  • Buffer.concat(list[, totalLength])

    連接多個 Buffer。如果沒有則傳回 0。最多傳回 totalLength

    • list:輸入 Buffer 的清單。請注意,這將被截斷為 totalLength

    • totalLength:選用。輸入不帶正負號的整數。如果清單為空白,則使用清單中 Buffer 執行個體的總和。

  • Buffer.from(array)

    從陣列建立 Buffer

    • array: 輸入從 0255 的位元組陣列。

  • Buffer.from(arrayBuffer, byteOffset[, length]))

    arrayBuffer 建立檢視,從偏移值 byteOffset 開始,長度為 length

    • arrayBuffer:輸入 Buffer 陣列。

    • byteOffset:輸入整數。

    • length:選用。輸入整數。

  • Buffer.from(buffer)

    建立 Buffer 的複本。

    • buffer:輸入 Buffer

  • Buffer.from(object[, offsetOrEncoding[, length]])

    從物件建立 Buffer。如果 valueOf() 不等於物件,則傳回 Buffer.from(object.valueOf(), offsetOrEncoding, length)

    • object:輸入物件。

    • offsetOrEncoding:選用。輸入整數或編碼字串。

    • length:選用。輸入整數。

  • Buffer.from(string[, encoding])

    從字串建立一個 Buffer

    • string:輸入字串。

    • encoding:選用。輸入以下其中之一:utf8hexbase64base64url。預設值為 utf8

  • Buffer.isBuffer(object)

    檢查 object 是否為緩衝區。傳回 truefalse

    • object:輸入物件。

  • Buffer.isEncoding(encoding)

    檢查是否支援 encoding。傳回 truefalse

    • encoding:選用。輸入以下其中之一:utf8hexbase64base64url。預設值為 utf8

此模組提供以下緩衝區原型方法:

  • Buffer.prototype.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])

    Buffer 與目標比較。如果兩者相同則傳回 0,如果 buffer 在前面則傳回 1,或如果 target 在前面則傳回 -1

    • target:輸入 Buffer

    • targetStart:選用。輸入整數。預設值為 0。

    • targetEnd:選用。輸入整數。預設值為 target 長度。

    • sourceStart:選用。輸入整數。預設值為 0。

    • sourceEnd:選用。輸入整數。預設值為 Buffer 長度。

  • Buffer.prototype.copy(target[, targetStart[, sourceStart[, sourceEnd]]])

    將緩衝區複製到 target

    • target:輸入 BufferUint8Array

    • targetStart:選用。輸入整數。預設值為 0。

    • sourceStart:選用。輸入整數。預設值為 0。

    • sourceEnd:選用。輸入整數。預設值為 Buffer 長度。

  • Buffer.prototype.equals(otherBuffer)

    BufferotherBuffer 比較。傳回 truefalse

    • otherBuffer:輸入字串。

  • Buffer.prototype.fill(value[, offset[, end][, encoding])

    value 填入 Buffer

    • value:輸入字串、Buffer 或整數。

    • offset:選用。輸入整數。

    • end:選用。輸入整數。

    • encoding:選用。輸入以下其中之一:utf8hexbase64base64url。預設值為 utf8

  • Buffer.prototype.includes(value[, byteOffset][, encoding])

    搜尋 Buffer 中的 value。傳回 truefalse

    • value:輸入字串、BufferUint8Array、或整數。

    • byteOffset:選用。輸入整數。

    • encoding:選用。輸入以下其中之一:utf8hexbase64base64url。預設值為 utf8

  • Buffer.prototype.indexOf(value[, byteOffset][, encoding])

    首先搜尋 Buffer 中的第一個 value。如果找到了,則傳回 index;如果找不到,則傳回 -1

    • value: 輸入字串、Buffer、Unit8Array 或 0 到 255 之間的整數。

    • byteOffset:選用。輸入整數。

    • encoding:選用。如果 value 是字串,請輸入以下其中一項:utf8hexbase64base64url。預設值為 utf8

  • Buffer.prototype.lastIndexOf(value[, byteOffset][, encoding])

    搜尋 Buffer 中的最後一個 value。如果找到了,則傳回 index;如果找不到,則傳回 -1

    • value: 輸入字串、Buffer、Unit8Array 或 0 到 255 之間的整數。

    • byteOffset:選用。輸入整數。

    • encoding:選用。如果 value 是字串,請輸入以下其中一項:utf8hexbase64base64url。預設值為 utf8

  • Buffer.prototype.readInt8(offset)

    Buffer 的偏移值 offset 讀取 Int8

    • offset:輸入整數。

  • Buffer.prototype.readIntBE(offset, byteLength)

    Buffer 的偏移值 offset 讀取大端序 Int

    • offset:輸入整數。

    • byteLength:選用。輸入從 16 的整數。

  • Buffer.prototype.readInt16BE(offset)

    Buffer 的偏移值 offset 讀取大端序 Int16

    • offset:輸入整數。

  • Buffer.prototype.readInt32BE(offset)

    Buffer 的偏移值 offset 讀取大端序 Int32

    • offset:輸入整數。

  • Buffer.prototype.readIntLE(offset, byteLength)

    Buffer 的偏移值 offset 讀取小端序 Int

    • offset:輸入整數。

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.readInt16LE(offset)

    Buffer 的偏移值 offset 讀取小端序 Int16

    • offset:輸入整數。

  • Buffer.prototype.readInt32LE(offset)

    Buffer 的偏移值 offset 讀取小端序 Int32

    • offset:輸入整數。

  • Buffer.prototype.readUInt8(offset)

    Buffer 的偏移值 offset 讀取 UInt8

    • offset:輸入整數。

  • Buffer.prototype.readUIntBE(offset, byteLength)

    Buffer 的偏移值 offset 讀取大端序 UInt

    • offset:輸入整數。

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.readUInt16BE(offset)

    Buffer 的偏移值 offset 讀取大端序 UInt16

    • offset:輸入整數。

  • Buffer.prototype.readUInt32BE(offset)

    Buffer 的偏移值 offset 讀取大端序 UInt32

    • offset:輸入整數。

  • Buffer.prototype.readUIntLE(offset, byteLength)

    Buffer 的偏移值 offset 讀取小端序 UInt

    • offset:輸入整數。

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.readUInt16LE(offset)

    Buffer 的偏移值 offset 讀取小端序 UInt16

    • offset:輸入整數。

  • Buffer.prototype.readUInt32LE(offset)

    Buffer 的偏移值 offset 讀取小端序 UInt32

    • offset:輸入整數。

  • Buffer.prototype.readDoubleBE([offset])

    Buffer 的偏移值 offset 讀取 64 位元大端序雙精度浮點數。

    • offset:選用。輸入整數。

  • Buffer.prototype.readDoubleLE([offset])

    Buffer 的偏移值 offset 讀取 64 位元小端序雙精度浮點數。

    • offset:選用。輸入整數。

  • Buffer.prototype.readFloatBE([offset])

    Buffer 的偏移值 offset 讀取 32 位元大端序浮點數。

    • offset:選用。輸入整數。

  • Buffer.prototype.readFloatLE([offset])

    Buffer 的偏移值 offset 讀取 32 位元小端序浮點數。

    • offset:選用。輸入整數。

  • Buffer.prototype.subarray([start[, end]])

    傳回 Buffer 的副本,並使用新的 startend 偏移和裁剪。

    • start:選用。輸入整數。預設值為 0。

    • end:選用。輸入整數。預設值為緩衝區長度。

  • Buffer.prototype.swap16()

    交換 Buffer 陣列的位元組順序,將其視為 16 位元數字的陣列。Buffer 的長度必須是 2 的倍數,否則您將收到錯誤訊息。

  • Buffer.prototype.swap32()

    交換 Buffer 陣列的位元組順序,將其視為 32 位元數字的陣列。Buffer 的長度必須是 4 的倍數,否則您將收到錯誤訊息。

  • Buffer.prototype.swap64()

    交換 Buffer 陣列的位元組順序,將其視為 64 位元數字的陣列。Buffer 的長度必須是 8 的倍數,否則您將收到錯誤訊息。

  • Buffer.prototype.toJSON()

    返回Buffer為JSON.

  • Buffer.prototype.toString([encoding[, start[, end]]])

    Bufferstartend 轉換為編碼字串。

    • encoding:選用。輸入以下其中之一:utf8hexbase64base64url。預設值為 utf8

    • start:選用。輸入整數。預設值為 0。

    • end:選用。輸入整數。預設值為緩衝區長度。

  • Buffer.prototype.write(string[, offset[, length]][, encoding])

    如果空間足夠,則將編碼 string 寫入 Buffer,如果空間不足,則寫入被截斷的 string

    • string:輸入字串。

    • offset:選用。輸入整數。預設值為 0。

    • length:選用。輸入整數。預設值是字串的長度。

    • encoding:選用。選擇性地輸入以下其中一項:utf8hexbase64base64url。預設值為 utf8

  • Buffer.prototype.writeInt8(value, offset, byteLength)

    Int8 value (長度為 byteLength) 寫入 Buffer 的偏移值 offset

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeIntBE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeInt16BE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeInt32BE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeIntLE(offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • offset:輸入整數。

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeInt16LE(offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • offset:輸入整數。

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeInt32LE(offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • offset:輸入整數。

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUInt8(value, offset, byteLength)

    UInt8 value (長度為 byteLength) 寫入 Buffer 的偏移值 offset

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUIntBE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUInt16BE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUInt32BE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUIntLE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUInt16LE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeUInt32LE(value, offset, byteLength)

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • value:輸入整數。

    • offset:輸入整數

    • byteLength:輸入從 16 的整數。

  • Buffer.prototype.writeDoubleBE(value, [offset])

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:選用。輸入整數。預設值為 0。

  • Buffer.prototype.writeDoubleLE(value, [offset])

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • value:輸入整數。

    • offset:選用。輸入整數。預設值為 0。

  • Buffer.prototype.writeFloatBE(value, [offset])

    value 寫入 Buffer 的偏移值 offset,使用大端序。

    • value:輸入整數。

    • offset:選用。輸入整數。預設值為 0。

  • Buffer.prototype.writeFloatLE(value, [offset])

    value 寫入 Buffer 的偏移值 offset,使用小端序。

    • value:輸入整數。

    • offset:選用。輸入整數。預設值為 0。

支援以下執行個體方法:

  • buffer[index]

    取得和設定 Buffer 中偏移值 index 的八位元組 (位元組)。

    • 取得從 0255 的數字。或設定一個從 0255 的數字。

支援以下執行個體屬性:

  • buffer

    取得緩衝區的 ArrayBuffer 物件。

  • byteOffset

    取得緩衝區 Arraybuffer 物件的 byteOffset

  • length

    取得緩衝區位元組計數。

注意

所有緩衝區模塊方法在 JavaScript 運行時 2.0 中都是新的。

查詢字串

注意

CloudFront Functions 事件物件會自動為您解析URL查詢字串。這意味著在大多數情況下,您不需要使用此模組。

查詢字串模組 (querystring) 提供剖析和格式化URL查詢字串的方法。您可以使用 require('querystring') 加載模組。此模組提供下列方法。

querystring.escape(string)

URL-編碼給定的string,返回一個轉義的查詢字符串。該方法由 querystring.stringify() 使用,並且不應直接使用。

querystring.parse(string[, separator[, equal[, options]]])

剖析查詢字串 (string) 並傳回物件。

separator 參數是用來分隔查詢字串中的鍵/值對的子字串。其在預設情況下為 &

equal 參數是用來分隔查詢字串中的鍵和值的子字串。其在預設情況下為 =

options 參數是具有下列鍵的物件:

decodeURIComponent function

解碼查詢字串中百分比編碼字元的函數。其在預設情況下為 querystring.unescape()

maxKeys number

要剖析的鍵的最大數量。其在預設情況下為 1000。使用 0 的值移除計數鍵的限制。

根據預設,會假設查詢字串中的百分比編碼字元使用 -8 編碼。UTF無效的 UTF -8 個序列被替U+FFFD換為替換字符。

例如,對於下列查詢字串:

'name=value&abc=xyz&abc=123'

querystring.parse() 的返回值是:

{ name: 'value', abc: ['xyz', '123'] }

querystring.decode() 是 的別名。querystring.parse()

querystring.stringify(object[, separator[, equal[, options]]])

序列化 object 並傳回查詢字串。

separator 參數是用來分隔查詢字串中的鍵/值對的子字串。其在預設情況下為 &

equal 參數是用來分隔查詢字串中的鍵和值的子字串。其在預設情況下為 =

options 參數是具有下列鍵的物件:

encodeURIComponent function

用於在查詢字串中將URL不安全字元轉換為百分比編碼的函數。其在預設情況下為 querystring.escape()

根據預設,在查詢字串中需要百分比編碼的字元會編碼為 -8。UTF若要使用不同的編碼,請指定 encodeURIComponent 選項。

例如,對於以下程式碼:

querystring.stringify({ name: 'value', abc: ['xyz', '123'], anotherName: '' });

返回值是:

'name=value&abc=xyz&abc=123&anotherName='

querystring.encode()querystring.stringify() 的別名。

querystring.unescape(string)

解碼給定的URL百分比編碼字符string,返回一個未轉義的查詢字符串。此方法由 querystring.parse() 使用,並且不應直接使用。

加密

加密模塊(crypto)提供標準的散列和基於哈希的消息身份驗證代碼(HMAC)助手。您可以使用 require('crypto') 加載模組。

雜湊方法

crypto.createHash(algorithm)

建立並傳回雜湊物件,藉助此物件,您可以使用給定的演算法產生雜湊摘要:md5sha1sha256

hash.update(data)

使用給定的 data 更新雜湊內容。

hash.digest([encoding])

計算使用 hash.update() 傳遞的所有資料的摘要。編碼可以是 hexbase64base64url

HMAC方法

crypto.createHmac(algorithm, secret key)

建立並傳回使用指定algorithm與的HMAC物件secret key。演算法可以是 md5sha1sha256

hmac.update(data)

更新與給定的HMAC內容data

hmac.digest([encoding])

計算使用 hmac.update() 傳遞的所有資料的摘要。編碼可以是 hexbase64base64url

限制功能

基於安全考量,下列 JavaScript 語言功能不受支援或受限制。

動態程式碼評估

不支援動態程式碼評估。如果嘗試此評估,eval()Function 建構子都會丟出錯誤。例如,const sum = new Function('a', 'b', 'return a + b') 丟出錯誤。

計時器

不支援 setTimeout()setImmediate()clearTimeout() 函數。在函數執行期間未推遲或產生任何佈建。您的函數必須同步執行方可完成。

日期和時間戳記

基於安全考量,無法存取高解析度計時器。查詢當前時間的所有 Date 方法始終在單個函數執行的生命週期內返回相同的值。返回的時間戳記是函數開始執行的時間。因此,您無法測量函數中的經過時間。

檔案系統存取

沒有檔案系統存取權。例如,沒有類似 Node.js 中的檔案系統存取 fs 模組。

程序存取

沒有進程訪問權限。例如,沒有像 Node.js 中那樣處理信息訪問的process全局對象。

環境變數

無法存取環境變數。相反,您可以使用 CloudFront KeyValueStore為 CloudFront Functions 建立索引鍵值對的集中式資料存放區。 CloudFront KeyValueStore 啟用動態更新您的組態資料,而不需要部署程式碼變更。如需詳細資訊,請參閱Amazon CloudFront KeyValueStore

網路存取

不支援網路呼叫。例如XHR,不支援、HTTP (S) 和通訊端。