ember-primitives 0.33.0 → 0.34.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.
@@ -1,19 +1,61 @@
1
1
  import Helper from '@ember/component/helper';
2
2
  import type RouterService from '@ember/routing/router-service';
3
- export interface Signature {
3
+ interface Signature {
4
4
  Args: {
5
5
  Positional: [string];
6
6
  };
7
7
  Return: string | undefined;
8
8
  }
9
- declare class QP extends Helper<Signature> {
9
+ /**
10
+ * Grabs a query-param off the current route from the router service.
11
+ *
12
+ * ```gjs
13
+ * import { qp } from 'ember-primitives/qp';
14
+ *
15
+ * <template>
16
+ * {{qp "query-param"}}
17
+ * </template>
18
+ * ```
19
+ */
20
+ export declare class qp extends Helper<Signature> {
10
21
  router: RouterService;
11
22
  compute([name]: [string]): string | undefined;
12
23
  }
13
- export declare const qp: typeof QP;
24
+ /**
25
+ * Returns a string for use as an `href` on `<a>` tags, updated with the passed query param
26
+ *
27
+ * ```gjs
28
+ * import { withQP } from 'ember-primitives/qp';
29
+ *
30
+ * <template>
31
+ * <a href={{withQP "foo" "2"}}>
32
+ * ...
33
+ * </a>
34
+ * </template>
35
+ * ```
36
+ */
37
+ export declare class withQP extends Helper<{
38
+ Args: {
39
+ Positional: [string, string];
40
+ };
41
+ Return: string;
42
+ }> {
43
+ router: RouterService;
44
+ compute([qpName, nextValue]: [string, string]): string;
45
+ }
14
46
  /**
15
47
  * Cast a query-param string value to a boolean
16
48
  *
49
+ * ```gjs
50
+ * import { castToBoolean, qp } from 'ember-primitives/qp';
51
+ *
52
+ * <template>
53
+ * {{#if (castToBoolean (qp 'the-qp'))}}
54
+ * ...
55
+ * {{/if}}
56
+ * </template>
57
+ * ```
58
+ *
17
59
  * The following values are considered "false"
18
60
  * - undefined
19
61
  * - ""
package/dist/qp.js CHANGED
@@ -3,7 +3,18 @@ import { assert } from '@ember/debug';
3
3
  import { service } from '@ember/service';
4
4
  import { g, i } from 'decorator-transforms/runtime';
5
5
 
6
- class QP extends Helper {
6
+ /**
7
+ * Grabs a query-param off the current route from the router service.
8
+ *
9
+ * ```gjs
10
+ * import { qp } from 'ember-primitives/qp';
11
+ *
12
+ * <template>
13
+ * {{qp "query-param"}}
14
+ * </template>
15
+ * ```
16
+ */
17
+ class qp extends Helper {
7
18
  static {
8
19
  g(this.prototype, "router", [service]);
9
20
  }
@@ -13,11 +24,48 @@ class QP extends Helper {
13
24
  return this.router.currentRoute?.queryParams?.[name];
14
25
  }
15
26
  }
16
- const qp = QP;
27
+
28
+ /**
29
+ * Returns a string for use as an `href` on `<a>` tags, updated with the passed query param
30
+ *
31
+ * ```gjs
32
+ * import { withQP } from 'ember-primitives/qp';
33
+ *
34
+ * <template>
35
+ * <a href={{withQP "foo" "2"}}>
36
+ * ...
37
+ * </a>
38
+ * </template>
39
+ * ```
40
+ */
41
+ class withQP extends Helper {
42
+ static {
43
+ g(this.prototype, "router", [service]);
44
+ }
45
+ #router = (i(this, "router"), void 0);
46
+ compute([qpName, nextValue]) {
47
+ const existing = this.router.currentURL;
48
+ assert('A queryParam name is required', qpName);
49
+ assert('There is no currentURL', existing);
50
+ const url = new URL(existing, location.origin);
51
+ url.searchParams.set(qpName, nextValue);
52
+ return url.href;
53
+ }
54
+ }
17
55
 
18
56
  /**
19
57
  * Cast a query-param string value to a boolean
20
58
  *
59
+ * ```gjs
60
+ * import { castToBoolean, qp } from 'ember-primitives/qp';
61
+ *
62
+ * <template>
63
+ * {{#if (castToBoolean (qp 'the-qp'))}}
64
+ * ...
65
+ * {{/if}}
66
+ * </template>
67
+ * ```
68
+ *
21
69
  * The following values are considered "false"
22
70
  * - undefined
23
71
  * - ""
@@ -40,5 +88,5 @@ function castToBoolean(x) {
40
88
  return true;
41
89
  }
42
90
 
43
- export { castToBoolean, qp };
91
+ export { castToBoolean, qp, withQP };
44
92
  //# sourceMappingURL=qp.js.map
package/dist/qp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"qp.js","sources":["../src/qp.ts"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\n\nimport type RouterService from '@ember/routing/router-service';\n\nexport interface Signature {\n Args: {\n Positional: [string];\n };\n Return: string | undefined;\n}\n\nclass QP extends Helper<Signature> {\n @service declare router: RouterService;\n\n compute([name]: [string]): string | undefined {\n assert('A queryParam name is required', name);\n\n return this.router.currentRoute?.queryParams?.[name] as string | undefined;\n }\n}\n\nexport const qp = QP;\n\n/**\n * Cast a query-param string value to a boolean\n *\n * The following values are considered \"false\"\n * - undefined\n * - \"\"\n * - \"0\"\n * - false\n * - \"f\"\n * - \"off\"\n * - \"no\"\n * - \"null\"\n * - \"undefined\"\n *\n * All other values are considered truthy\n */\nexport function castToBoolean(x: string | undefined) {\n if (!x) return false;\n\n const isFalsey =\n x === '0' ||\n x === 'false' ||\n x === 'f' ||\n x === 'null' ||\n x === 'off' ||\n x === 'undefined' ||\n x === 'no';\n\n if (isFalsey) return false;\n\n // All other values are considered truthy\n return true;\n}\n"],"names":["QP","Helper","g","prototype","service","i","void 0","compute","name","assert","router","currentRoute","queryParams","qp","castToBoolean","x","isFalsey"],"mappings":";;;;;AAaA,MAAMA,EAAE,SAASC,MAAM,CAAY;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAChCC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACC,IAAI,CAAW,EAAsB;AAC5CC,IAAAA,MAAM,CAAC,+BAA+B,EAAED,IAAI,CAAC;IAE7C,OAAO,IAAI,CAACE,MAAM,CAACC,YAAY,EAAEC,WAAW,GAAGJ,IAAI,CAAC;AACtD;AACF;AAEO,MAAMK,EAAE,GAAGb;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASc,aAAaA,CAACC,CAAqB,EAAE;AACnD,EAAA,IAAI,CAACA,CAAC,EAAE,OAAO,KAAK;AAEpB,EAAA,MAAMC,QAAQ,GACZD,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,OAAO,IACbA,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,MAAM,IACZA,CAAC,KAAK,KAAK,IACXA,CAAC,KAAK,WAAW,IACjBA,CAAC,KAAK,IAAI;EAEZ,IAAIC,QAAQ,EAAE,OAAO,KAAK;;AAE1B;AACA,EAAA,OAAO,IAAI;AACb;;;;"}
1
+ {"version":3,"file":"qp.js","sources":["../src/qp.ts"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\n\nimport type RouterService from '@ember/routing/router-service';\n\ninterface Signature {\n Args: {\n Positional: [string];\n };\n Return: string | undefined;\n}\n\n/**\n * Grabs a query-param off the current route from the router service.\n *\n * ```gjs\n * import { qp } from 'ember-primitives/qp';\n *\n * <template>\n * {{qp \"query-param\"}}\n * </template>\n * ```\n */\nexport class qp extends Helper<Signature> {\n @service declare router: RouterService;\n\n compute([name]: [string]): string | undefined {\n assert('A queryParam name is required', name);\n\n return this.router.currentRoute?.queryParams?.[name] as string | undefined;\n }\n}\n\n/**\n * Returns a string for use as an `href` on `<a>` tags, updated with the passed query param\n *\n * ```gjs\n * import { withQP } from 'ember-primitives/qp';\n *\n * <template>\n * <a href={{withQP \"foo\" \"2\"}}>\n * ...\n * </a>\n * </template>\n * ```\n */\nexport class withQP extends Helper<{ Args: { Positional: [string, string] }; Return: string }> {\n @service declare router: RouterService;\n\n compute([qpName, nextValue]: [string, string]) {\n const existing = this.router.currentURL;\n\n assert('A queryParam name is required', qpName);\n assert('There is no currentURL', existing);\n\n const url = new URL(existing, location.origin);\n\n url.searchParams.set(qpName, nextValue);\n\n return url.href;\n }\n}\n\n/**\n * Cast a query-param string value to a boolean\n *\n * ```gjs\n * import { castToBoolean, qp } from 'ember-primitives/qp';\n *\n * <template>\n * {{#if (castToBoolean (qp 'the-qp'))}}\n * ...\n * {{/if}}\n * </template>\n * ```\n *\n * The following values are considered \"false\"\n * - undefined\n * - \"\"\n * - \"0\"\n * - false\n * - \"f\"\n * - \"off\"\n * - \"no\"\n * - \"null\"\n * - \"undefined\"\n *\n * All other values are considered truthy\n */\nexport function castToBoolean(x: string | undefined) {\n if (!x) return false;\n\n const isFalsey =\n x === '0' ||\n x === 'false' ||\n x === 'f' ||\n x === 'null' ||\n x === 'off' ||\n x === 'undefined' ||\n x === 'no';\n\n if (isFalsey) return false;\n\n // All other values are considered truthy\n return true;\n}\n"],"names":["qp","Helper","g","prototype","service","i","void 0","compute","name","assert","router","currentRoute","queryParams","withQP","qpName","nextValue","existing","currentURL","url","URL","location","origin","searchParams","set","href","castToBoolean","x","isFalsey"],"mappings":";;;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,EAAE,SAASC,MAAM,CAAY;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CACvCC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACC,IAAI,CAAW,EAAsB;AAC5CC,IAAAA,MAAM,CAAC,+BAA+B,EAAED,IAAI,CAAC;IAE7C,OAAO,IAAI,CAACE,MAAM,CAACC,YAAY,EAAEC,WAAW,GAAGJ,IAAI,CAAC;AACtD;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,MAAM,SAASZ,MAAM,CAA6D;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC5FC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACO,MAAM,EAAEC,SAAS,CAAmB,EAAE;AAC7C,IAAA,MAAMC,QAAQ,GAAG,IAAI,CAACN,MAAM,CAACO,UAAU;AAEvCR,IAAAA,MAAM,CAAC,+BAA+B,EAAEK,MAAM,CAAC;AAC/CL,IAAAA,MAAM,CAAC,wBAAwB,EAAEO,QAAQ,CAAC;IAE1C,MAAME,GAAG,GAAG,IAAIC,GAAG,CAACH,QAAQ,EAAEI,QAAQ,CAACC,MAAM,CAAC;IAE9CH,GAAG,CAACI,YAAY,CAACC,GAAG,CAACT,MAAM,EAAEC,SAAS,CAAC;IAEvC,OAAOG,GAAG,CAACM,IAAI;AACjB;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,CAAqB,EAAE;AACnD,EAAA,IAAI,CAACA,CAAC,EAAE,OAAO,KAAK;AAEpB,EAAA,MAAMC,QAAQ,GACZD,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,OAAO,IACbA,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,MAAM,IACZA,CAAC,KAAK,KAAK,IACXA,CAAC,KAAK,WAAW,IACjBA,CAAC,KAAK,IAAI;EAEZ,IAAIC,QAAQ,EAAE,OAAO,KAAK;;AAE1B;AACA,EAAA,OAAO,IAAI;AACb;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-primitives",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Making apps easier to build",
5
5
  "sideEffects": [
6
6
  "*.css"