{"id":15366129,"url":"https://github.com/keyvan-m-sadeghi/pythonic","last_synced_at":"2025-04-15T11:02:48.622Z","repository":{"id":150840263,"uuid":"75467379","full_name":"keyvan-m-sadeghi/pythonic","owner":"keyvan-m-sadeghi","description":"Python like utility functions for JavaScript: range, enumerate, zip and items.","archived":false,"fork":false,"pushed_at":"2019-03-10T10:50:22.000Z","size":31,"stargazers_count":30,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T00:35:01.404Z","etag":null,"topics":["functional","javascript","modules","python","pythonic","utilities"],"latest_commit_sha":null,"homepage":"","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/keyvan-m-sadeghi.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-03T10:31:55.000Z","updated_at":"2023-08-01T23:57:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"a5ddec3c-574b-41c8-8148-f3b3e1b069c0","html_url":"https://github.com/keyvan-m-sadeghi/pythonic","commit_stats":null,"previous_names":["assister-ai/pythonic"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyvan-m-sadeghi%2Fpythonic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyvan-m-sadeghi%2Fpythonic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyvan-m-sadeghi%2Fpythonic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keyvan-m-sadeghi%2Fpythonic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keyvan-m-sadeghi","download_url":"https://codeload.github.com/keyvan-m-sadeghi/pythonic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952358,"owners_count":21188426,"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":["functional","javascript","modules","python","pythonic","utilities"],"created_at":"2024-10-01T13:17:42.056Z","updated_at":"2025-04-15T11:02:48.585Z","avatar_url":"https://github.com/keyvan-m-sadeghi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/pythonic.svg)](https://www.npmjs.com/package/pythonic)\n[![Build Status](https://api.travis-ci.org/assister-ai/pythonic.svg?branch=master)](https://travis-ci.org/assister-ai/pythonic)\n\n# Pythonic\n\nPython like utility functions for JavaScript: `range`, `enumerate`, `items`, `zip` and `zipLongest`.\n\nThese functions return an [`Iterator`](https://github.com/assister-ai/pythonic/blob/master/index.js#L1)\ninstance similar to [Python Iterators](https://wiki.python.org/moin/Iterator).\nThis `Iterator` implementation is lazy evaluated,\noffers [`map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map),\n[`filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),\n[`reduce`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce),\n[`some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some),\n[`every`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)\nand [`Symbol.asyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)\ninterfaces.\n\n### Install\n```bash\nnpm install pythonic --save\n```\n\n### Functions\n\n#### range\n\n```javascript\nimport {range} from 'pythonic';\n\nrange(3).map(x =\u003e console.log(x + 1));\n// 1\n// 2\n// 3\n\nfor (const i of range(10, 25, 5))\n    console.log(i);\n// 10\n// 15\n// 20\n\nconsole.log(range(5).reduce((accumulator, current) =\u003e accumulator + current));\n// 10\n```\n\n#### enumerate\n\n```javascript\nimport {enumerate} from 'pythonic';\n\nconst arr = ['a', 'b'];\nfor (const [index, value] of enumerate(arr))\n    console.log(`index: ${index}, value: ${value}`);\n// index: 0, value: a\n// index: 1, value: b\n```\n\n#### zip | zipLongest\n\n```javascript\nimport {zip, zipLongest} from 'pythonic';\n\nconst arr1 = ['a', 'b'];\nconst arr2 = ['c', 'd', 'e'];\nfor (const [first, second] of zip(arr1, arr2))\n    console.log(`first: ${first}, second: ${second}`);\n// first: a, second: c\n// first: b, second: d\n\nfor (const [first, second] of zipLongest(arr1, arr2))\n    console.log(`first: ${first}, second: ${second}`);\n// first: a, second: c\n// first: b, second: d\n// first: undefined, second: e\n\n// unzip\nconst [arrayFirst, arraySecond] = [...zip(...zip(arr1, arr2))];\n```\n\n#### items\n\n```javascript\nimport {items} from 'pythonic';\n\nconst obj = {a: 'aa', b: 'bb'};\nfor (const [key, value] of items(obj))\n    console.log(`key: ${key}, value: ${value}`);\n// key: a, value: aa\n// key: b, value: bb\n\nconst map = new Map([[1, 'one'], [2, 'two']]);\nfor (const [key, value] of items(map))\n    console.log(`key: ${key}, value: ${value}`);\n// key: 1, value: one\n// key: 2, value: two\n```\n\n### Iterator\n```javascript\nimport {Iterator, range} from 'pythonic';\n\nconst randomIntegers = (size, start, stop) =\u003e new Iterator(function * () {\n    for (const _ of range(size))\n        yield Math.floor(Math.random() * (stop - start) + start);\n});\n\nconst randomNumbers = randomIntegers(3, 10, 1000);\n\nfor (const randomNumber of randomNumbers)\n    console.log(randomNumber);\n// 685\n// 214\n// 202\n\nconsole.log(randomNumbers.some(value =\u003e value \u003e 10));\n// true\nconsole.log(randomNumbers.every(value =\u003e value \u003c 1000));\n// true\n```\n\n### License\n\n[MIT](https://github.com/assister-ai/pythonic/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeyvan-m-sadeghi%2Fpythonic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeyvan-m-sadeghi%2Fpythonic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeyvan-m-sadeghi%2Fpythonic/lists"}