本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CloudFront Functions JavaScript 執行期環境符合 ECMAScript (ES) 版本 5.1
核心功能
支援 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
注意
async
JavaScript 執行期 2.0let
支援await
、const
、 和 。await
只能在async
函數內使用。不支援引async
數和關閉。
-
- 文字
-
支援 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
-
支援所有 ES 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()
實作會使用植入函數執行時間戳記的 OpenBSDarc4random
。支援以下 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
-
支援以下針對 ArrayBuffer 的 ES 6 方法:
-
isView()
支援以下針對 ArrayBuffer 的 ES 6 原型方法:
-
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()
注意
所有 DataView 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
為字串,請輸入以下其中一項:utf8
、hex
、base64
、base64url
。預設值為utf8
。
-
-
Buffer.allocUnsafe(size)
配置一個未初始化的
Buffer
。-
size
:輸入整數。
-
-
Buffer.byteLength(value[, encoding])
返回值的長度,以位元組為單位。
-
value
: 字串、Buffer
、TypedArray、DataView 或 ArrayBuffer。 -
encoding
:選用。當value
為字串,請輸入以下其中一項:utf8
、hex
、base64
、base64url
。預設值為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
: 輸入從0
到255
的位元組陣列。
-
-
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
:選用。輸入以下其中之一:utf8
、hex
、base64
、base64url
。預設值為utf8
。
-
-
Buffer.isBuffer(object)
檢查
object
是否為緩衝區。傳回true
或false
。-
object
:輸入物件。
-
-
Buffer.isEncoding(encoding)
檢查是否支援
encoding
。傳回true
或false
。-
encoding
:選用。輸入以下其中之一:utf8
、hex
、base64
、base64url
。預設值為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
:輸入Buffer
或Uint8Array
。 -
targetStart
:選用。輸入整數。預設值為 0。 -
sourceStart
:選用。輸入整數。預設值為 0。 -
sourceEnd
:選用。輸入整數。預設值為Buffer
長度。
-
-
Buffer.prototype.equals(otherBuffer)
將
Buffer
與otherBuffer
比較。傳回true
或false
。-
otherBuffer
:輸入字串。
-
-
Buffer.prototype.fill(value[, offset[, end][, encoding])
以
value
填入Buffer
。-
value
:輸入字串、Buffer
或整數。 -
offset
:選用。輸入整數。 -
end
:選用。輸入整數。 -
encoding
:選用。輸入以下其中之一:utf8
、hex
、base64
、base64url
。預設值為utf8
。
-
-
Buffer.prototype.includes(value[, byteOffset][, encoding])
搜尋
Buffer
中的value
。傳回true
或false
。-
value
:輸入字串、Buffer
、Uint8Array
、或整數。 -
byteOffset
:選用。輸入整數。 -
encoding
:選用。輸入以下其中之一:utf8
、hex
、base64
、base64url
。預設值為utf8
。
-
-
Buffer.prototype.indexOf(value[, byteOffset][, encoding])
首先搜尋
Buffer
中的第一個value
。如果找到了,則傳回index
;如果找不到,則傳回-1
。-
value
: 輸入字串、Buffer
、Unit8Array 或 0 到 255 之間的整數。 -
byteOffset
:選用。輸入整數。 -
encoding
:選用。如果value
是字串,請輸入以下其中一項:utf8
、hex
、base64
、base64url
。預設值為utf8
。
-
-
Buffer.prototype.lastIndexOf(value[, byteOffset][, encoding])
搜尋
Buffer
中的最後一個value
。如果找到了,則傳回index
;如果找不到,則傳回-1
。-
value
: 輸入字串、Buffer
、Unit8Array 或 0 到 255 之間的整數。 -
byteOffset
:選用。輸入整數。 -
encoding
:選用。如果value
是字串,請輸入以下其中一項:utf8
、hex
、base64
、base64url
。預設值為utf8
。
-
-
Buffer.prototype.readInt8(offset)
從
Buffer
的偏移值offset
讀取Int8
。-
offset
:輸入整數。
-
-
Buffer.prototype.readIntBE(offset, byteLength)
從
Buffer
的偏移值offset
讀取大端序Int
。-
offset
:輸入整數。 -
byteLength
:選用。輸入從1
到6
的整數。
-
-
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
:輸入從1
到6
的整數。
-
-
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
:輸入從1
到6
的整數。
-
-
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
:輸入從1
到6
的整數。
-
-
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
的副本,並使用新的start
和end
偏移和裁剪。-
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()
以 JSON 格式傳回
Buffer
。 -
Buffer.prototype.toString([encoding[, start[, end]]])
將
Buffer
從start
到end
轉換為編碼字串。-
encoding
:選用。輸入以下其中之一:utf8
、hex
、base64
或base64url
。預設值為utf8
。 -
start
:選用。輸入整數。預設值為 0。 -
end
:選用。輸入整數。預設值為緩衝區長度。
-
-
Buffer.prototype.write(string[, offset[, length]][, encoding])
如果空間足夠,則將編碼
string
寫入Buffer
,如果空間不足,則寫入被截斷的string
。-
string
:輸入字串。 -
offset
:選用。輸入整數。預設值為 0。 -
length
:選用。輸入整數。預設值是字串的長度。 -
encoding
:選用。選擇性地輸入以下其中一項:utf8
、hex
、base64
或base64url
。預設值為utf8
。
-
-
Buffer.prototype.writeInt8(value, offset, byteLength)
將
Int8
value
(長度為byteLength
) 寫入Buffer
的偏移值offset
。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeIntBE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用大端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeInt16BE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用大端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeInt32BE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用大端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeIntLE(offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用小端序。-
offset
:輸入整數。 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeInt16LE(offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用小端序。-
offset
:輸入整數。 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeInt32LE(offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用小端序。-
offset
:輸入整數。 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUInt8(value, offset, byteLength)
將
UInt8
value
(長度為byteLength
) 寫入Buffer
的偏移值offset
。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUIntBE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用大端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUInt16BE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用大端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUInt32BE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用大端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUIntLE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用小端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUInt16LE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用小端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
Buffer.prototype.writeUInt32LE(value, offset, byteLength)
將
value
寫入Buffer
的偏移值offset
,使用小端序。-
value
:輸入整數。 -
offset
:輸入整數 -
byteLength
:輸入從1
到6
的整數。
-
-
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
的八位元組 (位元組)。-
取得從
0
到255
的數字。或設定一個從0
到255
的數字。
-
支援以下執行個體屬性:
-
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
的值移除計數鍵的限制。
根據預設,查詢字串中的百分比編碼字元會假設為使用 UTF-8 編碼。無效的 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()
。
根據預設,在查詢字串中需要百分比編碼的字元會編碼為 UTF-8。若要使用不同的編碼,請指定
encodeURIComponent
選項。例如,對於以下程式碼:
querystring.stringify({ name: 'value', abc: ['xyz', '123'], anotherName: '' });
返回值是:
'name=value&abc=xyz&abc=123&anotherName='
querystring.encode()
是querystring.stringify()
的別名。 querystring.unescape(string)
-
解碼給定
string
中的 URL 百分比編碼字元,傳回未逸出的查詢字串。此方法由querystring.parse()
使用,並且不應直接使用。
加密
密碼編譯模組 (crypto
) 提供標準雜湊和雜湊型訊息身分驗證碼 (HMAC) 協助程式。您可以使用 require('crypto')
加載模組。
雜湊方法
crypto.createHash(algorithm)
-
建立並傳回雜湊物件,藉助此物件,您可以使用給定的演算法產生雜湊摘要:
md5
、sha1
或sha256
。 hash.update(data)
-
使用給定的
data
更新雜湊內容。 hash.digest([encoding])
-
計算使用
hash.update()
傳遞的所有資料的摘要。編碼可以是hex
、base64
或base64url
。
HMAC 方法
crypto.createHmac(algorithm, secret key)
-
建立並返回使用給定
algorithm
和secret key
的 HMAC 物件。演算法可以是md5
、sha1
或sha256
。 hmac.update(data)
-
使用給定的
data
更新 HMAC 內容。 hmac.digest([encoding])
-
計算使用
hmac.update()
傳遞的所有資料的摘要。編碼可以是hex
、base64
或base64url
。
限制功能
由於安全考量,下列 JavaScript 語言功能不受支援或受到限制。
- 動態程式碼評估
-
不支援動態程式碼評估。如果嘗試此評估,
eval()
和Function
建構子都會丟出錯誤。例如,const sum = new Function('a', 'b', 'return a + b')
丟出錯誤。 - 計時器
-
不支援
setTimeout()
、setImmediate()
和clearTimeout()
函數。在函數執行期間未推遲或產生任何佈建。您的函數必須同步執行方可完成。 - 日期和時間戳記
-
基於安全考量,無法存取高解析度計時器。查詢當前時間的所有
Date
方法始終在單個函數執行的生命週期內返回相同的值。返回的時間戳記是函數開始執行的時間。因此,您無法測量函數中的經過時間。 - 檔案系統存取
-
沒有檔案系統存取權。例如,沒有類似 Node.js 中的檔案系統存取
fs
模組。 - 程序存取
-
沒有程序存取。例如,沒有
process
全域物件可處理資訊存取,就像 Node.js 中一樣。 - 環境變數
-
無法存取環境變數。反之,您可以使用 CloudFront KeyValueStore 為您的 CloudFront Functions 建立金鑰值對的集中式資料存放區。CloudFront KeyValueStore 啟用組態資料的動態更新,而不需要部署程式碼變更。如需詳細資訊,請參閱Amazon CloudFront KeyValueStore。
- 網路存取
-
不支援網路呼叫。例如,不支援 XHR、HTTP(S) 和通訊端。