@beenotung/tslib
Version:
utils library in Typescript
29 lines (28 loc) • 1.33 kB
TypeScript
/**
* Encodes an object into a URL-encoded query string.
*
* Similar to native `URLSearchParams` but with key differences:
* - **Same behavior for strings and numbers**: Both are handled identically to native implementation
* - **Different for arrays and objects**: Automatically converts complex values to JSON strings
* - Arrays: `[1,2,3]` becomes `"[1,2,3]"` (vs native: `"1,2,3"`)
* - Objects: `{a:1}` becomes `'{"a":1}'` (vs native: `"[object Object]"`)
* - **Encoding differences**: Uses lowercase hex (`%3d`) and `%20` for spaces (vs native: `%3D` and `+`)
* - **Null values**: Converts `null` to the string `"null"` (same as native behavior)
*
* @param o - Object to encode into query string
* @returns URL-encoded query string
*
* @example
* ```typescript
* urlEncode({ name: 'john', age: 25 }) // "name=john&age=25"
* urlEncode({ items: [1,2,3] }) // "items=%5b1%2c2%2c3%5d"
* urlEncode({ user: { id: 1, username: 'tester' } }) // "user=%7b%22id%22%3a1%2c%22username%22%3a%22tester%22%7d"
* ```
*/
export declare function urlEncode(o: object): string;
export declare function decodeUTF16BE(buffer: Buffer): string;
export declare function encodeUTF16BE(text: string): Buffer;
/**
* convert between BE (big endian) and LE (little endian)
*/
export declare function swapBytes(buffer: Buffer): void;