typebars 1.0.16 → 1.0.18

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.
Files changed (38) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/analyzer.js +1 -1
  3. package/dist/cjs/analyzer.js.map +1 -1
  4. package/dist/cjs/executor.d.ts +1 -1
  5. package/dist/cjs/executor.js +1 -1
  6. package/dist/cjs/executor.js.map +1 -1
  7. package/dist/cjs/helpers/index.d.ts +1 -1
  8. package/dist/cjs/helpers/index.js +1 -1
  9. package/dist/cjs/helpers/index.js.map +1 -1
  10. package/dist/cjs/helpers/{collection-helpers.d.ts → map-helpers.d.ts} +4 -4
  11. package/dist/cjs/helpers/map-helpers.js +2 -0
  12. package/dist/cjs/helpers/map-helpers.js.map +1 -0
  13. package/dist/cjs/typebars.d.ts +1 -3
  14. package/dist/cjs/typebars.js +1 -1
  15. package/dist/cjs/typebars.js.map +1 -1
  16. package/dist/cjs/types.d.ts +10 -14
  17. package/dist/cjs/types.js.map +1 -1
  18. package/dist/esm/analyzer.js +1 -1
  19. package/dist/esm/analyzer.js.map +1 -1
  20. package/dist/esm/executor.d.ts +1 -1
  21. package/dist/esm/executor.js +1 -1
  22. package/dist/esm/executor.js.map +1 -1
  23. package/dist/esm/helpers/index.d.ts +1 -1
  24. package/dist/esm/helpers/index.js +1 -1
  25. package/dist/esm/helpers/index.js.map +1 -1
  26. package/dist/esm/helpers/{collection-helpers.d.ts → map-helpers.d.ts} +4 -4
  27. package/dist/esm/helpers/map-helpers.js +2 -0
  28. package/dist/esm/helpers/map-helpers.js.map +1 -0
  29. package/dist/esm/typebars.d.ts +1 -3
  30. package/dist/esm/typebars.js +1 -1
  31. package/dist/esm/typebars.js.map +1 -1
  32. package/dist/esm/types.d.ts +10 -14
  33. package/dist/esm/types.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/cjs/helpers/collection-helpers.js +0 -2
  36. package/dist/cjs/helpers/collection-helpers.js.map +0 -1
  37. package/dist/esm/helpers/collection-helpers.js +0 -2
  38. package/dist/esm/helpers/collection-helpers.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/helpers/collection-helpers.ts"],"sourcesContent":["import type { HelperDefinition } from \"../types.ts\";\nimport { HelperFactory } from \"./helper-factory.ts\";\n\n// ─── CollectionHelpers ───────────────────────────────────────────────────────\n// Aggregates all collection-related helpers for the template engine.\n//\n// Provides helpers for working with arrays of objects:\n//\n// - **`collect`** — Extracts a specific property from each element of an\n// array, returning a new array of those values.\n// Usage: `{{ collect users \"name\" }}` → `[\"Alice\", \"Bob\", \"Charlie\"]`\n//\n// ─── Registration ────────────────────────────────────────────────────────────\n// CollectionHelpers are automatically pre-registered by the `Typebars`\n// constructor. They can also be registered manually on any object\n// implementing `HelperRegistry`:\n//\n// const factory = new CollectionHelpers();\n// factory.register(engine); // registers all helpers\n// factory.unregister(engine); // removes all helpers\n//\n// ─── Static Analysis ─────────────────────────────────────────────────────────\n// The `collect` helper has special static analysis handling in the analyzer:\n// - The first argument must resolve to an array of objects\n// - The second argument must be a quoted string literal (e.g. `\"name\"`, not `name`)\n// - The property must exist in the item schema of the array\n// - The inferred return type is `{ type: \"array\", items: <property schema> }`\n\n// ─── Internal utilities ─────────────────────────────────────────────────────\n\n/**\n * Extracts a property from each element of an array.\n *\n * @param collection - The array of objects\n * @param property - The property name to extract from each element\n * @returns A new array containing the extracted property values\n */\nfunction collectProperty(collection: unknown, property: unknown): unknown[] {\n\tif (!Array.isArray(collection)) {\n\t\treturn [];\n\t}\n\tconst prop = String(property);\n\t// Use flatMap semantics: if the collection contains nested arrays\n\t// (e.g. from a previous collect), flatten one level before extracting.\n\t// This enables chaining like `{{ collect (collect users 'cartItems') 'productId' }}`\n\t// where the inner collect returns an array of arrays.\n\tconst flattened = collection.flat(1);\n\treturn flattened.map((item: unknown) => {\n\t\tif (item !== null && item !== undefined && typeof item === \"object\") {\n\t\t\treturn (item as Record<string, unknown>)[prop];\n\t\t}\n\t\treturn undefined;\n\t});\n}\n\n// ─── Main class ─────────────────────────────────────────────────────────────\n\nexport class CollectionHelpers extends HelperFactory {\n\t/** The name used for special-case detection in the analyzer/executor */\n\tstatic readonly COLLECT_HELPER_NAME = \"collect\";\n\n\t// ─── buildDefinitions (required by HelperFactory) ──────────────────\n\n\tprotected buildDefinitions(defs: Map<string, HelperDefinition>): void {\n\t\tthis.registerCollect(defs);\n\t}\n\n\t// ── collect ──────────────────────────────────────────────────────────\n\n\t/** Registers the `collect` helper */\n\tprivate registerCollect(defs: Map<string, HelperDefinition>): void {\n\t\tdefs.set(CollectionHelpers.COLLECT_HELPER_NAME, {\n\t\t\tfn: (collection: unknown, property: unknown) =>\n\t\t\t\tcollectProperty(collection, property),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"collection\",\n\t\t\t\t\ttype: { type: \"array\" },\n\t\t\t\t\tdescription: \"The array of objects to extract values from\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"property\",\n\t\t\t\t\ttype: { type: \"string\" },\n\t\t\t\t\tdescription: \"The property name to extract from each element\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"array\" },\n\t\t\tdescription:\n\t\t\t\t'Extracts a property from each element of an array: {{ collect users \"name\" }} → [\"Alice\", \"Bob\", \"Charlie\"]',\n\t\t});\n\t}\n}\n"],"names":["HelperFactory","collectProperty","collection","property","Array","isArray","prop","String","flattened","flat","map","item","undefined","CollectionHelpers","buildDefinitions","defs","registerCollect","set","COLLECT_HELPER_NAME","fn","params","name","type","description","returnType"],"mappings":"oLACA,OAASA,aAAa,KAAQ,qBAAsB,CAoCpD,SAASC,gBAAgBC,UAAmB,CAAEC,QAAiB,EAC9D,GAAI,CAACC,MAAMC,OAAO,CAACH,YAAa,CAC/B,MAAO,EAAE,AACV,CACA,MAAMI,KAAOC,OAAOJ,UAKpB,MAAMK,UAAYN,WAAWO,IAAI,CAAC,GAClC,OAAOD,UAAUE,GAAG,CAAC,AAACC,OACrB,GAAIA,OAAS,MAAQA,OAASC,WAAa,OAAOD,OAAS,SAAU,CACpE,OAAO,AAACA,IAAgC,CAACL,KAAK,AAC/C,CACA,OAAOM,SACR,EACD,CAIA,OAAO,MAAMC,0BAA0Bb,cAMtC,AAAUc,iBAAiBC,IAAmC,CAAQ,CACrE,IAAI,CAACC,eAAe,CAACD,KACtB,CAKA,AAAQC,gBAAgBD,IAAmC,CAAQ,CAClEA,KAAKE,GAAG,CAACJ,kBAAkBK,mBAAmB,CAAE,CAC/CC,GAAI,CAACjB,WAAqBC,WACzBF,gBAAgBC,WAAYC,UAC7BiB,OAAQ,CACP,CACCC,KAAM,aACNC,KAAM,CAAEA,KAAM,OAAQ,EACtBC,YAAa,6CACd,EACA,CACCF,KAAM,WACNC,KAAM,CAAEA,KAAM,QAAS,EACvBC,YAAa,gDACd,EACA,CACDC,WAAY,CAAEF,KAAM,OAAQ,EAC5BC,YACC,6GACF,EACD,CACD,CAhCC,iBAFYV,kBAEIK,sBAAsB"}