@nymphjs/sorter 1.0.0-beta.63 → 1.0.0-beta.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/lib/Sorter.d.ts +1 -1
- package/lib/Sorter.js +69 -62
- package/lib/Sorter.js.map +1 -1
- package/lib/Sorter.test.js +58 -50
- package/lib/Sorter.test.js.map +1 -1
- package/package.json +2 -2
- package/src/Sorter.test.ts +58 -50
- package/src/Sorter.ts +85 -67
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-beta.65](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.64...v1.0.0-beta.65) (2024-08-05)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- hsort exponential time complexity ([47dc370](https://github.com/sciactive/nymphjs/commit/47dc370a88478dfb7fbfa2d6a257427395451013))
|
|
11
|
+
|
|
12
|
+
# [1.0.0-beta.64](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.63...v1.0.0-beta.64) (2024-08-04)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @nymphjs/sorter
|
|
15
|
+
|
|
6
16
|
# [1.0.0-beta.63](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.62...v1.0.0-beta.63) (2024-06-18)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @nymphjs/sorter
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(r
|
|
1
|
+
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["@nymphjs/sorter"]=r():t["@nymphjs/sorter"]=r()}(this,(()=>(()=>{"use strict";var t={18:(t,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.default=class{constructor(t){this.sortProperty=null,this.sortParent=null,this.collator=new Intl.Collator,this.comparator=void 0,this.array=t}_arraySortProperty(t,r){const e=this.sortProperty,o=this.sortParent;if(null!=o&&t[o]instanceof Object&&r[o]instanceof Object){const s=t[o][e],i=r[o][e];if(void 0!==s||void 0!==i)if(null!=this.comparator){const t=this.comparator(s,i);if(0!==t)return t}else if("string"==typeof s&&"string"==typeof i){const t=this.collator.compare(s,i);if(0!==t)return t}else{if(s>i)return 1;if(s<i)return-1}}const s=t[e],i=r[e];return null!=this.comparator?this.comparator(s,i):"string"==typeof s&&"string"==typeof i?this.collator.compare(s,i):s>i?1:s<i?-1:0}hsort(t,r,{caseSensitive:e=!1,reverse:o=!1,collatorOptions:s,comparator:i}={}){if(null==r)return this.sort(t,{caseSensitive:e,reverse:o,collatorOptions:s,comparator:i}),this.array;this.sortProperty=t,this.sortParent=null,this.collator=new Intl.Collator(void 0,s||{sensitivity:e?"case":"base"}),this.comparator=i;const a=t=>(t.sort(this._arraySortProperty.bind(this)),o&&t.reverse(),t),n={},l=new Map;for(let t=0;t<this.array.length;){const e=this.array[t],o=e[r];if(null==o)t++;else if(null!=o.guid)this.array.splice(t,1),o.guid in n||(n[o.guid]=[]),n[o.guid].push(e);else{this.array.splice(t,1);let r=[];l.has(o)&&(r=l.get(o)||[]),r.push(e),l.set(o,r)}}a(this.array);for(let t=0;t<this.array.length;t++){const r=this.array[t];null!=r.guid?r.guid in n&&(this.array.splice(t+1,0,...a(n[r.guid])),delete n[r.guid]):l.has(r)&&(this.array.splice(t+1,0,...a(l.get(r.guid)||[])),l.delete(r))}for(let t of Object.values(n))this.array.splice(this.array.length,0,...a(t));for(let[t,r]of l)this.array.splice(this.array.length,0,...a(r));return this.array}psort(t,r,{caseSensitive:e=!1,reverse:o=!1,collatorOptions:s,comparator:i}={}){return this.sortProperty=t,this.sortParent=r,this.collator=new Intl.Collator(void 0,s||{sensitivity:e?"case":"base",caseFirst:"false"}),this.comparator=i,this.array.sort(this._arraySortProperty.bind(this)),o&&this.array.reverse(),this.array}sort(t,{caseSensitive:r=!1,reverse:e=!1,collatorOptions:o,comparator:s}={}){return this.sortProperty=t,this.sortParent=null,this.collator=new Intl.Collator(void 0,o||{sensitivity:r?"case":"base"}),this.comparator=s,this.array.sort(this._arraySortProperty.bind(this)),e&&this.array.reverse(),this.array}}},509:function(t,r,e){var o=this&&this.__createBinding||(Object.create?function(t,r,e,o){void 0===o&&(o=e);var s=Object.getOwnPropertyDescriptor(r,e);s&&!("get"in s?!r.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return r[e]}}),Object.defineProperty(t,o,s)}:function(t,r,e,o){void 0===o&&(o=e),t[o]=r[e]}),s=this&&this.__exportStar||function(t,r){for(var e in t)"default"===e||Object.prototype.hasOwnProperty.call(r,e)||o(r,t,e)},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,"__esModule",{value:!0}),r.Sorter=void 0,s(e(18),r);const a=i(e(18));r.Sorter=a.default}},r={};return function e(o){var s=r[o];if(void 0!==s)return s.exports;var i=r[o]={exports:{}};return t[o].call(i.exports,i,i.exports,e),i.exports}(509)})()));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,mBAAqBD,IAE7BD,EAAK,mBAAqBC,GAC3B,CATD,CASGK,MAAM,I,qCCRTC,OAAOC,eAAeN,EAAS,aAAc,CAAEO,OAAO,IA6LtDP,EAAA,QAvLA,MACI,WAAAQ,CAAYC,GACRL,KAAKM,aAAe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,EACII,EAAmBpE,MAAQA,KAAKoE,iBAAoB,SAAUC,GAC9D,OAAQA,GAAOA,EAAIX,WAAcW,EAAM,CAAE,QAAWA,EACxD,EACApE,OAAOC,eAAeN,EAAS,aAAc,CAAEO,OAAO,IACtDP,EAAQ0E,YAAS,EACjBP,EAAa,EAAQ,IAAanE,GAClC,MAAM2E,EAAWH,EAAgB,EAAQ,KACzCxE,EAAQ0E,OAASC,EAASC,O,GCrBtBC,EAA2B,CAAC,E,OAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqB/D,IAAjBgE,EACH,OAAOA,EAAahF,QAGrB,IAAIC,EAAS4E,EAAyBE,GAAY,CAGjD/E,QAAS,CAAC,GAOX,OAHAiF,EAAoBF,GAAUR,KAAKtE,EAAOD,QAASC,EAAQA,EAAOD,QAAS8E,GAGpE7E,EAAOD,OACf,CCnB0B8E,CAAoB,I","sources":["webpack://@nymphjs/sorter/webpack/universalModuleDefinition","webpack://@nymphjs/sorter/./lib/Sorter.js","webpack://@nymphjs/sorter/./lib/index.js","webpack://@nymphjs/sorter/webpack/bootstrap","webpack://@nymphjs/sorter/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@nymphjs/sorter\"] = factory();\n\telse\n\t\troot[\"@nymphjs/sorter\"] = factory();\n})(this, () => {\nreturn ","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * Entity Array Sorter\n *\n * Sorting functions sort the array in place and also return the sorted array.\n */\nclass Sorter {\n constructor(array) {\n this.sortProperty = null;\n this.sortParent = null;\n this.collator = new Intl.Collator();\n this.comparator = undefined;\n this.array = array;\n }\n _arraySortProperty(a, b) {\n const prop = this.sortProperty;\n const parent = this.sortParent;\n if (parent != null &&\n a[parent] instanceof Object &&\n b[parent] instanceof Object) {\n const aParentProp = a[parent][prop];\n const bParentProp = b[parent][prop];\n if (typeof aParentProp !== 'undefined' ||\n typeof bParentProp !== 'undefined') {\n if (this.comparator != null) {\n const result = this.comparator(aParentProp, bParentProp);\n if (result !== 0) {\n return result;\n }\n }\n else if (typeof aParentProp === 'string' &&\n typeof bParentProp === 'string') {\n const result = this.collator.compare(aParentProp, bParentProp);\n if (result !== 0) {\n return result;\n }\n }\n else if (aParentProp > bParentProp) {\n return 1;\n }\n else if (aParentProp < bParentProp) {\n return -1;\n }\n }\n }\n // If they have the same parent, order them by their own prop.\n const aProp = a[prop];\n const bProp = b[prop];\n if (this.comparator != null) {\n return this.comparator(aProp, bProp);\n }\n else if (typeof aProp === 'string' && typeof bProp === 'string') {\n return this.collator.compare(aProp, bProp);\n }\n else if (aProp > bProp) {\n return 1;\n }\n else if (aProp < bProp) {\n return -1;\n }\n return 0;\n }\n /**\n * Sort an array of entities hierarchically by a specified property's value.\n *\n * Entities will be placed immediately after their parents. The\n * `parentProperty` property, if present, should hold either null, undefined,\n * or the entity's parent.\n *\n * @param property The name of the property to sort entities by.\n * @param parentProperty The name of the property which holds the parent of the entity.\n */\n hsort(property, parentProperty, sortOptions) {\n // First sort by the requested property.\n this.sort(property, sortOptions);\n if (typeof parentProperty === 'undefined' || parentProperty === null) {\n return this.array;\n }\n // Now sort by children.\n let newArray = [];\n // Look for entities ready to go in order.\n let changed;\n while (this.array.length) {\n changed = false;\n for (let key = 0; key < this.array.length; key++) {\n // Must break after adding one, so any following children don't go in\n // the wrong order.\n if (!(parentProperty in this.array[key]) ||\n this.array[key][parentProperty] == null ||\n typeof this.array[key][parentProperty].$inArray !== 'function' ||\n !this.array[key][parentProperty].$inArray([\n ...newArray,\n ...this.array,\n ])) {\n // If they have no parent (or their parent isn't in the array), they\n // go on the end.\n newArray.push(this.array[key]);\n this.array.splice(key, 1);\n changed = true;\n break;\n }\n else if (typeof this.array[key][parentProperty].$arraySearch === 'function') {\n // Else find the parent.\n const pkey = this.array[key][parentProperty].$arraySearch(newArray);\n if (pkey !== -1) {\n // And insert after the parent.\n // This makes entities go to the end of the child list.\n const ancestry = [this.array[key][parentProperty].guid];\n let newKey = pkey;\n while (newKey + 1 < newArray.length &&\n parentProperty in newArray[newKey + 1] &&\n newArray[newKey + 1][parentProperty] != null &&\n ancestry.indexOf(newArray[newKey + 1][parentProperty].guid) !== -1) {\n ancestry.push(newArray[newKey + 1].guid);\n newKey += 1;\n }\n // Where to place the entity.\n newKey += 1;\n if (newKey < newArray.length) {\n // If it already exists, we have to splice it in.\n newArray.splice(newKey, 0, this.array[key]);\n }\n else {\n // Else just add it.\n newArray.push(this.array[key]);\n }\n this.array.splice(key, 1);\n changed = true;\n break;\n }\n }\n }\n if (!changed) {\n // If there are any unexpected errors and the array isn't changed, just\n // stick the rest on the end.\n if (this.array.length) {\n newArray = newArray.concat(this.array);\n this.array.splice(0, this.array.length);\n }\n }\n }\n // Now push the new array out.\n this.array.splice(0, 0, ...newArray);\n return this.array;\n }\n /**\n * Sort an array of entities by parent and a specified property's value.\n *\n * Entities' will be sorted by their parents' properties, then the entities'\n * properties.\n *\n * @param property The name of the property to sort entities by.\n * @param parentProperty The name of the property which holds the parent of the entity.\n */\n psort(property, parentProperty, { caseSensitive = false, reverse = false, collatorOptions = undefined, comparator = undefined, } = {}) {\n // Sort by the requested property.\n this.sortProperty = property;\n this.sortParent = parentProperty;\n this.collator = new Intl.Collator(undefined, collatorOptions || {\n sensitivity: caseSensitive ? 'case' : 'base',\n caseFirst: 'false',\n });\n this.comparator = comparator;\n this.array.sort(this._arraySortProperty.bind(this));\n if (reverse) {\n this.array.reverse();\n }\n return this.array;\n }\n /**\n * Sort an array of entities by a specified property's value.\n *\n * @param property The name of the property to sort entities by.\n */\n sort(property, { caseSensitive = false, reverse = false, collatorOptions = undefined, comparator = undefined, } = {}) {\n // Sort by the requested property.\n this.sortProperty = property;\n this.sortParent = null;\n this.collator = new Intl.Collator(undefined, collatorOptions || {\n sensitivity: caseSensitive ? 'case' : 'base',\n });\n this.comparator = comparator;\n this.array.sort(this._arraySortProperty.bind(this));\n if (reverse) {\n this.array.reverse();\n }\n return this.array;\n }\n}\nexports.default = Sorter;\n//# sourceMappingURL=Sorter.js.map","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Sorter = void 0;\n__exportStar(require(\"./Sorter\"), exports);\nconst Sorter_1 = __importDefault(require(\"./Sorter\"));\nexports.Sorter = Sorter_1.default;\n//# sourceMappingURL=index.js.map","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(509);\n"],"names":["root","factory","exports","module","define","amd","this","Object","defineProperty","value","constructor","array","sortProperty","sortParent","collator","Intl","Collator","comparator","undefined","_arraySortProperty","a","b","prop","parent","aParentProp","bParentProp","result","compare","aProp","bProp","hsort","property","parentProperty","sortOptions","sort","changed","newArray","length","key","$inArray","push","splice","$arraySearch","pkey","ancestry","guid","newKey","indexOf","concat","psort","caseSensitive","reverse","collatorOptions","sensitivity","caseFirst","bind","__createBinding","create","o","m","k","k2","desc","getOwnPropertyDescriptor","__esModule","writable","configurable","enumerable","get","__exportStar","p","prototype","hasOwnProperty","call","__importDefault","mod","Sorter","Sorter_1","default","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,mBAAqBD,IAE7BD,EAAK,mBAAqBC,GAC3B,CATD,CASGK,MAAM,I,qCCRTC,OAAOC,eAAeN,EAAS,aAAc,CAAEO,OAAO,IAoMtDP,EAAA,QA9LA,MACI,WAAAQ,CAAYC,GACRL,KAAKM,aAAe,KACpBN,KAAKO,WAAa,KAClBP,KAAKQ,SAAW,IAAIC,KAAKC,SACzBV,KAAKW,gBAAaC,EAClBZ,KAAKK,MAAQA,CACjB,CACA,kBAAAQ,CAAmBC,EAAGC,GAClB,MAAMC,EAAOhB,KAAKM,aACZW,EAASjB,KAAKO,WACpB,GAAc,MAAVU,GACAH,EAAEG,aAAmBhB,QACrBc,EAAEE,aAAmBhB,OAAQ,CAC7B,MAAMiB,EAAcJ,EAAEG,GAAQD,GACxBG,EAAcJ,EAAEE,GAAQD,GAC9B,QAA2B,IAAhBE,QACgB,IAAhBC,EACP,GAAuB,MAAnBnB,KAAKW,WAAoB,CACzB,MA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AOC,eAAeN,EAAS,aAAc,CAAEO,OAAO,IACtDP,EAAQ0E,YAAS,EACjBP,EAAa,EAAQ,IAAanE,GAClC,MAAM2E,EAAWH,EAAgB,EAAQ,KACzCxE,EAAQ0E,OAASC,EAASC,O,GCrBtBC,EAA2B,CAAC,E,OAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqB/D,IAAjBgE,EACH,OAAOA,EAAahF,QAGrB,IAAIC,EAAS4E,EAAyBE,GAAY,CAGjD/E,QAAS,CAAC,GAOX,OAHAiF,EAAoBF,GAAUR,KAAKtE,EAAOD,QAASC,EAAQA,EAAOD,QAAS8E,GAGpE7E,EAAOD,OACf,CCnB0B8E,CAAoB,I","sources":["webpack://@nymphjs/sorter/webpack/universalModuleDefinition","webpack://@nymphjs/sorter/./lib/Sorter.js","webpack://@nymphjs/sorter/./lib/index.js","webpack://@nymphjs/sorter/webpack/bootstrap","webpack://@nymphjs/sorter/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@nymphjs/sorter\"] = factory();\n\telse\n\t\troot[\"@nymphjs/sorter\"] = factory();\n})(this, () => {\nreturn ","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * Entity Array Sorter\n *\n * Sorting functions sort the array in place and also return the sorted array.\n */\nclass Sorter {\n constructor(array) {\n this.sortProperty = null;\n this.sortParent = null;\n this.collator = new Intl.Collator();\n this.comparator = undefined;\n this.array = array;\n }\n _arraySortProperty(a, b) {\n const prop = this.sortProperty;\n const parent = this.sortParent;\n if (parent != null &&\n a[parent] instanceof Object &&\n b[parent] instanceof Object) {\n const aParentProp = a[parent][prop];\n const bParentProp = b[parent][prop];\n if (typeof aParentProp !== 'undefined' ||\n typeof bParentProp !== 'undefined') {\n if (this.comparator != null) {\n const result = this.comparator(aParentProp, bParentProp);\n if (result !== 0) {\n return result;\n }\n }\n else if (typeof aParentProp === 'string' &&\n typeof bParentProp === 'string') {\n const result = this.collator.compare(aParentProp, bParentProp);\n if (result !== 0) {\n return result;\n }\n }\n else if (aParentProp > bParentProp) {\n return 1;\n }\n else if (aParentProp < bParentProp) {\n return -1;\n }\n }\n }\n // If they have the same parent, order them by their own prop.\n const aProp = a[prop];\n const bProp = b[prop];\n if (this.comparator != null) {\n return this.comparator(aProp, bProp);\n }\n else if (typeof aProp === 'string' && typeof bProp === 'string') {\n return this.collator.compare(aProp, bProp);\n }\n else if (aProp > bProp) {\n return 1;\n }\n else if (aProp < bProp) {\n return -1;\n }\n return 0;\n }\n /**\n * Sort an array of entities hierarchically by a specified property's value.\n *\n * Entities will be placed immediately after their parents. The\n * `parentProperty` property, if present, should hold either null, undefined,\n * or the entity's parent.\n *\n * @param property The name of the property to sort entities by.\n * @param parentProperty The name of the property which holds the parent of the entity.\n */\n hsort(property, parentProperty, { caseSensitive = false, reverse = false, collatorOptions = undefined, comparator = undefined, } = {}) {\n if (typeof parentProperty === 'undefined' || parentProperty === null) {\n // Just sort by the requested property.\n this.sort(property, {\n caseSensitive,\n reverse,\n collatorOptions,\n comparator,\n });\n return this.array;\n }\n this.sortProperty = property;\n this.sortParent = null;\n this.collator = new Intl.Collator(undefined, collatorOptions || {\n sensitivity: caseSensitive ? 'case' : 'base',\n });\n this.comparator = comparator;\n const sort = (array) => {\n // Sort by the requested property.\n array.sort(this._arraySortProperty.bind(this));\n if (reverse) {\n array.reverse();\n }\n return array;\n };\n // Pick out all of the children.\n const guidEntries = {};\n const newEntries = new Map();\n // There is no incrementor in this for loop on purpose. It is incremented\n // conditionally.\n for (let i = 0; i < this.array.length;) {\n const entity = this.array[i];\n const parent = entity[parentProperty];\n if (parent == null) {\n i++;\n }\n else if (parent.guid != null) {\n this.array.splice(i, 1);\n if (!(parent.guid in guidEntries)) {\n guidEntries[parent.guid] = [];\n }\n guidEntries[parent.guid].push(entity);\n }\n else {\n this.array.splice(i, 1);\n let entries = [];\n if (newEntries.has(parent)) {\n entries = newEntries.get(parent) || [];\n }\n entries.push(entity);\n newEntries.set(parent, entries);\n }\n }\n // Sort the top level entries.\n sort(this.array);\n // Now place all of the children back in order.\n for (let i = 0; i < this.array.length; i++) {\n const entity = this.array[i];\n if (entity.guid != null) {\n if (entity.guid in guidEntries) {\n this.array.splice(i + 1, 0, ...sort(guidEntries[entity.guid]));\n delete guidEntries[entity.guid];\n }\n }\n else {\n if (newEntries.has(entity)) {\n this.array.splice(i + 1, 0, ...sort(newEntries.get(entity.guid) || []));\n newEntries.delete(entity);\n }\n }\n }\n // Now place any orphans on the end.\n for (let orphans of Object.values(guidEntries)) {\n this.array.splice(this.array.length, 0, ...sort(orphans));\n }\n for (let [parent, orphans] of newEntries) {\n this.array.splice(this.array.length, 0, ...sort(orphans));\n }\n return this.array;\n }\n /**\n * Sort an array of entities by parent and a specified property's value.\n *\n * Entities' will be sorted by their parents' properties, then the entities'\n * properties.\n *\n * @param property The name of the property to sort entities by.\n * @param parentProperty The name of the property which holds the parent of the entity.\n */\n psort(property, parentProperty, { caseSensitive = false, reverse = false, collatorOptions = undefined, comparator = undefined, } = {}) {\n // Sort by the requested property.\n this.sortProperty = property;\n this.sortParent = parentProperty;\n this.collator = new Intl.Collator(undefined, collatorOptions || {\n sensitivity: caseSensitive ? 'case' : 'base',\n caseFirst: 'false',\n });\n this.comparator = comparator;\n this.array.sort(this._arraySortProperty.bind(this));\n if (reverse) {\n this.array.reverse();\n }\n return this.array;\n }\n /**\n * Sort an array of entities by a specified property's value.\n *\n * @param property The name of the property to sort entities by.\n */\n sort(property, { caseSensitive = false, reverse = false, collatorOptions = undefined, comparator = undefined, } = {}) {\n // Sort by the requested property.\n this.sortProperty = property;\n this.sortParent = null;\n this.collator = new Intl.Collator(undefined, collatorOptions || {\n sensitivity: caseSensitive ? 'case' : 'base',\n });\n this.comparator = comparator;\n this.array.sort(this._arraySortProperty.bind(this));\n if (reverse) {\n this.array.reverse();\n }\n return this.array;\n }\n}\nexports.default = Sorter;\n//# sourceMappingURL=Sorter.js.map","\"use strict\";\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Sorter = void 0;\n__exportStar(require(\"./Sorter\"), exports);\nconst Sorter_1 = __importDefault(require(\"./Sorter\"));\nexports.Sorter = Sorter_1.default;\n//# sourceMappingURL=index.js.map","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(509);\n"],"names":["root","factory","exports","module","define","amd","this","Object","defineProperty","value","constructor","array","sortProperty","sortParent","collator","Intl","Collator","comparator","undefined","_arraySortProperty","a","b","prop","parent","aParentProp","bParentProp","result","compare","aProp","bProp","hsort","property","parentProperty","caseSensitive","reverse","collatorOptions","sort","sensitivity","bind","guidEntries","newEntries","Map","i","length","entity","guid","splice","push","entries","has","get","set","delete","orphans","values","psort","caseFirst","__createBinding","create","o","m","k","k2","desc","getOwnPropertyDescriptor","__esModule","writable","configurable","enumerable","__exportStar","p","prototype","hasOwnProperty","call","__importDefault","mod","Sorter","Sorter_1","default","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|
package/lib/Sorter.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export default class Sorter<Entity extends Object> {
|
|
|
33
33
|
* @param property The name of the property to sort entities by.
|
|
34
34
|
* @param parentProperty The name of the property which holds the parent of the entity.
|
|
35
35
|
*/
|
|
36
|
-
hsort(property: string, parentProperty: string,
|
|
36
|
+
hsort(property: string, parentProperty: string, { caseSensitive, reverse, collatorOptions, comparator, }?: SortOptions): Entity[];
|
|
37
37
|
/**
|
|
38
38
|
* Sort an array of entities by parent and a specified property's value.
|
|
39
39
|
*
|
package/lib/Sorter.js
CHANGED
|
@@ -71,77 +71,84 @@ class Sorter {
|
|
|
71
71
|
* @param property The name of the property to sort entities by.
|
|
72
72
|
* @param parentProperty The name of the property which holds the parent of the entity.
|
|
73
73
|
*/
|
|
74
|
-
hsort(property, parentProperty,
|
|
75
|
-
// First sort by the requested property.
|
|
76
|
-
this.sort(property, sortOptions);
|
|
74
|
+
hsort(property, parentProperty, { caseSensitive = false, reverse = false, collatorOptions = undefined, comparator = undefined, } = {}) {
|
|
77
75
|
if (typeof parentProperty === 'undefined' || parentProperty === null) {
|
|
76
|
+
// Just sort by the requested property.
|
|
77
|
+
this.sort(property, {
|
|
78
|
+
caseSensitive,
|
|
79
|
+
reverse,
|
|
80
|
+
collatorOptions,
|
|
81
|
+
comparator,
|
|
82
|
+
});
|
|
78
83
|
return this.array;
|
|
79
84
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
this.sortProperty = property;
|
|
86
|
+
this.sortParent = null;
|
|
87
|
+
this.collator = new Intl.Collator(undefined, collatorOptions || {
|
|
88
|
+
sensitivity: caseSensitive ? 'case' : 'base',
|
|
89
|
+
});
|
|
90
|
+
this.comparator = comparator;
|
|
91
|
+
const sort = (array) => {
|
|
92
|
+
// Sort by the requested property.
|
|
93
|
+
array.sort(this._arraySortProperty.bind(this));
|
|
94
|
+
if (reverse) {
|
|
95
|
+
array.reverse();
|
|
96
|
+
}
|
|
97
|
+
return array;
|
|
98
|
+
};
|
|
99
|
+
// Pick out all of the children.
|
|
100
|
+
const guidEntries = {};
|
|
101
|
+
const newEntries = new Map();
|
|
102
|
+
// There is no incrementor in this for loop on purpose. It is incremented
|
|
103
|
+
// conditionally.
|
|
104
|
+
for (let i = 0; i < this.array.length;) {
|
|
105
|
+
const entity = this.array[i];
|
|
106
|
+
const parent = entity[parentProperty];
|
|
107
|
+
if (parent == null) {
|
|
108
|
+
i++;
|
|
109
|
+
}
|
|
110
|
+
else if (parent.guid != null) {
|
|
111
|
+
this.array.splice(i, 1);
|
|
112
|
+
if (!(parent.guid in guidEntries)) {
|
|
113
|
+
guidEntries[parent.guid] = [];
|
|
102
114
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
let newKey = pkey;
|
|
111
|
-
while (newKey + 1 < newArray.length &&
|
|
112
|
-
parentProperty in newArray[newKey + 1] &&
|
|
113
|
-
newArray[newKey + 1][parentProperty] != null &&
|
|
114
|
-
ancestry.indexOf(newArray[newKey + 1][parentProperty].guid) !== -1) {
|
|
115
|
-
ancestry.push(newArray[newKey + 1].guid);
|
|
116
|
-
newKey += 1;
|
|
117
|
-
}
|
|
118
|
-
// Where to place the entity.
|
|
119
|
-
newKey += 1;
|
|
120
|
-
if (newKey < newArray.length) {
|
|
121
|
-
// If it already exists, we have to splice it in.
|
|
122
|
-
newArray.splice(newKey, 0, this.array[key]);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
// Else just add it.
|
|
126
|
-
newArray.push(this.array[key]);
|
|
127
|
-
}
|
|
128
|
-
this.array.splice(key, 1);
|
|
129
|
-
changed = true;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
115
|
+
guidEntries[parent.guid].push(entity);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.array.splice(i, 1);
|
|
119
|
+
let entries = [];
|
|
120
|
+
if (newEntries.has(parent)) {
|
|
121
|
+
entries = newEntries.get(parent) || [];
|
|
132
122
|
}
|
|
123
|
+
entries.push(entity);
|
|
124
|
+
newEntries.set(parent, entries);
|
|
133
125
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
}
|
|
127
|
+
// Sort the top level entries.
|
|
128
|
+
sort(this.array);
|
|
129
|
+
// Now place all of the children back in order.
|
|
130
|
+
for (let i = 0; i < this.array.length; i++) {
|
|
131
|
+
const entity = this.array[i];
|
|
132
|
+
if (entity.guid != null) {
|
|
133
|
+
if (entity.guid in guidEntries) {
|
|
134
|
+
this.array.splice(i + 1, 0, ...sort(guidEntries[entity.guid]));
|
|
135
|
+
delete guidEntries[entity.guid];
|
|
140
136
|
}
|
|
141
137
|
}
|
|
138
|
+
else {
|
|
139
|
+
if (newEntries.has(entity)) {
|
|
140
|
+
this.array.splice(i + 1, 0, ...sort(newEntries.get(entity.guid) || []));
|
|
141
|
+
newEntries.delete(entity);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Now place any orphans on the end.
|
|
146
|
+
for (let orphans of Object.values(guidEntries)) {
|
|
147
|
+
this.array.splice(this.array.length, 0, ...sort(orphans));
|
|
148
|
+
}
|
|
149
|
+
for (let [parent, orphans] of newEntries) {
|
|
150
|
+
this.array.splice(this.array.length, 0, ...sort(orphans));
|
|
142
151
|
}
|
|
143
|
-
// Now push the new array out.
|
|
144
|
-
this.array.splice(0, 0, ...newArray);
|
|
145
152
|
return this.array;
|
|
146
153
|
}
|
|
147
154
|
/**
|
package/lib/Sorter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sorter.js","sourceRoot":"","sources":["../src/Sorter.ts"],"names":[],"mappings":";;AAWA;;;;GAIG;AACH,MAAqB,MAAM;IAOzB,YAAY,KAAe;QALnB,iBAAY,GAAkB,IAAI,CAAC;QACnC,eAAU,GAAkB,IAAI,CAAC;QACjC,aAAQ,GAAkB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9C,eAAU,GAA6C,SAAS,CAAC;QAGvE,IAAI,CAAC,KAAK,GAAG,KAA0C,CAAC;IAC1D,CAAC;IAEO,kBAAkB,CACxB,CAAgC,EAChC,CAAgC;QAEhC,MAAM,IAAI,GAAG,IAAI,CAAC,YAAsB,CAAC;QACzC,MAAM,MAAM,GAAG,IAAI,CAAC,UAAoB,CAAC;QAEzC,IACE,MAAM,IAAI,IAAI;YACd,CAAC,CAAC,MAAM,CAAC,YAAY,MAAM;YAC3B,CAAC,CAAC,MAAM,CAAC,YAAY,MAAM,EAC3B,CAAC;YACD,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;YACpC,IACE,OAAO,WAAW,KAAK,WAAW;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OAAO,IAAI,CAAC,KAAiB,CAAC;IAChC,CAAC;CACF;AAnPD,yBAmPC"}
|
package/lib/Sorter.test.js
CHANGED
|
@@ -176,48 +176,54 @@ describe('Sorter', () => {
|
|
|
176
176
|
]);
|
|
177
177
|
});
|
|
178
178
|
it('sorts entities hierarchically', () => {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
179
|
+
const getEntries = () => {
|
|
180
|
+
const firstParent = new testArtifacts_1.TestModel();
|
|
181
|
+
firstParent.name = 'Herbert';
|
|
182
|
+
const secondParent = new testArtifacts_1.TestModel();
|
|
183
|
+
secondParent.name = 'Anthony';
|
|
184
|
+
const subParent = new testArtifacts_1.TestModel();
|
|
185
|
+
subParent.name = 'Lamar';
|
|
186
|
+
subParent.parent = secondParent;
|
|
187
|
+
return [
|
|
188
|
+
(() => {
|
|
189
|
+
const entity = new testArtifacts_1.TestModel();
|
|
190
|
+
entity.name = 'Jacob';
|
|
191
|
+
entity.parent = firstParent;
|
|
192
|
+
return entity;
|
|
193
|
+
})(),
|
|
194
|
+
(() => {
|
|
195
|
+
const entity = new testArtifacts_1.TestModel();
|
|
196
|
+
entity.name = 'Joshua';
|
|
197
|
+
entity.parent = firstParent;
|
|
198
|
+
return entity;
|
|
199
|
+
})(),
|
|
200
|
+
subParent,
|
|
201
|
+
(() => {
|
|
202
|
+
const entity = new testArtifacts_1.TestModel();
|
|
203
|
+
entity.name = 'Peter';
|
|
204
|
+
entity.parent = secondParent;
|
|
205
|
+
return entity;
|
|
206
|
+
})(),
|
|
207
|
+
(() => {
|
|
208
|
+
const entity = new testArtifacts_1.TestModel();
|
|
209
|
+
entity.name = 'Warren';
|
|
210
|
+
entity.parent = subParent;
|
|
211
|
+
return entity;
|
|
212
|
+
})(),
|
|
213
|
+
(() => {
|
|
214
|
+
const entity = new testArtifacts_1.TestModel();
|
|
215
|
+
entity.name = 'Arthur';
|
|
216
|
+
entity.parent = subParent;
|
|
217
|
+
return entity;
|
|
218
|
+
})(),
|
|
219
|
+
firstParent,
|
|
220
|
+
secondParent,
|
|
221
|
+
];
|
|
222
|
+
};
|
|
223
|
+
const entities = [];
|
|
224
|
+
for (let i = 0; i < 100; i++) {
|
|
225
|
+
entities.push(...getEntries());
|
|
226
|
+
}
|
|
221
227
|
const sorter = new Sorter_1.default(entities);
|
|
222
228
|
sorter.hsort('name', 'parent');
|
|
223
229
|
expect(sorter.array.map((entity) => {
|
|
@@ -229,14 +235,16 @@ describe('Sorter', () => {
|
|
|
229
235
|
}
|
|
230
236
|
return output + entity.name;
|
|
231
237
|
})).toEqual([
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
...[...Array(100)]
|
|
239
|
+
.map(() => [
|
|
240
|
+
'Anthony',
|
|
241
|
+
'- Lamar',
|
|
242
|
+
'- - Arthur',
|
|
243
|
+
'- - Warren',
|
|
244
|
+
'- Peter',
|
|
245
|
+
])
|
|
246
|
+
.flat(),
|
|
247
|
+
...[...Array(100)].map(() => ['Herbert', '- Jacob', '- Joshua']).flat(),
|
|
240
248
|
]);
|
|
241
249
|
});
|
|
242
250
|
it('sorts array in place', () => {
|
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CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACpD,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG;SACJ,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACxD,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG;SACJ,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YAClD,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG;YACH,GAAG;SACJ,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nymphjs/sorter",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.65",
|
|
4
4
|
"description": "Nymph.js - Sorter",
|
|
5
5
|
"browser": "dist/index.js",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"webpack": "^5.90.3",
|
|
48
48
|
"webpack-cli": "^5.1.4"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "5ddd665dadc649d08e5628a0e2ba0dcbaddff31e"
|
|
51
51
|
}
|
package/src/Sorter.test.ts
CHANGED
|
@@ -193,48 +193,54 @@ describe('Sorter', () => {
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
it('sorts entities hierarchically', () => {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
196
|
+
const getEntries = () => {
|
|
197
|
+
const firstParent = new TestModel();
|
|
198
|
+
firstParent.name = 'Herbert';
|
|
199
|
+
const secondParent = new TestModel();
|
|
200
|
+
secondParent.name = 'Anthony';
|
|
201
|
+
const subParent = new TestModel();
|
|
202
|
+
subParent.name = 'Lamar';
|
|
203
|
+
subParent.parent = secondParent;
|
|
204
|
+
return [
|
|
205
|
+
(() => {
|
|
206
|
+
const entity = new TestModel();
|
|
207
|
+
entity.name = 'Jacob';
|
|
208
|
+
entity.parent = firstParent;
|
|
209
|
+
return entity;
|
|
210
|
+
})(),
|
|
211
|
+
(() => {
|
|
212
|
+
const entity = new TestModel();
|
|
213
|
+
entity.name = 'Joshua';
|
|
214
|
+
entity.parent = firstParent;
|
|
215
|
+
return entity;
|
|
216
|
+
})(),
|
|
217
|
+
subParent,
|
|
218
|
+
(() => {
|
|
219
|
+
const entity = new TestModel();
|
|
220
|
+
entity.name = 'Peter';
|
|
221
|
+
entity.parent = secondParent;
|
|
222
|
+
return entity;
|
|
223
|
+
})(),
|
|
224
|
+
(() => {
|
|
225
|
+
const entity = new TestModel();
|
|
226
|
+
entity.name = 'Warren';
|
|
227
|
+
entity.parent = subParent;
|
|
228
|
+
return entity;
|
|
229
|
+
})(),
|
|
230
|
+
(() => {
|
|
231
|
+
const entity = new TestModel();
|
|
232
|
+
entity.name = 'Arthur';
|
|
233
|
+
entity.parent = subParent;
|
|
234
|
+
return entity;
|
|
235
|
+
})(),
|
|
236
|
+
firstParent,
|
|
237
|
+
secondParent,
|
|
238
|
+
];
|
|
239
|
+
};
|
|
240
|
+
const entities: TestModel[] = [];
|
|
241
|
+
for (let i = 0; i < 100; i++) {
|
|
242
|
+
entities.push(...getEntries());
|
|
243
|
+
}
|
|
238
244
|
|
|
239
245
|
const sorter = new Sorter(entities);
|
|
240
246
|
|
|
@@ -250,14 +256,16 @@ describe('Sorter', () => {
|
|
|
250
256
|
return output + entity.name;
|
|
251
257
|
}),
|
|
252
258
|
).toEqual([
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
...[...Array(100)]
|
|
260
|
+
.map(() => [
|
|
261
|
+
'Anthony',
|
|
262
|
+
'- Lamar',
|
|
263
|
+
'- - Arthur',
|
|
264
|
+
'- - Warren',
|
|
265
|
+
'- Peter',
|
|
266
|
+
])
|
|
267
|
+
.flat(),
|
|
268
|
+
...[...Array(100)].map(() => ['Herbert', '- Jacob', '- Joshua']).flat(),
|
|
261
269
|
]);
|
|
262
270
|
});
|
|
263
271
|
|
package/src/Sorter.ts
CHANGED
|
@@ -92,83 +92,101 @@ export default class Sorter<Entity extends Object> {
|
|
|
92
92
|
public hsort(
|
|
93
93
|
property: string,
|
|
94
94
|
parentProperty: string,
|
|
95
|
-
|
|
95
|
+
{
|
|
96
|
+
caseSensitive = false,
|
|
97
|
+
reverse = false,
|
|
98
|
+
collatorOptions = undefined,
|
|
99
|
+
comparator = undefined,
|
|
100
|
+
}: SortOptions = {},
|
|
96
101
|
): Entity[] {
|
|
97
|
-
// First sort by the requested property.
|
|
98
|
-
this.sort(property, sortOptions);
|
|
99
102
|
if (typeof parentProperty === 'undefined' || parentProperty === null) {
|
|
103
|
+
// Just sort by the requested property.
|
|
104
|
+
this.sort(property, {
|
|
105
|
+
caseSensitive,
|
|
106
|
+
reverse,
|
|
107
|
+
collatorOptions,
|
|
108
|
+
comparator,
|
|
109
|
+
});
|
|
100
110
|
return this.array;
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
let newKey = pkey;
|
|
137
|
-
while (
|
|
138
|
-
newKey + 1 < newArray.length &&
|
|
139
|
-
parentProperty in newArray[newKey + 1] &&
|
|
140
|
-
newArray[newKey + 1][parentProperty] != null &&
|
|
141
|
-
ancestry.indexOf(newArray[newKey + 1][parentProperty].guid) !== -1
|
|
142
|
-
) {
|
|
143
|
-
ancestry.push(newArray[newKey + 1].guid);
|
|
144
|
-
newKey += 1;
|
|
145
|
-
}
|
|
146
|
-
// Where to place the entity.
|
|
147
|
-
newKey += 1;
|
|
148
|
-
if (newKey < newArray.length) {
|
|
149
|
-
// If it already exists, we have to splice it in.
|
|
150
|
-
newArray.splice(newKey, 0, this.array[key]);
|
|
151
|
-
} else {
|
|
152
|
-
// Else just add it.
|
|
153
|
-
newArray.push(this.array[key]);
|
|
154
|
-
}
|
|
155
|
-
this.array.splice(key, 1);
|
|
156
|
-
changed = true;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
113
|
+
this.sortProperty = property;
|
|
114
|
+
this.sortParent = null;
|
|
115
|
+
this.collator = new Intl.Collator(
|
|
116
|
+
undefined,
|
|
117
|
+
collatorOptions || {
|
|
118
|
+
sensitivity: caseSensitive ? 'case' : 'base',
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
this.comparator = comparator;
|
|
122
|
+
const sort = (array: Entity[]) => {
|
|
123
|
+
// Sort by the requested property.
|
|
124
|
+
array.sort(this._arraySortProperty.bind(this));
|
|
125
|
+
if (reverse) {
|
|
126
|
+
array.reverse();
|
|
127
|
+
}
|
|
128
|
+
return array;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Pick out all of the children.
|
|
132
|
+
const guidEntries: { [k: string]: Entity[] } = {};
|
|
133
|
+
const newEntries = new Map<Entity, Entity[]>();
|
|
134
|
+
|
|
135
|
+
// There is no incrementor in this for loop on purpose. It is incremented
|
|
136
|
+
// conditionally.
|
|
137
|
+
for (let i = 0; i < this.array.length; ) {
|
|
138
|
+
const entity = this.array[i];
|
|
139
|
+
const parent = entity[parentProperty];
|
|
140
|
+
if (parent == null) {
|
|
141
|
+
i++;
|
|
142
|
+
} else if (parent.guid != null) {
|
|
143
|
+
this.array.splice(i, 1);
|
|
144
|
+
if (!(parent.guid in guidEntries)) {
|
|
145
|
+
guidEntries[parent.guid] = [];
|
|
159
146
|
}
|
|
147
|
+
guidEntries[parent.guid].push(entity);
|
|
148
|
+
} else {
|
|
149
|
+
this.array.splice(i, 1);
|
|
150
|
+
let entries: Entity[] = [];
|
|
151
|
+
if (newEntries.has(parent)) {
|
|
152
|
+
entries = newEntries.get(parent) || [];
|
|
153
|
+
}
|
|
154
|
+
entries.push(entity);
|
|
155
|
+
newEntries.set(parent, entries);
|
|
160
156
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Sort the top level entries.
|
|
160
|
+
sort(this.array);
|
|
161
|
+
|
|
162
|
+
// Now place all of the children back in order.
|
|
163
|
+
for (let i = 0; i < this.array.length; i++) {
|
|
164
|
+
const entity = this.array[i];
|
|
165
|
+
if (entity.guid != null) {
|
|
166
|
+
if (entity.guid in guidEntries) {
|
|
167
|
+
this.array.splice(i + 1, 0, ...sort(guidEntries[entity.guid]));
|
|
168
|
+
delete guidEntries[entity.guid];
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
if (newEntries.has(entity)) {
|
|
172
|
+
this.array.splice(
|
|
173
|
+
i + 1,
|
|
174
|
+
0,
|
|
175
|
+
...sort(newEntries.get(entity.guid) || []),
|
|
176
|
+
);
|
|
177
|
+
newEntries.delete(entity);
|
|
167
178
|
}
|
|
168
179
|
}
|
|
169
180
|
}
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
|
|
182
|
+
// Now place any orphans on the end.
|
|
183
|
+
for (let orphans of Object.values(guidEntries)) {
|
|
184
|
+
this.array.splice(this.array.length, 0, ...sort(orphans));
|
|
185
|
+
}
|
|
186
|
+
for (let [parent, orphans] of newEntries) {
|
|
187
|
+
this.array.splice(this.array.length, 0, ...sort(orphans));
|
|
188
|
+
}
|
|
189
|
+
|
|
172
190
|
return this.array as Entity[];
|
|
173
191
|
}
|
|
174
192
|
|