{"id":20336776,"url":"https://github.com/abelflopes/snippets","last_synced_at":"2026-03-07T02:03:46.321Z","repository":{"id":179220936,"uuid":"426471985","full_name":"abelflopes/snippets","owner":"abelflopes","description":"Typescript code snippets \u0026 utils","archived":false,"fork":false,"pushed_at":"2022-03-08T17:34:49.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-11T04:03:09.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abelflopes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-10T03:29:25.000Z","updated_at":"2021-11-10T03:35:00.000Z","dependencies_parsed_at":"2023-07-12T01:45:34.621Z","dependency_job_id":null,"html_url":"https://github.com/abelflopes/snippets","commit_stats":null,"previous_names":["abelflopes/snippets"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abelflopes/snippets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelflopes%2Fsnippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelflopes%2Fsnippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelflopes%2Fsnippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelflopes%2Fsnippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abelflopes","download_url":"https://codeload.github.com/abelflopes/snippets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abelflopes%2Fsnippets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30205893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"online","status_checked_at":"2026-03-07T02:00:06.765Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T21:06:47.487Z","updated_at":"2026-03-07T02:03:46.295Z","avatar_url":"https://github.com/abelflopes.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snippets\n\nTypescript code snippets \u0026amp; utils.\n\n## Sequential Promise Array Execution\n\nUnlike `Promise.all`, you can sequentially execute promises using `Array.reduce`.\n\n```ts\nconst dummyFn = (): Promise\u003cvoid\u003e =\u003e\n  new Promise((resolve) =\u003e {\n    console.log(\"start\");\n    setTimeout(() =\u003e {\n      console.log(\"end\", new Date());\n      resolve();\n    }, 1500);\n  });\n\nconst sequentialPromiseAll = (\n  arr: (() =\u003e Promise\u003cvoid\u003e)[]\n): Promise\u003cvoid\u003e =\u003e {\n  return arr.reduce\u003cPromise\u003cvoid\u003e\u003e(\n    (prev, curr) =\u003e prev.then(() =\u003e curr()),\n    new Promise((resolve) =\u003e resolve())\n  );\n};\n\nawait sequentialPromiseAll([dummyFn, dummyFn, dummyFn]);\n```\n\n[Codepen](https://codepen.io/abelflopes/pen/PoKayWy)\n\n## Create a type with common properties of 2 interfaces\n\nThe resulting type will only accept properties `b` \u0026 `z`.\n\n```ts\ninterface I1 {\n  a: number;\n  b: number;\n  z: number;\n}\n\ninterface I2 {\n  b: number;\n  c: number;\n  z: number;\n}\n\ntype CommonIntersection\u003cT1, T2\u003e = {\n  [Property in keyof T1 \u0026 keyof T2]: (T1 \u0026 T2)[Property];\n};\n\nconst X: CommonIntersection\u003cI1, I2\u003e = {\n  b: 1,\n  z: 2,\n};\n```\n\n\n## Webpack plugin template\n\n```ts\n/* eslint-disable @typescript-eslint/no-var-requires */\nimport { Compiler } from \"webpack\";\nimport { log, chalk } from \"@advicefront/log\";\n\nexport type CustomWebpackPluginOptions = {\n  /* options here */\n};\n\nexport class CustomWebpackPlugin {\n  private options: CustomWebpackPluginOptions;\n\n  constructor(options: CustomWebpackPluginOptions) {\n    this.options = options;\n  }\n\n  /**\n   * Apply function (called by webpack)\n   * Webpack compiler docs: https://webpack-v3.jsx.app/api/compiler/\n   * @param compiler Compiler\n   */\n\n  public apply = (compiler: Compiler): void =\u003e {\n    // Display all hooks\n    Object.keys(compiler.hooks).forEach((hook) =\u003e {\n      // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n      compiler.hooks[hook].tap(\"CustomWebpackPlugin\", () =\u003e {\n        log(chalk.yellow(hook));\n      });\n    });\n\n    compiler.hooks.beforeCompile.tapPromise(\"CustomWebpackPlugin\", async (): Promise\u003cvoid\u003e =\u003e {\n      /**\n       * Code to execute here\n       */\n    });\n  };\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabelflopes%2Fsnippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabelflopes%2Fsnippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabelflopes%2Fsnippets/lists"}