Last active
July 24, 2025 23:58
-
-
Save dir/70643d41a92047ee4313e107a99f8539 to your computer and use it in GitHub Desktop.
Postman Package Library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let t="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",e=t=>crypto.getRandomValues(new Uint8Array(t)),r=(t,e,r)=>{let n=(2<<Math.log(t.length-1)/Math.LN2)-1,l=-~(1.6*n*e/t.length);return(o=e)=>{let a="";for(;;){let e=r(l),g=0|l;for(;g--;)if(a+=t[e[g]&n]||"",a.length===o)return a}}},n=(t,n=21)=>r(t,n,e),l=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce(((t,e)=>t+=(e&=63)<36?e.toString(36):e<62?(e-26).toString(36).toUpperCase():e>62?"-":"_"),"");module.exports={customAlphabet:n,customRandom:r,nanoid:l,random:e,urlAlphabet:t};module.exports.default=null; | |
| //# sourceMappingURL=https://cdn.jsdelivr.net/sm/2bcc6c4870702ad675061bedae7ea2c4af9274577d2bce6e749ab8c564d06b45.map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * nanoid | |
| * | |
| * For use in Postman scripts. Manually converted to CJS. | |
| * | |
| * @version 5.1.5 | |
| * @license MIT | |
| * @homepage https://github.com/ai/nanoid | |
| */ | |
| /** | |
| * URL safe symbols. | |
| * | |
| * ```js | |
| * import { urlAlphabet } from 'nanoid' | |
| * const nanoid = customAlphabet(urlAlphabet, 10) | |
| * nanoid() //=> "Uakgb_J5m9" | |
| * ``` | |
| */ | |
| const urlAlphabet = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'; | |
| const scopedUrlAlphabet = urlAlphabet; | |
| /** | |
| * Generate an array of random bytes collected from hardware noise. | |
| * | |
| * ```js | |
| * import { customRandom, random } from 'nanoid' | |
| * const nanoid = customRandom("abcdef", 5, random) | |
| * ``` | |
| * | |
| * @param bytes Size of the array. | |
| * @returns An array of random bytes. | |
| */ | |
| const random = bytes => crypto.getRandomValues(new Uint8Array(bytes)); | |
| /** | |
| * Generate unique ID with custom random generator and alphabet. | |
| * | |
| * Alphabet must contain 256 symbols or less. Otherwise, the generator | |
| * will not be secure. | |
| * | |
| * ```js | |
| * import { customRandom } from 'nanoid/format' | |
| * | |
| * const nanoid = customRandom('abcdef', 5, size => { | |
| * const random = [] | |
| * for (let i = 0; i < size; i++) { | |
| * random.push(randomByte()) | |
| * } | |
| * return random | |
| * }) | |
| * | |
| * nanoid() //=> "fbaef" | |
| * ``` | |
| * | |
| * @param alphabet Alphabet used to generate a random string. | |
| * @param size Size of the random string. | |
| * @param random A random bytes generator. | |
| * @returns A random string generator. | |
| */ | |
| const customRandom = (alphabet, defaultSize, getRandom) => { | |
| let mask = (2 << Math.log2(alphabet.length - 1)) - 1 | |
| let step = -~((1.6 * mask * defaultSize) / alphabet.length) | |
| return (size = defaultSize) => { | |
| let id = '' | |
| while (true) { | |
| let bytes = getRandom(step) | |
| let j = step | 0 | |
| while (j--) { | |
| id += alphabet[bytes[j] & mask] || '' | |
| if (id.length >= size) return id | |
| } | |
| } | |
| } | |
| } | |
| /** | |
| * Generate secure unique ID with custom alphabet. | |
| * | |
| * Alphabet must contain 256 symbols or less. Otherwise, the generator | |
| * will not be secure. | |
| * | |
| * @param alphabet Alphabet used to generate the ID. | |
| * @param defaultSize Size of the ID. The default size is 21. | |
| * @returns A random string generator. | |
| * | |
| * ```js | |
| * const { customAlphabet } = require('nanoid') | |
| * const nanoid = customAlphabet('0123456789абвгдеё', 5) | |
| * nanoid() //=> "8ё56а" | |
| * ``` | |
| */ | |
| const customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size | 0, random); | |
| /** | |
| * Generate secure URL-friendly unique ID. | |
| * | |
| * By default, the ID will have 21 symbols to have a collision probability | |
| * similar to UUID v4. | |
| * | |
| * ```js | |
| * import { nanoid } from 'nanoid' | |
| * model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL" | |
| * ``` | |
| * | |
| * @param size Size of the ID. The default size is 21. | |
| * @returns A random string. | |
| */ | |
| const nanoid = (size = 21) => { | |
| let id = '' | |
| let bytes = crypto.getRandomValues(new Uint8Array((size |= 0))) | |
| while (size--) { | |
| id += scopedUrlAlphabet[bytes[size] & 63] | |
| } | |
| return id | |
| } | |
| module.exports = { urlAlphabet, random, customRandom, customAlphabet, nanoid }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Parses XML responses to objects | |
| */ | |
| const xml2js = require("xml2js"); | |
| /** @type {Object<string, function>} */ | |
| const processors = { | |
| /** | |
| * Converts a string to snake_case | |
| * | |
| * @param {string} str - The string to convert | |
| * @returns {string} The snake_cased string | |
| */ | |
| toSnakeCase: (str) => | |
| str | |
| .replace(/([A-Z])([A-Z])([a-z])/g, "$1_$2$3") // Handle end of acronym | |
| .replace(/([a-z])([A-Z])/g, "$1_$2") // Handle regular camelCase | |
| .toLowerCase(), | |
| /** | |
| * Parses numbers while preserving empty strings | |
| * | |
| * @param {string} str - The string to parse | |
| * @returns {number | string} Parsed number or original string if empty | |
| */ | |
| parseNumbers: (str) => (str === "" ? str : xml2js.processors.parseNumbers(str)), | |
| }; | |
| /** | |
| * XML parser instance with custom processing options | |
| * | |
| * @type {xml2js.Parser} | |
| */ | |
| const Parser = new xml2js.Parser({ | |
| tagNameProcessors: [xml2js.processors.stripPrefix, processors.toSnakeCase], | |
| attrNameProcessors: [xml2js.processors.stripPrefix, processors.toSnakeCase], | |
| valueProcessors: [processors.parseNumbers, xml2js.processors.parseBooleans], | |
| attrValueProcessors: [processors.parseNumbers, xml2js.processors.parseBooleans], | |
| explicitArray: false, // Don't create arrays for single elements | |
| ignoreAttrs: false, // Keep attributes | |
| mergeAttrs: true, // Merge attributes with element content | |
| normalize: true, // Trim whitespace | |
| explicitRoot: false, // Don't wrap in a root element | |
| }); | |
| /** | |
| * Asynchronously parses an XML string into a JavaScript object | |
| * | |
| * @example | |
| * const { parse } = pm.require("xml"); | |
| * | |
| * const xmlString = pm.response.text(); | |
| * const parsed = await parse(xmlString); //=> JS object | |
| * // ... do something with the parsed object | |
| * | |
| * @param {string} xmlString - The XML string to parse | |
| * @returns {Promise<Object>} A promise that resolves to the parsed object | |
| * @throws {Error} If parsing fails | |
| */ | |
| const parse = async (xmlString) => Parser.parseStringPromise(xmlString); | |
| module.exports = { Parser, parse }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment