{"_id":"@a15-ghm/gh-ngrx-elements","_rev":"2-188c62cf361d9252c852cd375d44ef82","name":"@a15-ghm/gh-ngrx-elements","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@a15-ghm/gh-ngrx-elements","version":"1.0.0","peerDependencies":{"@angular/common":"^16.2.12","@angular/core":"^16.2.12","@ngrx/store":"^16.3.0","@a15-ghm/gh-models":"^1.2.0"},"dependencies":{"tslib":"^2.3.0"},"sideEffects":false,"module":"fesm2022/a15-ghm-gh-ngrx-elements.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/a15-ghm-gh-ngrx-elements.mjs","esm":"./esm2022/a15-ghm-gh-ngrx-elements.mjs","default":"./fesm2022/a15-ghm-gh-ngrx-elements.mjs"}},"_id":"@a15-ghm/gh-ngrx-elements@1.0.0","gitHead":"8553d0cecdb23057eb6856271c582d4ee5d33948","description":"This Angular library contains sharable NgRx elements such as selectors, actions, and related functions. It allows to reuse these elements without duplication code in another Angular libraries or Angular applications.","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-enmglcJAMj+ixXq7rDqO/ZFv7oLyuy7Aym4Tni7s8iodZ0a8VQFkxfFnvXDkpel/aiRNR6bdTAMOapUaKnxLaw==","shasum":"5ef752907a6b3bc18d57ef48289e38a40742c6b7","tarball":"https://registry.npmjs.org/@a15-ghm/gh-ngrx-elements/-/gh-ngrx-elements-1.0.0.tgz","fileCount":16,"unpackedSize":18881,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIATgJKdHbofa1Z+R2R9A2EdV6QomTnNg6KR4HO94GbDiAiEAlQR5QGcvm4HYz/n8d9Inveh629gp/x6n3V8diobU0VU="}]},"_npmUser":{"name":"devops-ghm-npm","email":"dev@goldenhippo.com"},"directories":{},"maintainers":[{"name":"devops-ghm-npm","email":"dev@goldenhippo.com"},{"name":"danni.liu","email":"danni.liu@goldenhippo.com"},{"name":"s.bely","email":"s.bely@itransition.com"},{"name":"kiskina_victoria","email":"v.kiskina@itransition.com"},{"name":"sergey.kuzovlev","email":"s.kuzovlev@itransition.com"},{"name":"s.bozhik","email":"s.bozhik@itransition.com"},{"name":"brian.park","email":"brian@goldenhippo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gh-ngrx-elements_1.0.0_1700559073598_0.18481934752092988"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-21T09:31:13.515Z","1.0.0":"2023-11-21T09:31:13.758Z","modified":"2024-05-21T15:51:03.514Z"},"maintainers":[{"email":"dev@goldenhippo.com","name":"devops-ghm-npm"},{"email":"danni.liu@goldenhippo.com","name":"danni.liu"},{"email":"v.kiskina@itransition.com","name":"kiskina_victoria"},{"email":"s.kuzovlev@itransition.com","name":"sergey.kuzovlev"},{"email":"brian@goldenhippo.com","name":"brian.park"}],"description":"This Angular library contains sharable NgRx elements such as selectors, actions, and related functions. It allows to reuse these elements without duplication code in another Angular libraries or Angular applications.","readme":"# gh-ngrx-elements\n\nThis Angular library contains sharable NgRx elements such as selectors, actions, and related functions. It allows to reuse these elements without duplication code in another Angular libraries or Angular applications.\n\n## Sharable selectors\n\n1. `cartSubtotalBeforeDiscountSelector`\n   The selector returns product prices in the cart before discounts, tax and shipping calculation, only the total price of all products and variants. For calculation `state.ghCartState.cart.products` and `state.ghCartState.cart.variants` are used.\n\n## Sharable utils\n\n1.  `calculateCartSubtotal`\n    The function returns the subtotal price of incoming products and variants.\n\n```ts\ncalculateCartSubtotal(products: Products, variants: Products): number;\n```\n\n2. `getRoundedTotal`\n   The function returns a rounded price with a maximum of two decimal places.\n\n```ts\ngetRoundedTotal(total: number): number;\n```\n\n## Usage\n\nTo use these sharable elements follow these steps:\n\n### Installation\n\nInstall the `gh-ngrx-elements` library by running the following command\n\n```bash\nnpm install --save @a15-ghm/gh-ngrx-elements\n```\n\n### Importing and usage selectors\n\nImport the selector to where you need it and use it\n\n```ts\nimport { Component, OnInit, inject } from '@angular/core';\nimport { Store } from '@ngrx/store';\n\nimport { IStore } from '@a15-ghm/gh-models/interfaces/store';\nimport { cartSubtotalBeforeDiscountSelector } from '@a15-ghm/gh-ngrx-elements';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent implements OnInit {\n  cartSubtotal: number;\n\n  private store: Store<IStore> = inject(Store);\n\n  ngOnInit() {\n    this.store.select(cartSubtotalBeforeDiscountSelector).subscribe((subtotal) => {\n      this.cartSubtotal = subtotal;\n    });\n  }\n}\n```\n\n### Improting and usage utilities\n\nImport the utility to where you need it and use it\n\n```ts\nimport { Component } from '@angular/core';\n\nimport { calculateCartSubtotal, getRoundedTotal } from '@a15-ghm/gh-ngrx-elements';\nimport { Product } from '@a15-ghm/gh-models/types/product';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent {\n  products: Product;\n  variants: Product;\n\n  calculateSubtotal(): number {\n    const subtotal = calculateCartSubtotal(this.products, this.variants);\n\n    return getRoundedTotal(subtotal);\n  }\n}\n```\n","readmeFilename":"README.md"}