{"id":22021537,"url":"https://github.com/lamansky/m-o","last_synced_at":"2026-04-11T05:36:23.066Z","repository":{"id":92611987,"uuid":"112343708","full_name":"lamansky/m-o","owner":"lamansky","description":"A Node.js package of has/get/set/delete methods that work on both Maps and Objects.","archived":false,"fork":false,"pushed_at":"2018-01-22T10:42:01.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-05T08:19:29.498Z","etag":null,"topics":[],"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/lamansky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","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":"2017-11-28T14:10:55.000Z","updated_at":"2017-11-28T16:31:21.000Z","dependencies_parsed_at":"2023-04-12T04:01:54.243Z","dependency_job_id":null,"html_url":"https://github.com/lamansky/m-o","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"824b9055d643ebb6d7ec26c172a669bee8c3aa14"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/lamansky/m-o","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fm-o","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fm-o/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fm-o/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fm-o/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamansky","download_url":"https://codeload.github.com/lamansky/m-o/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamansky%2Fm-o/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269740554,"owners_count":24467802,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"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-30T06:12:40.428Z","updated_at":"2025-12-30T21:47:24.054Z","avatar_url":"https://github.com/lamansky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# m-o\n\nA collection of functions that work on both Maps and Objects, letting you write code that can handle either, if that’s your M.O.\n\nThe functions are: `has`, `hasIn`, `get`, `getIn`, `set`, `edit`, `delete`, `construct`, `reconstruct`, `entries`, `entriesArray`, `keys`, `keysArray`, `values`, and `valuesArray`.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 7.0.0 or above.\n\n```bash\nnpm install m-o --save\n```\n\nThe module exports an object with multiple methods.\n\n## Usage\n\nNota Bene: Maps can accept keys of any type, but Objects cannot. If you expect your code to work with both, then you should only use strings/numbers/symbols as keys.\n\n```javascript\nconst mo = require('m-o')\n\nconst map = new Map()\nconst obj = {}\n\n// Set\nmo.set(map, 'hello', 'world')\nmo.set(obj, 'hello', 'world')\n\n// Has\nmo.has(map, 'hello') // true\nmo.has(obj, 'hello') // true\n\n// Get\nmo.get(map, 'hello') // 'world'\nmo.get(obj, 'hello') // 'world'\n\n// vs. the normal way:\nmap.get('hello') // 'world'\nobj.hello // 'world'\n\n// Edit\nmo.edit(map, 'hello', value =\u003e value + '!')\nmo.edit(obj, 'hello', value =\u003e value + '!')\nmo.get(map, 'hello') // 'world!'\nmo.get(obj, 'hello') // 'world!'\n\n// Delete\nmo.delete(map, 'hello') // true\nmo.delete(obj, 'hello') // true\nmo.delete(map, 'nonexistent') // false\nmo.delete(obj, 'nonexistent') // false\n\n// Entries\nmo.entries(map) // MapIterator\nmo.entries(obj) // ArrayIterator\n\n// Construct a Map or an Object, depending on the class provided\nconst entries = [['hello', 'world']]\nmo.construct(Object, entries) // {hello: 'world'}\nmo.construct(Map, entries) // Map\nclass XMap extends Map {}\nmo.construct(XMap, entries) // XMap\n\n// Construct a new Map or Object having the same class as an existing object\nmo.reconstruct(obj, entries) // {hello: 'world'}\nmo.reconstruct(map, entries) // Map\nmo.reconstruct(new XMap(), entries) // XMap\n```\n\n### Entries, Keys, and Values\n\nThe `Map` prototype has `entries()`, `keys()`, and `values()` methods which return iterators, whereas the global functions `Object.entries()`, `Object.keys()`, and `Object.values()` return arrays. The `m-o` module lets you remain consistent regardless of which type you’re dealing with. Use the `entries()`, `keys()`, and `values()` methods if you want iterators, and use `entriesArray()`, `keysArray()`, and `valuesArray()` if you want arrays.\n\n### Accessing Prototype Properties\n\nBy default, `has` and `get` treat an object like a dictionary and therefore only access its own properties. If you want to access object prototype properties as well, use the `hasIn` or `getIn` methods instead. (With Maps, behavior is the same regardless of which set of methods you use.)\n\n```javascript\ntypeof obj.toString // 'function'\ntypeof mo.get(obj, 'toString') // 'undefined'\ntypeof mo.getIn(obj, 'toString') // 'function'\n\nmo.has(obj, 'toString') // false\nmo.hasIn(obj, 'toString') // true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fm-o","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamansky%2Fm-o","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamansky%2Fm-o/lists"}