{"id":18379004,"url":"https://github.com/tnfe/jscalpel","last_synced_at":"2026-03-03T23:31:40.750Z","repository":{"id":41819320,"uuid":"102451809","full_name":"tnfe/jscalpel","owner":"tnfe","description":"A small feature library that makes it easier to manipulate objects","archived":false,"fork":false,"pushed_at":"2023-01-05T06:42:16.000Z","size":1453,"stargazers_count":27,"open_issues_count":13,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-26T23:39:20.079Z","etag":null,"topics":["es6","javascript","jscalpel","object","objects","parser","path","react","vue"],"latest_commit_sha":null,"homepage":"https://tnfe.github.io/jscalpel/","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/tnfe.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":"2017-09-05T07:57:36.000Z","updated_at":"2022-12-09T13:54:25.000Z","dependencies_parsed_at":"2023-02-03T16:15:25.799Z","dependency_job_id":null,"html_url":"https://github.com/tnfe/jscalpel","commit_stats":null,"previous_names":["ihtml5/scalpel"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tnfe/jscalpel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Fjscalpel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Fjscalpel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Fjscalpel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Fjscalpel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tnfe","download_url":"https://codeload.github.com/tnfe/jscalpel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tnfe%2Fjscalpel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30065783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["es6","javascript","jscalpel","object","objects","parser","path","react","vue"],"created_at":"2024-11-06T00:36:40.330Z","updated_at":"2026-03-03T23:31:40.722Z","avatar_url":"https://github.com/tnfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n![](./logo/logox3.png)\n\nA small feature library that makes it easier to manipulate objects\n\n[![npm package](https://img.shields.io/npm/v/jscalpel.svg)](https://www.npmjs.org/package/jscalpel)\n[![NPM downloads](http://img.shields.io/npm/dm/jscalpel.svg)](https://npmjs.org/package/jscalpel)\n## Overview\n\nIt is tiny but very useful and can help you handle javascript native objects. Data-driven interface development is very common today, we are in the [angular](https://github.com/angular/angular), [react](http://www.github.com/facebook/react), [vue](http://www.github.com/vuejs/vue) will encounter a lot of object processing, including set the default value, query, assignment, etc., [jscalpel](http://www.github.com/tnfe/jscalpel) is born for this scene.\n\njscalpel is little poor, gzip less than **3k**, so a library you can use it anytime, anywhere without worrying about anything.\n\n## Document\n\n#### View the document please visit [https://tnfe.github.io/jscalpel/](https://tnfe.github.io/jscalpel/)\n[中文文档](https://tnfe.github.io/jscalpel/index_zh.html)\n\n## Installation\n\n#### Install using npm \n[![jscalpel](https://nodei.co/npm/jscalpel.png)](https://npmjs.org/package/jscalpel)\n``` \nnpm install jscalpel --save\nyarn add jscalpel --save\n```\n\n## Useage\n\n#### Es6\n```javascript\n  import Jscalpel from 'jscalpel'\n```\n#### Include in html\n```javascript\n  \u003cscript charset=\"utf-8\" src=\"https://unpkg.com/jscalpel@latest/dist/index.js\"\u003e\u003c/script\u003e\n```\n## APIS\n\u003ctable class=\"scalpel-table\"\u003e\n                \u003cthead\u003e\n                    \u003ctr\u003e\n                        \u003cth\u003eparameter\u003c/th\u003e\n                        \u003cth\u003etype\u003c/th\u003e\n                        \u003cth\u003edefault value\u003c/th\u003e\n                        \u003cth\u003euse\u003c/th\u003e\n                        \u003cth\u003eisRequired\u003c/th\u003e\n                        \u003cth\u003erequired version\u003c/th\u003e\n                    \u003c/tr\u003e\n                \u003c/thead\u003e\n                \u003ctbody\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003etarget\u003c/td\u003e\n                        \u003ctd\u003estring/object\u003c/td\u003e\n                        \u003ctd\u003e{}\u003c/td\u003e\n                        \u003ctd\u003etarget\u003c/td\u003e\n                        \u003ctd\u003etrue\u003c/td\u003e\n                        \u003ctd\u003eall\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003edeep\u003c/td\u003e\n                        \u003ctd\u003eboolean\u003c/td\u003e\n                        \u003ctd\u003efalse\u003c/td\u003e\n                        \u003ctd\u003ewhether or not to copy the target object in depth\u003c/td\u003e\n                        \u003ctd\u003efalse\u003c/td\u003e\n                        \u003ctd\u003eall\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003eprefix\u003c/td\u003e\n                        \u003ctd\u003estring\u003c/td\u003e\n                        \u003ctd\u003eundefined\u003c/td\u003e\n                        \u003ctd\u003epublic prefix, automatically added for the keys\u003c/td\u003e\n                        \u003ctd\u003efalse\u003c/td\u003e\n                        \u003ctd\u003eall\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003esuccess\u003c/td\u003e\n                        \u003ctd\u003efunction\u003c/td\u003e\n                        \u003ctd\u003efunction () {}\u003c/td\u003e\n                        \u003ctd\u003eThe function that was called when the analysis was successful\u003c/td\u003e\n                        \u003ctd\u003etrue\u003c/td\u003e\n                        \u003ctd\u003e^0.6.2\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003eerror\u003c/td\u003e\n                        \u003ctd\u003efunction\u003c/td\u003e\n                        \u003ctd\u003efunction () {}\u003c/td\u003e\n                        \u003ctd\u003eThe function that is called when the analysis fails.\u003c/td\u003e\n                        \u003ctd\u003efalse\u003c/td\u003e\n                        \u003ctd\u003e^0.6.2\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003epath\u003c/td\u003e\n                        \u003ctd\u003estring/array/function\u003c/td\u003e\n                        \u003ctd\u003e[]\u003c/td\u003e\n                        \u003ctd\u003epath\u003c/td\u003e\n                        \u003ctd\u003efalse\u003c/td\u003e\n                        \u003ctd\u003e^0.6.2\u003c/td\u003e\n                    \u003c/tr\u003e\n                    \u003ctr\u003e\n                        \u003ctd\u003eplugins\u003c/td\u003e\n                        \u003ctd\u003earray\u003c/td\u003e\n                        \u003ctd\u003e[]\u003c/td\u003e\n                        \u003ctd\u003eA plug-in set, similar to the webpack plugins.\u003c/td\u003e\n                        \u003ctd\u003efalse\u003c/td\u003e\n                        \u003ctd\u003e^0.6.2\u003c/td\u003e\n                    \u003c/tr\u003e\n                \u003c/tbody\u003e\n            \u003c/table\u003e\n            \n## [Online Demos](https://jsfiddle.net/as3tLkdy/27/?utm_source=website\u0026utm_medium=embed\u0026utm_campaign=as3tLkdy)\n\n## Code\n#### 1. simple pattern\n```javascript\n// mock data\nvar data = {\n  status: '0',\n  data: {\n    response: {\n      code: 1,\n      msg: 'response msg'\n    }\n  }\n}\n// super easy\njscalpel.get(data, 'data.response.code'); // return 1\n// deep copy object\njscalpel.toCopy(data) !== data; // return true;\njscalpel.set(data, 'data.response.code', 0);\njscalpel.get(data, 'data.response.code') // return 0;\n// bind data\nvar jscalpelIns = jscalpel({\n  target: data\n})\njscalpelIns.get('data.response.code') // returned 1;\njscalpelIns.set('data.response.code', 12);\njscalpelIns.set({\n  'status': '1'\n})\njscalpelIns.get('data.response.code') // returned 12\njscalpelIns.get('status') // returned 1\njscalpelIns.has('data.response.code') // returned true\njscalpelIns.del('data.reponse.code') \njscalpelIns.get('data.reponse.code') // returned undefined;\njscalpelIns.has('data.reponse.code') // returned false;\n```\n#### 2.advanced patterns\n```\nconst res = {\n  data: {\n    article: [{\n      articleId: 0,\n        title: 'jscalpel'\n    }]\n  },\n  response: {\n    code: '0',\n    msg: 'success'\n  }\n}\njscalpel({\n\ttarget: res,\n  path: ['data.article.0', 'response.msg'],\n  success:  (article, msg) =\u003e {\n  \tconsole.log('keys=\u003earray=\u003eoutput:', article, msg);\n  }\n})\n\njscalpel({\n\ttarget: res,\n  path: 'response.msg',\n  success:  (msg) =\u003e {\n  \tconsole.log('keys=\u003estring=\u003eoutput:',msg);\n  }\n});\n```\n#### 3.use prefix\n```\njscalpel({\n\ttarget: res,\n  prefix: 'response',\n  path: ['code', 'msg'],\n  success:  (code, msg) =\u003e {\n  \tconsole.log('prefix=\u003eoutput:', code, msg);\n  }\n})\n```\n#### 4.dynamic path\n\n```\njscalpel({\n  target: res,\n  path: () =\u003e ['code', 'msg'].map((key) =\u003e `response.${key}`),\n  success:  (code, msg) =\u003e {\n  \tconsole.log('dynamic=\u003eoutput:', code, msg);\n  }\n})\n\njscalpel({\n\ttarget: res,\n  deep: true,\n  prefix: 'response',\n  path: ['code', 'msg'],\n  success:  (code, msg, finalRes, keys) =\u003e {\n    console.log( finalRes === res);\n  \tconsole.log('deep into callback:', code, msg, finalRes, keys);\n  }\n});\n```\n\n#### 5.use plugins\n```\nconst logicMap = {\n  'code': {\n    match: ({value, name}) =\u003e value === '0',\n    success: ({value, name}) =\u003e {\n      console.log('logicPlugin', value, name);\n    }\n  }\n}\njscalpel({\n  target: res,\n  deep: true,\n  prefix: 'response',\n  path: ['code', 'msg'],\n  plugins: [jscalpel.jscalpelType, jscalpel.jscalpelLogic(logicMap)],\n  success: (code, msg, finalRes, keys) =\u003e {\n    console.log( finalRes === res);\n  \tconsole.log('deep into callback:', code, msg, finalRes, keys);\n  }\n})\n```\n## Related projects\n[jscalpel-orm](https://github.com/tnfe/jscalpel-orm)\n\nIt is convenient for you to extract the required fields from one object to generate another object.\n\n## Changelog\n\n#### 2017.9.14\n\nAdd jscalpelLogic plugin, reduce ifelse, make run logic configurable\n\n#### 2018.3.08\n\nadd orm \n#### 2018.9.04\n\nadd get method\n```javascript\nimport { get } from 'jscalpel';\n// get(data, path ,defaultValue);\n```\n#### 2018.12.30\n```javascript\nimport { set, get, toCopy } from 'jscalpel';\n// deep copy object\ntoCopy(data) !== data; // return true;\n// set path value\nset(data, 'data.response.code', 0);\nget(data, 'data.response.code') // return 0;\n```\n\n#### 2021.8.31\n\npublish 2.0.0\n## License\n\n[The MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnfe%2Fjscalpel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftnfe%2Fjscalpel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftnfe%2Fjscalpel/lists"}