{"_id":"sort-object-keys2@3.0.10","bugs":{"url":"https://github.com/bluelovers/ws-array/issues"},"dist":{"shasum":"f2f1f3c07433191420402d9f5bdd66a7b00214e9","tarball":"http://registry-npm.ywwl.com/sort-object-keys2/download/sort-object-keys2-3.0.10.tgz","fileCount":17,"integrity":"sha512-mfu38UKPFskypYrs4dnmZnlfkvO2Ztv5Vg2DC0PTCcKfGgug/5outCc1HDLhANrIgntZOI+tqDLc5qc4WCVwbw==","signatures":[{"sig":"MEYCIQD95G77+kGtELp7W7wuJMG5JhsPOfNKYuyZznZfVar+9QIhANXfvqRl1BgZo2xmZliMg5n2/XVbX7DD6Y/9zD7+E8Is","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHypoI/u+QB4hjbfOM3/prgwoQQYdzYih5gkgnELAbGSAiAqtL252EyY91gbilkj0Ly0w0735T3o6/ft6RfPfUTsLQ=="}],"unpackedSize":62001,"size":10559,"noattachment":false,"key":"/sort-object-keys2/-/sort-object-keys2-3.0.10.tgz"},"main":"dist/index.cjs","name":"sort-object-keys2","types":"dist/index.d.ts","unpkg":"dist/index.umd.production.min.cjs","author":{"url":"http://keithcirkel.co.uk/","name":"Keith Cirkel","email":"npm@keithcirkel.co.uk"},"module":"dist/index.esm.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.mjs","require":"./dist/index.cjs"},"./core":{"types":"./dist/index.d.ts","import":"./dist/index.esm.mjs","require":"./dist/index.cjs"},"./src/*":"./src/*","./package.json":"./package.json"},"gitHead":"9d6f6c235933231c2b859e779d8b2fdde2ba6d47","license":"MIT","scripts":{"test":"node --run test:node","build":"pnpm run build:tsdx && pnpm run build:dts:bundle","version":"echo version","coverage":"pnpm run test --coverage","posttest":"pnpm run build","test:tsd":"ynpx tsd","test:jest":"jest --passWithNoTests","test:node":"tsx --test --test-update-snapshots **/*.node-spec.ts **/*.test.ts","build:tsdx":"ynpx @bluelovers/tsdx build --target node","preversion":"echo preversion && pnpm run test","build:dts:tsc":"pnpm run build:dts:tsc:emit && pnpm run build:dts:copy","test:snapshot":"pnpm run test -u","build:dts:copy":"copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts","tsc:showConfig":"ynpx get-current-tsconfig -p","build:dts:bundle":"ynpx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle","build:dts:tsc:emit":"tsc --emitDeclarationOnly --declaration --noEmit false","test:jest:coverage":"pnpm run test:jest --coverage","test:jest:snapshot":"pnpm run test:jest -u"},"typings":"dist/index.d.ts","version":"3.0.10","_npmUser":{"name":"bluelovers","email":"codelovers@users.sourceforge.net"},"homepage":"https://github.com/bluelovers/ws-array/tree/master/packages/sort-object-keys#readme","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"],"repository":{"url":"git+https://github.com/bluelovers/ws-array.git","type":"git","directory":"packages/sort-object-keys"},"_npmVersion":"lerna/7.4.2/node@v26.7.0+x64 (win32)","description":"對物件的鍵進行排序，支援自訂排序函式、指定鍵順序和原地修改選項 / Sort object keys with custom sort functions, specified key order, and in-place modification options","directories":{"test":"test"},"maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"sideEffects":false,"_nodeVersion":"26.7.0","dependencies":{"@lazy-array/util-unique":"^1.0.9"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sort-object-keys2_3.0.10_1791818241809_0.5701183261771445"},"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":1791818241894,"_cnpm_publish_time":1791818241894,"dist-tags":{"latest":"3.0.10"}}