{"name":"sort-object-keys2","version":"0.0.1","keywords":["arr","array","deep","deterministic","function","js","key","keys","obj","object","order","re","re-order","recursive","recursively","sort","source","stable","util","utils"],"author":{"url":"http://keithcirkel.co.uk/","name":"Keith Cirkel","email":"npm@keithcirkel.co.uk"},"license":"MIT","_id":"sort-object-keys2@0.0.1","maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"homepage":"https://github.com/bluelovers/sort-object-keys#readme","bugs":{"url":"https://github.com/bluelovers/sort-object-keys/issues"},"dist":{"shasum":"265f15454841830564be64f505670be0545bebac","tarball":"http://registry-npm.ywwl.com/sort-object-keys2/download/sort-object-keys2-0.0.1.tgz","integrity":"sha512-5YDfNMsG+VWP9Idd1KxrP38YStAkCse9kNkdvTqG8dBxNTVhNRQUES9TDIn5mMPOKPtTW32ObolXDIqCP/3xDg==","signatures":[{"sig":"MEUCICkSeL+NGPpnqz7E6at4hK2sAhpXXNRCOAEqVF7KSJdOAiEAnE++epNgNoUsXE7qEm9XW7cK+f2sU6qSSBKwHDqKJHM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":1435,"noattachment":false,"key":"/sort-object-keys2/-/sort-object-keys2-0.0.1.tgz"},"main":"index.js","files":["index.js"],"gitHead":"ba119e7c40fa94563ccf4864c4a7d14858bd1ebf","scripts":{"test":"npx mocha \"!(node_modules)\\**\\*.+(test|spec).ts\""},"_npmUser":{"name":"bluelovers","email":"codelovers@users.sourceforge.net"},"repository":{"url":"git+https://github.com/bluelovers/sort-object-keys.git","type":"git"},"_npmVersion":"5.6.0","description":"Sort an object's keys, including an optional key list","directories":{"test":"test"},"_nodeVersion":"9.4.0","devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/sort-object-keys2-0.0.1.tgz_1517754033002_0.27851788117550313","host":"s3://npm-registry-packages"},"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":1517754033084,"_cnpm_publish_time":1517754033084,"dist-tags":{"latest":"3.0.10"}}