{"_id":"@dennisdigital/injection-engine","_rev":"1-05a9230c5cd5665ea54df95d61fed331","name":"@dennisdigital/injection-engine","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@dennisdigital/injection-engine","version":"1.0.0","main":"dist/index.js","module":"src/index.js","dependencies":{"react":"16.8.5","react-dom":"16.8.5"},"peerDependencies":{"react":"^15.0.0 || ^16.0.0","react-dom":"^15.0.0 || ^16.0.0"},"scripts":{"bootstrap":"lerna bootstrap --use-workspaces"},"publishConfig":{"access":"public"},"gitHead":"c6b6ea5d6269bf0179e86381f7770a4002d760eb","description":"Each array item is iterated over and has each of the provided rules applied to it. If the rule condition passes then the component specified by the rule is injected after the current item. A counter of how many of such components have been injected is kep","_id":"@dennisdigital/injection-engine@1.0.0","_nodeVersion":"10.14.0","_npmVersion":"lerna/3.20.2/node@v10.14.0+x64 (darwin)","dist":{"integrity":"sha512-jsWmW6YLDBYK7h3sPSuFtDf1vJAQ7fqO8vkweeiZiHHyzwkA1Iu+otTmyRKYUaHe+8ly7s6eyvDfzjVFhi7q8g==","shasum":"80ed2ec62c629b857d60089ab702edd9a59f8ce5","tarball":"https://registry.npmjs.org/@dennisdigital/injection-engine/-/injection-engine-1.0.0.tgz","fileCount":17,"unpackedSize":29999,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeT6nUCRA9TVsSAnZWagAAtdUP/jGntEsUa+CYRalydAyv\nX77iw/YvxqEcxGiPX9Qln3nKBMkX2HncTPhB2AoGbkG5LQk6o6AQxEfsZYGf\nBJHVeRZyzSxeHuCBxCZAn0lD9p+QwMLvZG3NagmjJ5OLFqGwvnLsIJTHWG3g\n4NzmUaD93WXS+tKju0N1V/HrZOKLQ6ESILQuskf9FAWNpjxVo6+8ezp/Yb5R\n5NiZkW46QlIYabGjBlIGXRbLJydee8lc344HAp+akzX0n3BaIu3rmLMNcPd+\nu5br2OVTv2Yu5q3IoD8GsHIV0yYMu6oKcB7kBbXBBk6tXMA7GglXQX8EQ8Gy\nrHAyEuKCl5ooVAUCbduH715YGvvz5tgIgYZhZsw4wWMbr+J+EhdReD4huphS\n9NiDoUKObfAXM/7D/Moc7pDHn2/Ft+BmXPYowq5ssVLn94eqIWnDythNleX8\ncRQzMFDPVUKojcleUt5aJbAvma/jNeE/q7C/cXMGoNmEr/BhMxL+990mN2ry\nzAjI8CnPL86fVwMoYUN3pBZ1PmMvVWQlebCSPnrTwuRjc9CBzlnTaBXXH+iQ\npWEvcWzlYReiVZGvFzCV2sczzXmmqUXg3bPE6OA4XqPtoD5UD5CVjT9H4c4e\n+9b15vDNwnN7gJ9lmYLWq4eO2rCLKlYQwcZ7ilnIb4aJbztnPtzQk+GC30mk\nz2AW\r\n=VrZM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICKl4Gst1wnE8eQZAVYnmg4E9GFdCa1EInHSrb9kt2uUAiBMmdGMk/8qKO78wVjPDc/yCjPPMsvknQAFcOqK7fA6yQ=="}]},"maintainers":[{"name":"iliasp","email":"ilias.pittas1@gmail.com"},{"name":"majdanas","email":"majjda@hotmail.com"},{"name":"chriskinch","email":"kinchie@gmail.com"},{"name":"willhowlett","email":"bigwillchnpm@gmail.com"},{"name":"asvin","email":"asvin.balloo@gmail.com"}],"_npmUser":{"name":"iliasp","email":"ilias.pittas1@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/injection-engine_1.0.0_1582279124343_0.6447889372415401"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-21T09:58:44.122Z","1.0.0":"2020-02-21T09:58:44.560Z","modified":"2022-04-05T03:45:19.027Z"},"maintainers":[{"name":"iliasp","email":"ilias.pittas1@gmail.com"},{"name":"majdanas","email":"majjda@hotmail.com"},{"name":"chriskinch","email":"kinchie@gmail.com"},{"name":"willhowlett","email":"bigwillchnpm@gmail.com"},{"name":"asvin","email":"asvin.balloo@gmail.com"}],"description":"Each array item is iterated over and has each of the provided rules applied to it. If the rule condition passes then the component specified by the rule is injected after the current item. A counter of how many of such components have been injected is kep","readme":"# `injectionEngine`\n\nEach array item is iterated over and has each of the provided rules applied to it. If the rule condition passes then the component specified by the rule is injected after the current item. A counter of how many of such components have been injected is kept (by using the rule's componentType) and exposed by the function for other rules to use. Different rules might be adding the same components, in which case the relevant counter will be updated. A counter of how many times each rule has passed is also kept and exposed (by using the rule's unique id). Please ensure that when modifying/adding rules ids are unique.\n\n\n## Usage:\n```jsx\nimport { injectionRules } from '@dennisdigital/injection-rules-helpers';\n\n\nconst bodyInjected = injectionEngine({\n  body, // body array returned by GraphQL\n  rules, // rules to be applied on each body array element \n  amp,  // whether amp or not\n  props: propsToInject, // props that we want to pass in the injectionEngine function to be used by the rules\n});\n\nrender() {\n  return (\n    <Body\n      bodyInjected={injectBodyData} template={template}\n    />\n  )\n}\n```\n\n## Defining Rules\n\nThe `rules` parameter is an array of objects containing all the rules you want to apply in the body elements. Each object will have the following structure:\n\n```js\n {\n  id: 'inline-and-side', // used by injectionEngine function to keep track of how many times the object injected by the that individual rule has been injected up the current iteration\n  componentType: 'desktopSideAndInlineAd' // used by injectionEngine function to keep track of how many times the component injected has been injected up the current iteration\n  condition: options => shouldInject(options), // this is the logic that decides whether to inject or not\n  component: ({ componentCount: adCount }) => getAdsConfig(adCount), // this is used by injectionEngine function to pass props needed by the component injected. The props that are passed into the injectionEngine function as well as the componentCount (how many times this component has been injected) are available by the function (props are not being used in this case)\n  resetCurrentItemTypeCurrentCounter: true, // this determines whether you want to reset the current type count after you inject the component. Used for restarting the count once the component gets injected - that count is then compared with config (eg numberOfWordsBetweenInlineDesktopAds) to decide whether component will be injected \n};\n```\n\n## `condition`\n\nThis is a function you must provide to decide if your component will be injected at this point. When called each `condition` function will be provided an object parameter with the following properties which can be used for your logic\n\n * `amp` Boolean that says whether the page is amp or not (defaults to `false`)\n * `bodyElements` Array of body elements you can check against\n * `bodyIndex` The current index of the body element being checked against\n * `currentRuleInjectedComponentCount` The total number of current type of components injected (uses the shared componentType to keep track)\n * `currentRuleComponentTypeWordCount` The total number of word count by specific rule (uses unique rule id to keep track)\n * `currentType` The current type of body element being checked against\n * `currentTypeCurrentCount` The current number of times the current type has been iterated over in the array after the count reset took place (this number will equal the `currentTypeTotalCount` if no reset took place)\n * `currentTypeTotalCount` The total number of times that the current type has been iterated over in the array\n * `injectedArray` Injected array up to the current iteration\n * `nextType` The next type of body element in the array\n * `prevType` The next type of body element in the array\n * `props` The props being passed into the injectionEngine to be used by the rules\n * `totalWordCount` Total word count up to the current iteration\n\n\n## `component`\n\nThis can either return an Array of data objects that the `<Body/>` component knows how to parse, or just an Array of normal React components\n\n_Data object example_\n\n```js\ncomponent: (props) => [{\n  type: 'HEADER',\n  data: `Hi there ${props.name}`,\n}]\n```\n\n_React component example_\n\n```js\ncomponent: (props) => [\n  <Card\n    title={props.title}\n  />\n]\n```\n\nor\n\n```js\ncomponent: ({ componentCount: adCount }) => getAdsConfig(adCount),\n```\n\nThe component function has access to the props that are passed into the injectionEngine function as well as the componentCount that is provided by the injectionEngine, (how many times this component has been injected) are available by the function (props are not being used in this case)\n\n## `resetCurrentItemTypeCurrentCounter`\n\nThe function keeps track of the count (both total and current - ie. for when counter gets reset) and matches this count against the rules to decide whether to inject or not. \n\nFor example imagine that we want to inject a component every 7 text block. The `injectionEngine` function exposes two properties, the `currentTypeCurrentCount` and the `currentTypeTotalCount`. Both count the number of current type blocks elapsed. The difference is that when we inject a block and the `resetCurrentItemTypeCurrentCounter` flag is `true`, the `currentTypeCurrentCount` will get reset so it starts counting from zero again and when it reaches 7, the confition will be met again. The `currentTypeTotalCount` will continue counting the total number of current type blocks iterated over without being reset.","readmeFilename":"README.md"}