UNPKG

@feugene/mu

Version:

Helpful TS utilities without dependencies

44 lines 1.58 kB
type FromQueryStringOptions = { decodeName: boolean; }; /** * Converts a query string back into an object. * * Non-recursive: * * fromQueryString("foo=1&bar=2"); // returns {foo: '1', bar: '2'} * fromQueryString("foo=&bar=2"); // returns {foo: '', bar: '2'} * fromQueryString("some%20price=%24300"); // returns {'some price': '$300'} * fromQueryString("colors=red&colors=green&colors=blue"); // returns {colors: ['red', 'green', 'blue']} * * Recursive: * * fromQueryString( * "username=Jacky&"+ * "dateOfBirth[day]=1&dateOfBirth[month]=2&dateOfBirth[year]=1911&"+ * "hobbies[0]=coding&hobbies[1]=eating&hobbies[2]=sleeping&"+ * "hobbies[3][0]=nested&hobbies[3][1]=stuff", true); * * // returns * { * username: 'Jacky', * dateOfBirth: { * day: '1', * month: '2', * year: '1911' * }, * hobbies: ['coding', 'eating', 'sleeping', ['nested', 'stuff']] * } * * @param {String|null} queryString The query string to decode * @param {Boolean} [recursive=false] Whether or not to recursively decode the string. This format is supported by * @param {Object} options = { * - decodeName {Boolean} Decode KeyNames in the queryString * } * PHP / Ruby on Rails servers and similar. * @return {Object} * @todo write tests */ export default function fromQueryString(queryString: string, recursive?: boolean, options?: FromQueryStringOptions): Record<string, any>; export {}; //# sourceMappingURL=fromQueryString.d.ts.map