{"id":13682235,"url":"https://github.com/mlajtos/es1995","last_synced_at":"2025-04-30T07:30:58.713Z","repository":{"id":80877759,"uuid":"353684261","full_name":"mlajtos/es1995","owner":"mlajtos","description":"ES1995 – The Missing JS Polyfill","archived":false,"fork":false,"pushed_at":"2021-04-01T20:55:14.000Z","size":21,"stargazers_count":80,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-02T13:33:52.750Z","etag":null,"topics":["april-fools","javascript"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/github/mlajtos/es1995","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlajtos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-04-01T11:57:32.000Z","updated_at":"2024-06-29T03:34:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"97a683fd-3f01-4567-be72-e78fef2d9989","html_url":"https://github.com/mlajtos/es1995","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlajtos%2Fes1995","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlajtos%2Fes1995/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlajtos%2Fes1995/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlajtos%2Fes1995/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlajtos","download_url":"https://codeload.github.com/mlajtos/es1995/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224201910,"owners_count":17272664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["april-fools","javascript"],"created_at":"2024-08-02T13:01:42.653Z","updated_at":"2024-11-12T01:31:23.494Z","avatar_url":"https://github.com/mlajtos.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# ES1995 – The Missing JS Polyfill\n\nES1995 is a polyfill for super-modern Javascript that you can write today.\n\n## What people said about ES1995\n\n\u003e [Brendan Eich](https://twitter.com/BrendanEich):\n\u003e\n\u003e “I did JS in 10 days. If I had one more day, ES1995 would be there from the start.”\n\n\u003e [Alan Kay](https://en.wikiquote.org/wiki/Alan_Kay):\n\u003e\n\u003e “[…][…] The Web in comparison [to the Internet] is a joke. The Web was done by amateurs. […] JS is pile of bricks with limestone on top. […] To be precise, in case of ES1995, a change in perspective is worth **negative** 80 IQ points. […][…] […]”\n\n\u003e [Sebastian Mackenzie](https://twitter.com/sebmck):\n\u003e\n\u003e “If we had ES1995, [Rome](https://github.com/rome/tools) **would** be build in a day. Maybe less.”\n\n\u003e [Joe Armstrong](https://twitter.com/joeerl):\n\u003e\n\u003e “Discovered that I can speak tweets by pressing the microphone button and it gets it right most of the time this is amazing and saves a lot of time.\n\u003e\n\u003e One thing puzzles me.\n\u003e\n\u003e How did they fit the stenographer inside the phone?”\n\n\u003e [Alan Turing](https://en.wikipedia.org/wiki/Alan_Turing):\n\u003e\n\u003e “[TC39](https://tc39.es) can only see a short distance ahead, but they can see plenty there that needs to be done.”\n\n\u003e [Elon Musk](https://twitter.com/elonmusk):\n\u003e\n\u003e “If JS was like this from the start, humans would dominate the whole galaxy and we would have quantum-resistant Bitcoin with instant transactions running on Neuralink. \\*\\*nodding\\*\\* ”\n\n\u003e [Steve Ballmer](https://www.youtube.com/watch?v=KMU0tzLwhbE):\n\u003e\n\u003e [“DEVELOPERS DEVELOPERS DEVELOPERS”](https://www.youtube.com/watch?v=KMU0tzLwhbE)\n\n\u003e [God](https://xkcd.com/224/):\n\u003e\n\u003e “I was looking for a replacement for [Perl](https://xkcd.com/224/) and JS with ES1995 looks pretty slick!”\n\n## Showcase\n\n### Fancy FizzBuzz\n\n```js\nNumber.range(1, 101)\n  .map(\n    Function.conditional([\n      // 15 === Number.leastCommonMultiple(3, 5)\n      [(n) =\u003e n.multipleOf(15), () =\u003e \"FizzBuzz\"],\n      [(n) =\u003e n.multipleOf(5), () =\u003e \"Buzz\"],\n      [(n) =\u003e n.multipleOf(3), () =\u003e \"Fizz\"],\n      [Function.true, Function.identity]\n    ])\n  )\n  .join(\", \")\n  .pipe(console.log);\n```\n\n### Functional Objects\n\n```js\nconst count = Function.from({\n  state: 0,\n  [Symbol.callable]() {\n    this.state += 1;\n    return this.state;\n  }\n});\n\ncount().pipe(console.log);\ncount().pipe(console.log);\ncount().pipe(console.log);\n```\n\n### Number decomposition\n\n```js\nconst n = -23.47;\nconst [s, i, f] = [n.sign(), n.integerPart(), n.fractionalPart()];\nconst m = s * (i + f);\n\nconsole.assert(n === m);\n```\n\n### Array manipulation – Texas Hold'em\n\n```js\nconst suits = \"♠♥♦♣\".split(\"\");\nconst ranks = [...Number.range(2, 11), ...\"JQKA\".split(\"\")];\n\nlet deck = Array.cartesianProduct(suits, ranks).map((card) =\u003e card.join(\"\"));\n\n// Fisher-Yates + random cut\ndeck = deck.shuffle().rotate(Number.random(0, deck.length));\n\nconst players = [\"Douglas Crockford\", \"Marc Andreessen\", \"John-David Dalton\"];\n\nlet playersCards;\n[playersCards, deck] = deck.splitAt(2 * players.length);\nplayersCards = Array.zip(...playersCards.chunk(players.length));\nconst hands = Object.fromEntries(players.zip(playersCards));\n\nlet flop, turn, river;\n\n[flop, deck] = deck.drop(1).splitAt(3);\n[turn, deck] = deck.drop(1).splitAt(1);\n[river, deck] = deck.drop(1).splitAt(1);\n\nconst game = {\n  hands,\n  community: { flop, turn, river }\n};\n\nconsole.log(game);\n```\n\n### Merge Sort\n\n```js\nconst mergeSort = (L) =\u003e\n  L.length \u003c= 1\n    ? L\n    : L.splitAt(L.length / 2)\n        .map(mergeSort)\n        .pipe((L) =\u003e merge(...L));\n\nconst merge = Function.conditional([\n  [(A, B) =\u003e A.empty() || B.empty(), (A, B) =\u003e A.concat(B)],\n  [([a], [b]) =\u003e a \u003c b, ([a, ...A], B) =\u003e [a, ...merge(A, B)]],\n  [Function.true, (A, B) =\u003e merge(B, A)] // ba-dum-ts\n]);\n\nNumber.range(10).shuffle().pipe(mergeSort).pipe(console.log);\n```\n\n### Fuzzy string match\n\n```js\nconst names = [\n  \"Timothée\",\n  \"Beyoncé\",\n  \"Penélope\",\n  \"Renée\",\n  \"Clémence\",\n  \"Zoë\",\n  \"Chloë\",\n  \"Øyvind\",\n  \"Žofia\",\n  \"Michał\",\n  \"Clémentine\"\n];\n\nconst searchTerm = \"cle\";\n\nnames\n  .map((name) =\u003e name.removeDiacritics().toLowerCase())\n  // Sørensen–Dice coefficient: 0.0 – 1.0\n  .map((safeName) =\u003e searchTerm.similarityTo(safeName))\n  .zip(names)\n  .sorted(([a], [b]) =\u003e b - a)\n  .take(3)\n  .pipe(console.log);\n// [0.4444444444444444, \"Clémence\"]\n// [0.36363636363636365, \"Clémentine\"]\n// [0, \"Timothée\"]\n```\n\n### Fun fun fun\n\n```js\nconst fetchArticle = (id) =\u003e {\n  // get the latest hot shit from Hacker News\n};\nconst fetchArticleOnlyOnce = fetchArticle.memoize();\n```\n\n```js\nconst onResizeWindow = () =\u003e {\n  // recalculate expensive layout\n};\nconst smartOnResizeWindow = onResizeWindow.debounce(150);\n```\n\n```js\nconst onClick = () =\u003e {\n  // http://clickclickclick.click\n};\nconst rateLimitedOnClick = onClick.throttle(1000);\n```\n\n```js\nconst add = (a, b) =\u003e a + b;\nconst add10 = add.partial(10);\n```\n\n### Array Indexing\n\n```js\nconst squares = Number.range(10).map((i) =\u003e i ** 2);\nconst squareAtFirst = squares.at(1);\n\nconst oddIndices = Number.range(1, 10, 2);\nconst squaresAtOddIndices = squares.at(oddIndices);\n```\n\n---\n\nCheckout `src/es1995.js` for other funky stuff.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlajtos%2Fes1995","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlajtos%2Fes1995","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlajtos%2Fes1995/lists"}