@arc-js/qust 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +630 -0
- package/index.ts +456 -0
- package/js/index.js +328 -0
- package/package.json +18 -0
- package/tsconfig.json +27 -0
- package/web/qust.js +326 -0
- package/web/qust.min.js +1 -0
package/web/qust.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let globalFunct=(e=>{let t={arrayFormat:"bracket",arraySeparator:",",skipNull:!0,skipEmptyString:!1,encode:!0,decode:!0,depth:10};class o{options;constructor(e={}){this.options={...t,...e}}stringify(e){return e&&"object"==typeof e&&(this.processObject("",e,e=[],0),0<e.length)?"?"+e.join("&"):""}parse(e){if(!e||"string"!=typeof e)return{};e=e.startsWith("?")?e.slice(1):e;if(!e)return{};var t,o,s,r={};for(t of e.split("&"))t&&([o,s]=t.split("="),o)&&(o=this.options.decode?decodeURIComponent(o):o,s=this.options.decode&&void 0!==s?decodeURIComponent(s):s,this.setValue(r,o,s));return this.transformArrays(r)}processObject(e,t,o,s){if(s>this.options.depth)console.warn("Qust: Profondeur maximale atteinte, arrêt de la récursion");else if(null==t)this.options.skipNull||o.push(this.encodeKey(e));else if("string"!=typeof t||""!==t||!this.options.skipEmptyString)if(Array.isArray(t))this.processArray(e,t,o,s+1);else if("object"!=typeof t||this.isPrimitive(t)){var r=this.encodeKey(e),n=(this.options.encode&&"string"==typeof t?encodeURIComponent:String)(t);o.push(r+"="+n)}else for(var[i,a]of Object.entries(t)){i=e?`${e}[${i}]`:i;this.processObject(i,a,o,s+1)}}processArray(o,e,s,r){if(0!==e.length){let t=this.encodeKey(o);switch(this.options.arrayFormat){case"comma":var n=e.map(e=>(this.options.encode&&"string"==typeof e?encodeURIComponent:String)(e)).join(this.options.arraySeparator);s.push(t+"="+n);break;case"index":e.forEach((e,t)=>{this.processObject(o+`[${t}]`,e,s,r)});break;case"separator":e.forEach(e=>{e=(this.options.encode&&"string"==typeof e?encodeURIComponent:String)(e);s.push(t+"="+e)});break;case"none":e.forEach(e=>{this.processObject(o,e,s,r)});break;default:e.forEach(e=>{this.processObject(o+"[]",e,s,r)})}}}encodeKey(t){if(!this.options.encode)return t;var o=[];let s="";for(let e=0;e<t.length;e++){var r=t[e];"["===r||"]"===r?(s&&(o.push(encodeURIComponent(s)),s=""),o.push(r)):s+=r}return s&&o.push(encodeURIComponent(s)),o.join("")}setValue(e,t,o){var s=t.match(/([^\[\]]+)|(\[\])/g);if(s){let t=e;for(let e=0;e<s.length;e++){var r,n,i=s[e],a=e===s.length-1;"[]"===i?(Array.isArray(t)||(t=[]),a?o&&t.push(this.parseValue(o)):(r=s[e+1],r=parseInt(r,10),isNaN(r)?(n={},t.push(n),t=n):(void 0===t[r]&&(t[r]={}),t=t[r],e++))):a?void 0!==o&&(t[i]=this.parseValue(o)):(void 0!==t[i]&&"object"==typeof t[i]||(n=s[e+1],t[i]="[]"===n?[]:{}),t=t[i])}}else void 0!==o&&(e[t]=this.parseValue(o))}transformArrays(s){if(Array.isArray(s))return s.map(e=>"object"==typeof e&&null!==e?this.transformArrays(e):e);if("object"!=typeof s||null===s)return s;let o={};var e=Object.keys(s);if(e.every(e=>{var t=parseInt(e,10);return!isNaN(t)&&0<=t&&t.toString()===e})&&0<e.length){let o=[];return e.forEach(e=>{var t=parseInt(e,10);o[t]=this.transformArrays(s[e])}),o}return e.forEach(e=>{var t=s[e];o[e]="object"==typeof t&&null!==t?this.transformArrays(t):t}),o}parseValue(e){var t;return"true"===e||"false"!==e&&("null"===e?null:"undefined"!==e?(t=Number(e),isNaN(t)||""===e.trim()?e:t):void 0)}isPrimitive(e){return null===e||"object"!=typeof e&&"function"!=typeof e}setOptions(e){this.options={...this.options,...e}}getOptions(){return{...this.options}}static exposeToGlobal(){"undefined"!=typeof window&&(window.Qust=o)}}var s={stringify(e,t){return new o(t).stringify(e)},parse(e,t){return new o(t).parse(e)}},r=("undefined"!=typeof window&&(window.Qust=o,window.qust=s),{default:s,Qust:o,qust:s});return r.default={...r?.default||{},Qust:o},r.default={...r?.default||{},qust:s},void 0!==e&&(e.default=s,e.Qust=o,e.qust=s,e.__bundledModules=r),"undefined"!=typeof window&&(window.default=s,window.Qust=o,window.qust=s,window.__bundledModules=r),"undefined"!=typeof module&&module.exports&&(module.exports=r,module.exports.default=s,module.exports.Qust=o,module.exports.qust=s),"undefined"!=typeof exports&&(exports.default=s,exports.Qust=o,exports.qust=s),r})("undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof globalThis?globalThis:{}),QustElementGF=globalFunct.Qust,qustElementGF=globalFunct.qust,defaultElementGF=globalFunct.default;"undefined"!=typeof module&&module.exports&&(module.exports={Qust:QustElementGF,qust:qustElementGF}),"undefined"!=typeof module&&module.exports&&(module.exports.default=globalFunct?.default);
|