{"name":"sort-object-keys2","version":"3.0.8","description":"對物件的鍵進行排序，支援自訂排序函式、指定鍵順序和原地修改選項 / Sort object keys with custom sort functions, specified key order, and in-place modification options","keywords":["arr","array","deep","deterministic","function","js","key","keys","obj","object","order","re","re-order","recursive","recursively","sort","source","stable","util","utils","create-by-yarn-tool","create-by-tsdx"],"homepage":"https://github.com/bluelovers/ws-array/tree/master/packages/sort-object-keys#readme","bugs":{"url":"https://github.com/bluelovers/ws-array/issues"},"repository":{"type":"git","url":"git+https://github.com/bluelovers/ws-array.git","directory":"packages/sort-object-keys"},"license":"MIT","author":{"name":"Keith Cirkel","email":"npm@keithcirkel.co.uk","url":"http://keithcirkel.co.uk/"},"sideEffects":false,"exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.esm.mjs"},"./core":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.esm.mjs"},"./package.json":"./package.json","./src/*":"./src/*"},"main":"dist/index.cjs","unpkg":"dist/index.umd.production.min.cjs","module":"dist/index.esm.mjs","types":"dist/index.d.ts","typings":"dist/index.d.ts","directories":{"test":"test"},"scripts":{"coverage":"yarn run test -- --coverage","pretest":"echo pretest","test":"jest --passWithNoTests","test:jest":"jest --passWithNoTests","test:jest:coverage":"yarn run test:jest -- --coverage","test:jest:snapshot":"yarn run test:jest -- -u","test:snapshot":"yarn run test -- -u","test:tsd":"ynpx tsd","posttest":"yarn run build","build":"yarn run build:tsdx && yarn run build:dts:bundle","build:dts:bundle":"ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle","build:dts:copy":"copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts","build:dts:tsc":"yarn run build:dts:tsc:emit && yarn run build:dts:copy","build:dts:tsc:emit":"tsc --emitDeclarationOnly --declaration --noEmit false","build:tsdx":"ynpx @bluelovers/tsdx build --target node","ci:install":"echo ci:install","ci:build":"echo ci:build","npm:publish":"npm publish","preversion":"echo preversion && yarn run test","version":"echo version","postversion":"echo postversion","prepublish":"echo prepublish","prepublish:lockfile":"npx sync-lockfile .","prepare":"echo prepare","prepublishOnly":"yarn run ncu && yarn run sort-package-json && npx yarn-tool install && yarn run test","prepublishOnly:update":"yarn run ncu && yarn run sort-package-json","prepack":"echo prepack","pack":"echo pack","postpack":"echo postpack","publish":"echo publish","postpublish":"git commit -m \"chore(release): publish\" .","postpublishOnly":"echo postpublishOnly","ncu":"npx yarn-tool ncu -u","sort-package-json":"npx yarn-tool sort","tsc:showConfig":"ynpx get-current-tsconfig -p"},"dependencies":{"@lazy-array/util-unique":"^1.0.7"},"gitHead":"68e965aa157f693b353a85bab4a3b2c1eb33e65f","_id":"sort-object-keys2@3.0.8","_nodeVersion":"24.14.0","_npmVersion":"lerna/9.0.7/node@v24.14.0+x64 (win32)","dist":{"integrity":"sha512-48gnNhe7RvUc6PNFI3IHfAxoqWzSCqmOat2VlTYnvf6QZU7hmiOa4FTnDt9wmq9NiWtLSla+0P2r0LHC8N213A==","shasum":"b1ffbb82cd5376debb9a00502322126f35baaac7","tarball":"http://registry-npm.ywwl.com/sort-object-keys2/download/sort-object-keys2-3.0.8.tgz","fileCount":17,"unpackedSize":59096,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGOzJiPHICAWE9Z2F/AE4bfp/w/FS2jY0uvkhYAB1NbEAiEAstV2X/j3OkWDARKPl60MZoD0oQN1ahTH7s5aXOxCs/s="}],"size":10018,"noattachment":false,"key":"/sort-object-keys2/-/sort-object-keys2-3.0.8.tgz"},"_npmUser":{"name":"bluelovers","email":"codelovers@users.sourceforge.net"},"maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sort-object-keys2_3.0.8_1773569759506_0.46972593491924597"},"_hasShrinkwrap":false,"readme":"# sort-object-keys2\n\n對物件的鍵進行排序，支援自訂排序函式、指定鍵順序和原地修改選項。\n\nSort object keys with custom sort functions, specified key order, and in-place modification options.\n\n## 功能說明 / Features\n\n- **基本排序**: 依字母順序排序物件鍵\n- **自訂排序**: 使用自訂排序函式\n- **指定鍵順序**: 指定特定鍵的排列順序\n- **原地修改**: 可選擇直接修改原物件\n- **Basic sorting**: Sort keys alphabetically\n- **Custom sorting**: Use custom sort functions\n- **Specified key order**: Specify particular key order\n- **In-place modification**: Option to modify source object directly\n\n## 安裝 / Install\n\n```bash\nyarn add sort-object-keys2\nyarn-tool add sort-object-keys2\nyt add sort-object-keys2\n```\n\n## 使用範例 / Usage Examples\n\n### 基本排序 / Basic Sorting\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\n// 依鍵名字母順序排序\nconst obj = { c: 1, b: 2, a: 3 };\nconst sorted = sortObjectKeys(obj);\n\nconsole.log(sorted); // => { a: 3, b: 2, c: 1 }\n```\n\n### 指定鍵順序 / Specify Key Order\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\n// 指定鍵的優先順序\nconst obj = { c: 1, b: 2, a: 3 };\nconst sorted = sortObjectKeys(obj, ['b', 'a', 'c']);\n\nconsole.log(sorted); // => { b: 2, a: 3, c: 1 }\n```\n\n### 自訂排序函式 / Custom Sort Function\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\n// 自然排序數字鍵\nconst obj = { key2: 1, key10: 1, key1: 1 };\nconst sorted = sortObjectKeys(obj, (a, b) => {\n  return a.localeCompare(b, undefined, { numeric: true });\n});\n\nconsole.log(sorted); // => { key1: 1, key2: 1, key10: 1 }\n```\n\n### 降序排列 / Descending Order\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\nconst obj = { a: 1, b: 2, c: 3 };\nconst sorted = sortObjectKeys(obj, { desc: true });\n\nconsole.log(sorted); // => { c: 3, b: 2, a: 1 }\n```\n\n### 只返回指定鍵 / Return Only Specified Keys\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\nconst obj = { a: 1, b: 2, c: 3 };\nconst sorted = sortObjectKeys(obj, { keys: ['b', 'c'], onlyKeys: true });\n\nconsole.log(sorted); // => { b: 2, c: 3 }\n```\n\n### 原地修改 / In-place Modification\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\nconst obj = { c: 1, b: 2, a: 3 };\nsortObjectKeys(obj, { useSource: true });\n\nconsole.log(obj); // => { a: 3, b: 2, c: 1 }\n```\n\n### 允許不存在的鍵 / Allow Non-existent Keys\n\n```typescript\nimport { sortObjectKeys } from 'sort-object-keys2';\n\nconst obj = { a: 1, b: 2 };\nconst sorted = sortObjectKeys(obj, { keys: ['b', 'c', 'a'], allowNotExists: true });\n\nconsole.log(sorted); // => { b: 2, c: undefined, a: 1 }\n```\n\n## 應用情境 / Application Scenarios\n\n1. **測試穩定性**: 確保物件結構穩定以便比對\n2. **API 響應**: 產生一致且可預測的 JSON 響應\n3. **表單欄位**: 自訂表單欄位的顯示順序\n4. **配置管理**: 排序配置物件以便閱讀\n\n## API 參考 / API Reference\n\n```typescript\ndeclare function sortObject<T>(object: T, options?: sortObject.IOptions & {\n    useSource: true;\n}): T;\ndeclare function sortObject<T>(object: T, options?: sortObject.IOptions & {\n    keys: string[];\n    onlyKeys: true;\n}): Partial<T>;\ndeclare function sortObject<T>(object: T, options?: sortObject.IOptions): Partial<T>;\ndeclare function sortObject<T>(object: T, sortFn: (a, b) => any): Partial<T>;\ndeclare function sortObject<T>(object: T, sortWith: string[]): Partial<T>;\n```\n\n[查看完整 API](index.d.ts)\n","publish_time":1773569759657,"_cnpm_publish_time":1773569759657,"dist-tags":{"latest":"3.0.10"}}