{"id":19998097,"url":"https://github.com/wenlng/ofilter-js","last_synced_at":"2025-05-04T14:30:52.631Z","repository":{"id":63076077,"uuid":"564729596","full_name":"wenlng/ofilter-js","owner":"wenlng","description":"🖖 OfilterJs is a data object filter processor for Javascript, which provides simpler, more convenient and more efficient data operations for development.","archived":false,"fork":false,"pushed_at":"2022-12-21T05:31:30.000Z","size":171,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-11T00:47:43.274Z","etag":null,"topics":["es6","filter","javascript","json","json-filter","object","object-filter","ofilter","typescript"],"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/wenlng.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}},"created_at":"2022-11-11T11:09:27.000Z","updated_at":"2024-08-11T00:47:43.274Z","dependencies_parsed_at":"2023-01-30T02:46:27.594Z","dependency_job_id":null,"html_url":"https://github.com/wenlng/ofilter-js","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenlng%2Fofilter-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenlng%2Fofilter-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenlng%2Fofilter-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wenlng%2Fofilter-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wenlng","download_url":"https://codeload.github.com/wenlng/ofilter-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224393949,"owners_count":17303725,"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":["es6","filter","javascript","json","json-filter","object","object-filter","ofilter","typescript"],"created_at":"2024-11-13T05:07:21.649Z","updated_at":"2024-11-13T05:07:37.399Z","avatar_url":"https://github.com/wenlng.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"120\" style=\"padding-top: 50px\" src=\"http://47.104.180.148/ofilterjs/ofilterjs_logo.svg\"/\u003e\n\u003ch1 style=\"margin: 0; padding: 0\"\u003eOfilterJS\u003c/h1\u003e\n\u003cp\u003eData Filter Processor Of Javascript Object\u003c/p\u003e\n \u003ca href=\"https://www.npmjs.com/package/ofilterjs\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/ofilterjs.svg\" alt=\"Downloads\"\u003e\u003c/a\u003e\n \u003ca href=\"https://npmcharts.com/compare/ofilterjs?minimal=true\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/ofilterjs.svg?sanitize=true\" alt=\"Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/wenlng/ofilter-js/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/wenlng/ofilter-js.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/wenlng/ofilter-js\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/wenlng/ofilter-js.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/wenlng/ofilter-js\"\u003e\u003cimg src=\"https://img.shields.io/github/last-commit/wenlng/ofilter-js.svg\"/\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\n\u003e English | [中文](README_zh.md)\n\u003cp\u003e🖖 \u003ca href=\"https://github.com/wenlng/ofilter-js\"\u003eOfilterJs\u003c/a\u003e is a data object filter processor for Javascript, which provides simpler, more convenient and more efficient data operations for development. \u003c/p\u003e\n\n\u003cp\u003e ⭐️ If it helps you, please give a star.\u003c/p\u003e\n\u003cbr/\u003e\n\n- [https://github.com/wenlng/ofilter-js](https://github.com/wenlng/ofilter-js)\n\n\n### Supported languages\n- Javascript\n- TypeScript\n\n### Methods\n- 🍑 `filterValue`\n- 🍐 `getValue`\n- 🍎 `resetValue`\n\n\n### Install Module\n``` shell\n$ npm i ofilterjs\n```\nOr `pnpm`, Or `cnpm`, Or `yarn` ...\n``` shells\n$ pnpm i ofilterjs\n```\n\n### Import Module\n``` ts\n  const ofjs = require('ofilterjs')\n \n // import ofjs from 'ofilterjs'\n```\n\n\u003cbr/\u003e\n\n### Browser\n```html\n\u003cscript src=\"https://unpkg.com/ofilterjs@1.0.7/dist/ofilterjs.global.min.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n    console.log(ofilterjs)\n\u003c/script\u003e\n```\n\u003cbr/\u003e\n\n### 1. Data Filter\n\u003e filterValue([Object{}], [Config], ...[extraData])\n\n#### 1.1 Filter or Recombine for data\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version_number: 10001\n        }\n    }\n}\n\nconst newData = ofjs.filterValue(data, {\n    name: 'lib.pkg.name',\n    versionNumber: 'lib.pkg.version_number',\n})\nconsole.log(newData)\n\n/** result\n   newData = {\n        name: 'ofilterjs',\n        versionNumber: 10001\n   } \n*/\n```\n\u003cbr/\u003e\n\n#### 1.2 Set value\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version_number: 10001\n        }\n    }\n}\n\nconst newData = ofjs.filterValue(data, {\n    name: 'lib.pkg.name',\n    type: {\n        value: 'type value'\n    }\n})\nconsole.log(newData)\n\n/** result\n   newData = {\n        name: 'ofilterjs',\n        type: 'type value'\n   } \n*/\n```\n\u003cbr/\u003e\n\n#### 1.3 Set default value\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version_number: 10001\n        }\n    }\n}\n\nconst newData = ofjs.filterValue(data, {\n    name: 'lib.pkg.name',\n    alias: {\n        key: 'lib.pkg.alias',\n        default: 'Default alias'\n    },\n    type: {\n        key: 'lib.pkg.type',\n        default: 'Npm pkg'\n    }\n})\nconsole.log(newData)\n\n/** result\n   newData = {\n        name: 'ofilterjs',\n        alias: 'Default alias',\n        type: 'Npm pkg'\n   } \n*/\n```\n\u003cbr/\u003e\n\n#### 1.4 Custom filter callback\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version_number: 10001\n        }\n    }\n}\n\nconst newData = ofjs.filterValue(data, {\n    name: 'lib.pkg.name',\n    alias: {\n        key: 'lib.pkg.alias',\n        filter: (value, source) =\u003e {\n            if (value !== '') return value\n            return 'This is ' + (source?.lib?.pkg?.name || 'unknown')\n        }\n    },\n    type: {\n        key: 'lib.pkg.type',\n        filter: (value, source) =\u003e {\n            return 'Filter npm'\n        }\n    }\n})\nconsole.log(newData)\n\n/** result\n   newData = {\n        name: 'ofilterjs',\n        alias: 'This is ofilterjs',\n        type: 'Filter npm'\n   } \n*/\n```\n\u003cbr/\u003e\n\n#### 1.5 Merge data of filter return to result\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version_number: 10001\n        }\n    }\n}\n\nconst newData = ofjs.filterValue(data, {\n    name: 'lib.pkg.name',\n    _: {\n        merge: true,\n        filter: (_, source) =\u003e {\n            if (source?.lib?.pkg?.name === 'ofilterjs') {\n                return {\n                   support: ['js', 'ts', 'es']\n                }\n            }\n            return {}\n        }\n    },\n    _1: {\n        merge: true,\n        filter: (_, source) =\u003e {\n            return { more: 'more data ...' }\n        }\n    },\n  }\n})\nconsole.log(newData)\n\n/** result\n   newData = {\n        name: 'ofilterjs',\n        support: ['js', 'ts', 'es'],\n        more: 'more data ...'\n   } \n*/\n```\n\u003cbr/\u003e\n\n#### 1.6 Merge extra data to result\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version_number: 10001\n        }\n    }\n}\n\nconst newData = ofjs.filterValue(data, {\n    name: 'lib.pkg.name'\n  }\n}, {\n    name1: 'ofilter'\n}, {\n    name2: 'object filter'\n})\nconsole.log(newData)\n\n/** result\n   newData = {\n        name: 'ofilterjs',\n        name1: 'ofilter',\n        name2: 'object filter'\n   } \n*/\n```\n\u003cbr/\u003e\n\n### 2. Read Data\n\u003e getValue([nameStr], [defaultValue])\n\n#### 2.1 Read Value / Deep Read for value\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n\nconst name = ofjs.getValue(data, 'lib.pkg.name', 'unknown')\nconsole.log(name)   // ofilterjs\n```\n\u003cbr/\u003e\n\n#### 2.2 Priority reading value\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n\nconst alias = ofjs.getValue(data, 'lib.pkg.alias|lib.pkg.name', 'unknown')\nconsole.log(name)   // ofilterjs\n```\n\n\u003cbr/\u003e\n\n#### 2.3 Array index read\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n\nconst su = ofjs.getValue(data, 'lib.support.0', 'unknown')\nconsole.log(su)   // js\n```\n\u003cbr/\u003e\n\n### 3. Reset Data\n\u003e resetValue([Object{}], [Config,?Optional])\n\nTip: Prefixes with '_' attribute names will not be reset automatically.\n\n#### 3.1 Auto set at data type\n\nShallow Reset\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es'],\n        _private: 'private attr'  \n    },\n    lib2: {\n        pkg: {\n            name: 'ofilter'\n        }\n    }\n}\n\nofjs.resetValue(data, false)\n\n/**  result\nconst data = {\n    lib: {},\n    lib2: {}\n}\n*/\n```\n\nDepth Reset\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es'],\n        _private: 'private attr'  \n    },\n    lib2: {\n        pkg: {\n            name: 'ofilter'\n        }\n    }\n}\n\nofjs.resetValue(data, true)\n\n/**  result\nconst data = {\n    lib: {\n        pkg: {\n            name: '',\n            alias: '',\n            version: 0\n        },\n        support: [],\n        _private: 'private attr'\n    },\n    lib2: {\n        pkg: {\n            name: ''\n        }\n    }\n}\n*/\n```\n\nDepth Reset， Set depth layer parameter\n``` ts\nconst data = {\n    // level 0\n    name: 'lib_list',\n    lib: {\n        // level 1\n        type: 'npm',\n        pkg: {\n            // level 2\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: {\n            'js' : 'javascript',\n            'ts' : 'typescript'\n        },\n        _private: 'private attr' \n    },\n    lib2 : {\n        type: 'npm',\n        pkg: {\n            name: 'ofilter'\n        }\n    }\n}\n\n// 0 ~ (0+2)\nofjs.resetValue(data, true, 2)\n\n/**  result\nconst data = {\n    // level 0\n    name: '',   // Was reset\n    lib: {\n        // level 1\n        type: '',   // Was reset\n        pkg: {\n            // level 2\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: {\n            'js' : 'javascript',\n            'ts' : 'typescript'\n        },\n        _private: 'private attr' \n    },\n    lib2 : {\n        type: '',   // Was reset\n        pkg: {\n            name: 'ofilter'\n        }\n    }\n}\n*/\n```\n\nDepth Reset， Set depth layer and start position parameter\n``` ts\nconst data = {\n    // level 0\n    name: 'lib_list',\n    lib: {\n        // level 1\n        type: 'npm',\n        pkg: {\n            // level 2\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001,\n            support: {\n                // level 3\n                'js' : 'javascript',\n                'ts' : 'typescript'\n            }\n        },\n        _private: 'private attr' \n    },\n    lib2 : {\n        type: 'npm',\n        pkg: {\n            name: 'ofilter'\n        }\n    }\n}\n\n// 1 ~ (1+2)\nofjs.resetValue(data, true, 2, 1)\n\n/**  result\nconst data = {\n    // level 0\n    name: 'lib_list',\n    lib: {\n        // level 1\n        type: '',   // Was reset\n        pkg: {\n            // level 2\n            name: '',   // Was reset\n            alias: '',  // Was reset\n            version: 0, // Was reset\n            support: {\n                // level 3\n                'js' : 'javascript',\n                'ts' : 'typescript'\n            }\n        },\n        _private: 'private attr' \n    },\n    lib2 : {\n        type: '',   // Was reset\n        pkg: {\n            name: ''    // Was reset\n        }\n    }\n}\n```\n\u003cbr/\u003e\n\n\n#### 3.2 Configuration reset field\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n\nofjs.resetValue(data, [\n    'lib.pkg.name',\n    'lib.pkg.version'\n])\n\n/**  result\nconst data = {\n    lib: {\n        pkg: {\n            name: '',\n            alias: '',\n            version: 0\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n*/\n```\n\u003cbr/\u003e\n\n#### 3.3 Configuration set data\n``` ts\nconst data = {\n    lib: {\n        pkg: {\n            name: 'ofilterjs',\n            alias: '',\n            version: 10001\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n\n// us ofilterjs\nofjs.resetValue(data, {\n    'lib.pkg.name': 'newname',\n    'lib.pkg.version': 10002\n})\n\n/** result\nconst data = {\n    lib: {\n        pkg: {\n            name: 'newname',\n            alias: '',\n            version: 10002\n        },\n        support: ['js', 'ts', 'es']\n    }\n}\n*/\n```\n\u003cbr/\u003e\n\n\u003e Buy the author coffee: [http://witkeycode.com/sponsor](http://witkeycode.com/sponsor)\n\u003cbr/\u003e\n\n## LICENSE\n    MIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenlng%2Fofilter-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwenlng%2Fofilter-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenlng%2Fofilter-js/lists"}