{"id":16372026,"url":"https://github.com/qard/breadth-filter","last_synced_at":"2025-03-16T15:33:27.181Z","repository":{"id":57190386,"uuid":"160370008","full_name":"Qard/breadth-filter","owner":"Qard","description":"Breadth-first deep object filter","archived":false,"fork":false,"pushed_at":"2023-10-24T06:54:51.000Z","size":44,"stargazers_count":5,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-13T22:20:29.494Z","etag":null,"topics":["breadth","filter","nodejs","object","traversal"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/Qard.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":"2018-12-04T14:27:32.000Z","updated_at":"2024-06-18T18:36:59.306Z","dependencies_parsed_at":"2024-06-18T18:36:56.264Z","dependency_job_id":"02692737-b3be-4d3e-b483-4bbec61644b0","html_url":"https://github.com/Qard/breadth-filter","commit_stats":{"total_commits":14,"total_committers":4,"mean_commits":3.5,"dds":0.3571428571428571,"last_synced_commit":"0137ea6376fee85b0794dfc5e3a02d0987d79277"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fbreadth-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fbreadth-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fbreadth-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fbreadth-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qard","download_url":"https://codeload.github.com/Qard/breadth-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221665602,"owners_count":16860290,"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":["breadth","filter","nodejs","object","traversal"],"created_at":"2024-10-11T03:10:20.438Z","updated_at":"2024-10-27T10:51:56.243Z","avatar_url":"https://github.com/Qard.png","language":"JavaScript","readme":"# breadth-filter\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/Qard/breadth-filter.svg)](https://greenkeeper.io/)\n\nApply a deep object filter via breadth traversal. It allows replacing values, including retargeting objects and arrays and even detecting circular references to allow the user to decide how to handle the circle. Note that the filter will _not_ descend _into_ circular objects but will only _reach_ them.\n\n## Install\n\n```sh\nnpm install breadth-filter\n```\n\n## Example\n\n```js\nconst breadthFilter = require('breadth-filter')\n\nconst data = {\n  user: {\n    name: 'someone',\n    password: 'THIS SHOULD BE SECRET!!'\n  }\n}\n\nfunction onValue (value, key, path) {\n  if (key === 'password') {\n    console.log('redacted field at', path.join('.'))\n    return '[redacted]'\n  }\n  return value\n}\n\n// build a new filtered object...\n\nconst filtered = breadthFilter(data, {\n  onValue\n})\n\n// or, mutate in-place and break cycles...\n\nbreadthFilter(data, {\n  onValue,\n  onObject (value, key, path, isNew) {\n    return isNew ? value : '[Circular]'\n  },\n  onArray (value, key, path, isNew) {\n    return isNew ? value : '[Circular]'\n  }\n})\n```\n\n## Options\n\n### onValue(value, key, path)\n\nThis function handles primitive value types such as numbers or strings. It can be used to filter things like sensitive data such as passwords or credit card numbers.\n\nArguments:\n\n* `value` - any\nThe encountered value to filter.\n* `key` - string | number\nThe property key of the encountered value, at the current depth level. Will be `null` when encountering the root object.\n* `path` - array\u003cstring\u003e\nAny array of all property keys leading from the root to this encountered value.\n\n### onObject(value, key, path, isNew)\n\nThis handles encountered objects. It can be used to filter entire objects out of the result, by returning `undefined`, it can enable in-place mutation by return the value directly, and the `isNew` property can be used to identify and break out of circular references, replacing them with something else such as `'[Circular]'`.\n\nArguments:\n\n* `value` - any\nThe encountered value to filter.\n* `key` - string | number\nThe property key of the encountered value, at the current depth level. Will be `null` when encountering the root object.\n* `path` - array\u003cstring\u003e\nAny array of all property keys leading from the root to this encountered value.\n* `isNew` - boolean\nIndicates if this is the first time encountering this value, a false value indicates a circular reference.\n\n### onArray(value, key, path, isNew)\n\nThis handles encountered arrays. It can be used to filter entire arrays out of the result, by returning `undefined`, it can enable in-place mutation by return the value directly, and the `isNew` property can be used to identify and break out of circular references, replacing them with something else such as `'[Circular]'`.\n\nArguments:\n\n* `value` - any\nThe encountered value to filter.\n* `key` - string | number\nThe property key of the encountered value, at the current depth level. Will be `null` when encountering the root object.\n* `path` - array\u003cstring\u003e\nAny array of all property keys leading from the root to this encountered value.\n* `isNew` - boolean\nIndicates if this is the first time encountering this value, a false value indicates a circular reference.\n\n---\n\n### Copyright (c) 2019 Stephen Belanger\n#### Licensed under MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqard%2Fbreadth-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqard%2Fbreadth-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqard%2Fbreadth-filter/lists"}