PostMan内置对象
Import packages into your scripts
You can use the pm.require method to import packages from your team's Package Library or external package registries inside scripts in HTTP, gRPC, and GraphQL requests.
pm.require
The pm.require method accepts the name of a package. Declare the method as a variable if the package has functions or objects you want to call. If the package only has code or instances of the pm object, you don't need to declare the method as a variable.
Examples
Use the following format to import a package from the Package Library:
const variableName = pm.require('@team-domain/package-name');
variableName.functionName()
Use the following format to import an external package from a package registry:
// package imported from npm
const npmVariableName = pm.require('npm:package-name@version-number');
npmVariableName.functionName()
// package imported from jsr
const jsrVariableName = pm.require('jsr:package-name@version-number');
jsrVariableName.functionName()
Use global objects
Postman supports the following JavaScript objects globally in your scripts:
- Standard objects
- AggregateError
- Array
- ArrayBuffer
- Atomics
- BigInt
- BigInt64Array
- BigUint64Array
- Boolean
- DataView
- Date
- Error
- EvalError
- Float32Array
- Float64Array
- Function
- Infinity property
- Int8Array
- Int16Array
- Int32Array
- Intl
- JSON
- Map
- Math
- NaN property
- Number
- Object
- Promise
- Proxy
- RangeError
- ReferenceError
- Reflect
- RegExp
- Set
- SharedArrayBuffer
- String
- Symbol
- SyntaxError
- TypeError
- Uint8Array
- Uint8ClampedArray
- Uint16Array
- Uint32Array
- URIError
- WeakMap
- WeakSet
- Document Object Model (DOM) objects
- AbortController
- AbortSignal
- DOMException
- Event
- EventTarget
- Encoding objects
- atob method
- btoa method
- TextEncoder
- TextEncoderStream
- TextDecoder
- TextDecoderStream
- File objects
- Blob
- File
- JavaScript objects
- decodeURI
- decodeURIComponent
- encodeURI
- encodeURIComponent
- escape
- isFinite
- isNaN
- parseFloat
- parseInt
- undefined
- unescape
- HTML DOM objects
- structuredClone method
- queueMicrotask method
- Streams objects
- ByteLengthQueuingStrategy
- CountQueuingStrategy
- CompressionStream
- DecompressionStream
- ReadableByteStreamController
- ReadableStream
- ReadableStreamBYOBReader
- ReadableStreamBYOBRequest
- ReadableStreamDefaultController
- ReadableStreamDefaultReader
- TransformStream
- TransformStreamDefaultController
- WritableStream
- WritableStreamDefaultController
- WritableStreamDefaultWriter
- URL objects
- URL
- URLSearchParams
- Web Crypto objects
- Crypto
- CryptoKey
- SubtleCrypto
- crypto property
Use external libraries
The require method enables you to use the sandbox built-in library modules. To use a library, call the require method, pass the module name as a parameter, and assign the return object from the method to a variable:
require(moduleName:String):function
The supported libraries available for use in the sandbox include:
The following libraries are deprecated and no longer supported:
- atob (use the atob method)
- btoa (use the btoa method)
- crypto-js (use the Web Crypto objects)
- tv4 (use the ajv library)
The following NodeJS modules are also available:
Postman doesn't support the following in the buffer module: isAscii, isUtf8, resolveObjectURL, transcode, and copyBytesFrom.
- 转载请注明来源
- 作者:杨瀚博
- QQ:464884492

浙公网安备 33010602011771号