UNPKG

@restnfeel/agentc-starter-kit

Version:

한국어 기업용 CMS 모듈 - Task Master AI와 함께 빠르게 웹사이트를 구현할 수 있는 재사용 가능한 컴포넌트 시스템

92 lines (89 loc) 3.13 kB
import { RFC1738 } from './formats.js'; const is_array = Array.isArray; const hex_table = (() => { const array = []; for (let i = 0; i < 256; ++i) { array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase()); } return array; })(); const limit = 1024; const encode = (str, _defaultEncoder, charset, _kind, format) => { // This code was originally written by Brian White for the io.js core querystring library. // It has been adapted here for stricter adherence to RFC 3986 if (str.length === 0) { return str; } let string = str; if (typeof str === 'symbol') { string = Symbol.prototype.toString.call(str); } else if (typeof str !== 'string') { string = String(str); } if (charset === 'iso-8859-1') { return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) { return '%26%23' + parseInt($0.slice(2), 16) + '%3B'; }); } let out = ''; for (let j = 0; j < string.length; j += limit) { const segment = string.length >= limit ? string.slice(j, j + limit) : string; const arr = []; for (let i = 0; i < segment.length; ++i) { let c = segment.charCodeAt(i); if (c === 0x2d || // - c === 0x2e || // . c === 0x5f || // _ c === 0x7e || // ~ (c >= 0x30 && c <= 0x39) || // 0-9 (c >= 0x41 && c <= 0x5a) || // a-z (c >= 0x61 && c <= 0x7a) || // A-Z (format === RFC1738 && (c === 0x28 || c === 0x29)) // ( ) ) { arr[arr.length] = segment.charAt(i); continue; } if (c < 0x80) { arr[arr.length] = hex_table[c]; continue; } if (c < 0x800) { arr[arr.length] = hex_table[0xc0 | (c >> 6)] + hex_table[0x80 | (c & 0x3f)]; continue; } if (c < 0xd800 || c >= 0xe000) { arr[arr.length] = hex_table[0xe0 | (c >> 12)] + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)]; continue; } i += 1; c = 0x10000 + (((c & 0x3ff) << 10) | (segment.charCodeAt(i) & 0x3ff)); arr[arr.length] = hex_table[0xf0 | (c >> 18)] + hex_table[0x80 | ((c >> 12) & 0x3f)] + hex_table[0x80 | ((c >> 6) & 0x3f)] + hex_table[0x80 | (c & 0x3f)]; } out += arr.join(''); } return out; }; function is_buffer(obj) { if (!obj || typeof obj !== 'object') { return false; } return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj)); } function maybe_map(val, fn) { if (is_array(val)) { const mapped = []; for (let i = 0; i < val.length; i += 1) { mapped.push(fn(val[i])); } return mapped; } return fn(val); } export { encode, is_buffer, maybe_map }; //# sourceMappingURL=utils.js.map