@jsarc/qust 0.0.0 → 0.0.1-beta.0.2

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 CHANGED
@@ -328,18 +328,18 @@ const url = buildSearchUrl("/products", filters);
328
328
 
329
329
  ```typescript
330
330
  // Dans une application web
331
- const currentQuery = window.location.search;
331
+ const currentQuery = (window as any).location.search;
332
332
  const params = qust.parse(currentQuery);
333
333
 
334
334
  // Utilisation avec React/Vue/Angular
335
335
  function useQueryParams() {
336
336
  const [params, setParams] = useState(() => {
337
- return qust.parse(window.location.search);
337
+ return qust.parse((window as any).location.search);
338
338
  });
339
339
 
340
340
  const updateParams = (newParams: any) => {
341
341
  const query = qust.stringify({ ...params, ...newParams });
342
- window.history.pushState({}, '', `?\${query}`);
342
+ (window as any).history.pushState({}, '', `?\${query}`);
343
343
  setParams(qust.parse(query));
344
344
  };
345
345
 
@@ -376,11 +376,11 @@ class FormState {
376
376
  skipEmptyString: true,
377
377
  skipNull: true
378
378
  });
379
- window.location.hash = query;
379
+ (window as any).location.hash = query;
380
380
  }
381
381
 
382
382
  loadFromUrl() {
383
- const query = window.location.hash.substring(1);
383
+ const query = (window as any).location.hash.substring(1);
384
384
  this.state = qust.parse(`?\${query}`) || {};
385
385
  }
386
386
  }
package/index.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  // @ts-nocheck
2
2
 
3
- interface Window {
4
- default: typeof defaultElementGF;
5
- Qust: any;
6
- qust: any;
7
- __bundledModules: any;
8
- }
9
-
10
3
  interface QustOptions {
11
4
  arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'none';
12
5
  arraySeparator?: string;
@@ -24,7 +17,7 @@ type QueryValue = Primitive | Primitive[] | { [key: string]: QueryValue };
24
17
 
25
18
  type QueryObject = { [key: string]: QueryValue };
26
19
 
27
- const globalFunct = (function(global: any) {
20
+ const globalFunct = (function() {
28
21
  'use strict';
29
22
 
30
23
 
@@ -33,8 +26,6 @@ const globalFunct = (function(global: any) {
33
26
 
34
27
 
35
28
 
36
-
37
-
38
29
  const DEFAULT_OPTIONS: Required<QustOptions> = {
39
30
  arrayFormat: 'bracket',
40
31
  arraySeparator: ',',
@@ -350,12 +341,6 @@ const globalFunct = (function(global: any) {
350
341
  getOptions(): Required<QustOptions> {
351
342
  return { ...this.options };
352
343
  }
353
-
354
- static exposeToGlobal(): void {
355
- if (typeof window !== "undefined") {
356
- window.Qust = Qust;
357
- }
358
- }
359
344
  }
360
345
 
361
346
  const qust = {
@@ -369,11 +354,6 @@ const globalFunct = (function(global: any) {
369
354
  }
370
355
  };
371
356
 
372
- if (typeof window !== "undefined") {
373
- window.Qust = Qust;
374
- window.qust = qust;
375
- }
376
-
377
357
 
378
358
 
379
359
 
@@ -386,20 +366,6 @@ const globalFunct = (function(global: any) {
386
366
 
387
367
  const __bundledModules = globalFunctModule;
388
368
 
389
- if (typeof global !== 'undefined') {
390
- (global as any).default = qust;
391
- (global as any).Qust = Qust;
392
- (global as any).qust = qust;
393
- (global as any).__bundledModules = __bundledModules;
394
- }
395
-
396
- if (typeof window !== "undefined") {
397
- (window as any).default = qust;
398
- (window as any).Qust = Qust;
399
- (window as any).qust = qust;
400
- (window as any).__bundledModules = __bundledModules;
401
- }
402
-
403
369
  if (typeof exports !== 'undefined') {
404
370
  exports.default = qust;
405
371
  exports.Qust = Qust;
@@ -407,11 +373,7 @@ const globalFunct = (function(global: any) {
407
373
  }
408
374
  return globalFunctModule;
409
375
 
410
- })(typeof global !== 'undefined' ? global :
411
- typeof window !== 'undefined' ? window :
412
- typeof self !== 'undefined' ? self :
413
- typeof globalThis !== 'undefined' ? globalThis :
414
- {});
376
+ })();
415
377
 
416
378
  type QustElementTypeGF = typeof globalFunct.Qust;
417
379
 
package/js/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const globalFunct = (function (global) {
1
+ const globalFunct = (function () {
2
2
  'use strict';
3
3
  const DEFAULT_OPTIONS = {
4
4
  arrayFormat: 'bracket',
@@ -257,11 +257,6 @@ const globalFunct = (function (global) {
257
257
  getOptions() {
258
258
  return { ...this.options };
259
259
  }
260
- static exposeToGlobal() {
261
- if (typeof window !== "undefined") {
262
- window.Qust = Qust;
263
- }
264
- }
265
260
  }
266
261
  const qust = {
267
262
  stringify(obj, options) {
@@ -271,39 +266,19 @@ const globalFunct = (function (global) {
271
266
  return new Qust(options).parse(queryString);
272
267
  }
273
268
  };
274
- if (typeof window !== "undefined") {
275
- window.Qust = Qust;
276
- window.qust = qust;
277
- }
278
269
  const globalFunctModule = {
279
270
  default: qust,
280
271
  Qust: Qust,
281
272
  qust: qust,
282
273
  };
283
274
  const __bundledModules = globalFunctModule;
284
- if (typeof global !== 'undefined') {
285
- global.default = qust;
286
- global.Qust = Qust;
287
- global.qust = qust;
288
- global.__bundledModules = __bundledModules;
289
- }
290
- if (typeof window !== "undefined") {
291
- window.default = qust;
292
- window.Qust = Qust;
293
- window.qust = qust;
294
- window.__bundledModules = __bundledModules;
295
- }
296
275
  if (typeof exports !== 'undefined') {
297
276
  exports.default = qust;
298
277
  exports.Qust = Qust;
299
278
  exports.qust = qust;
300
279
  }
301
280
  return globalFunctModule;
302
- })(typeof global !== 'undefined' ? global :
303
- typeof window !== 'undefined' ? window :
304
- typeof self !== 'undefined' ? self :
305
- typeof globalThis !== 'undefined' ? globalThis :
306
- {});
281
+ })();
307
282
  const QustElementGF = globalFunct.Qust;
308
283
  const qustElementGF = globalFunct.qust;
309
284
  const defaultElementGF = globalFunct.default;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.0",
6
+ "version": "0.0.1-beta.0.2",
7
7
  "description": "Qust est une bibliothèque TypeScript ultra-légère et performante pour la sérialisation et désérialisation d'objets en chaînes de requête (query strings). Elle offre une API simple et puissante pour manipuler les paramètres d'URL avec support des types complexes, des tableaux, des objets imbriqués et des options avancées.",
8
8
  "main": "index.ts",
9
9
  "keywords": [],
package/web/qust.js CHANGED
@@ -1,4 +1,4 @@
1
- const globalFunct = (function (global) {
1
+ const globalFunct = (function () {
2
2
  'use strict';
3
3
  const DEFAULT_OPTIONS = {
4
4
  arrayFormat: 'bracket',
@@ -281,29 +281,13 @@ const globalFunct = (function (global) {
281
281
  qust: qust,
282
282
  };
283
283
  const __bundledModules = globalFunctModule;
284
- if (typeof global !== 'undefined') {
285
- global.default = qust;
286
- global.Qust = Qust;
287
- global.qust = qust;
288
- global.__bundledModules = __bundledModules;
289
- }
290
- if (typeof window !== "undefined") {
291
- window.default = qust;
292
- window.Qust = Qust;
293
- window.qust = qust;
294
- window.__bundledModules = __bundledModules;
295
- }
296
284
  if (typeof exports !== 'undefined') {
297
285
  exports.default = qust;
298
286
  exports.Qust = Qust;
299
287
  exports.qust = qust;
300
288
  }
301
289
  return globalFunctModule;
302
- })(typeof global !== 'undefined' ? global :
303
- typeof window !== 'undefined' ? window :
304
- typeof self !== 'undefined' ? self :
305
- typeof globalThis !== 'undefined' ? globalThis :
306
- {});
290
+ })();
307
291
  const QustElementGF = globalFunct.Qust;
308
292
  const qustElementGF = globalFunct.qust;
309
293
  const defaultElementGF = globalFunct.default;
package/web/qust.min.js CHANGED
@@ -1 +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}),n=r;return void 0!==e&&(e.default=s,e.Qust=o,e.qust=s,e.__bundledModules=n),"undefined"!=typeof window&&(window.default=s,window.Qust=o,window.qust=s,window.__bundledModules=n),"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;
1
+ let globalFunct=(()=>{let t={arrayFormat:"bracket",arraySeparator:",",skipNull:!0,skipEmptyString:!1,encode:!0,decode:!0,depth:10};class r{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,r,s,o={};for(t of e.split("&"))t&&([r,s]=t.split("="),r)&&(r=this.options.decode?decodeURIComponent(r):r,s=this.options.decode&&void 0!==s?decodeURIComponent(s):s,this.setValue(o,r,s));return this.transformArrays(o)}processObject(e,t,r,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||r.push(this.encodeKey(e));else if("string"!=typeof t||""!==t||!this.options.skipEmptyString)if(Array.isArray(t))this.processArray(e,t,r,s+1);else if("object"!=typeof t||this.isPrimitive(t)){var o=this.encodeKey(e),n=(this.options.encode&&"string"==typeof t?encodeURIComponent:String)(t);r.push(o+"="+n)}else for(var[i,a]of Object.entries(t)){i=e?`${e}[${i}]`:i;this.processObject(i,a,r,s+1)}}processArray(r,e,s,o){if(0!==e.length){let t=this.encodeKey(r);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(r+`[${t}]`,e,s,o)});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(r,e,s,o)});break;default:e.forEach(e=>{this.processObject(r+"[]",e,s,o)})}}}encodeKey(t){if(!this.options.encode)return t;var r=[];let s="";for(let e=0;e<t.length;e++){var o=t[e];"["===o||"]"===o?(s&&(r.push(encodeURIComponent(s)),s=""),r.push(o)):s+=o}return s&&r.push(encodeURIComponent(s)),r.join("")}setValue(e,t,r){var s=t.match(/([^\[\]]+)|(\[\])/g);if(s){let t=e;for(let e=0;e<s.length;e++){var o,n,i=s[e],a=e===s.length-1;"[]"===i?(Array.isArray(t)||(t=[]),a?r&&t.push(this.parseValue(r)):(o=s[e+1],o=parseInt(o,10),isNaN(o)?(n={},t.push(n),t=n):(void 0===t[o]&&(t[o]={}),t=t[o],e++))):a?void 0!==r&&(t[i]=this.parseValue(r)):(void 0!==t[i]&&"object"==typeof t[i]||(n=s[e+1],t[i]="[]"===n?[]:{}),t=t[i])}}else void 0!==r&&(e[t]=this.parseValue(r))}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 r={};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 r=[];return e.forEach(e=>{var t=parseInt(e,10);r[t]=this.transformArrays(s[e])}),r}return e.forEach(e=>{var t=s[e];r[e]="object"==typeof t&&null!==t?this.transformArrays(t):t}),r}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=r)}}var e={stringify(e,t){return new r(t).stringify(e)},parse(e,t){return new r(t).parse(e)}},s=("undefined"!=typeof window&&(window.Qust=r,window.qust=e),{default:e,Qust:r,qust:e});return"undefined"!=typeof exports&&(exports.default=e,exports.Qust=r,exports.qust=e),s})(),QustElementGF=globalFunct.Qust,qustElementGF=globalFunct.qust,defaultElementGF=globalFunct.default;