@soleil-se/app-util 5.13.0 → 5.14.1
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/common/localized-compare/index.d.ts +11 -2
- package/common/localized-compare/index.js +12 -4
- package/package.json +20 -5
- package/server/index.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ All notable changes to this project will be documented in this file.
|
|
|
7
7
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
8
8
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
9
9
|
|
|
10
|
+
## [5.14.1] - 2026-05-15
|
|
11
|
+
|
|
12
|
+
- Add exports to package.json for better support in ESM environments.
|
|
13
|
+
|
|
14
|
+
## [5.14.0] - 2026-04-24
|
|
15
|
+
|
|
16
|
+
- `localizedCompareBy` now accepts objects with a `key` and optional `order` (`'asc'` | `'desc'`,
|
|
17
|
+
defaults to `'asc'`) in addition to plain strings, enabling per-property sort direction.
|
|
18
|
+
Existing string-based usage is unchanged.
|
|
19
|
+
|
|
10
20
|
## [5.13.0] - 2026-01-16
|
|
11
21
|
|
|
12
22
|
- Add comparator functions `localizedCompare` and `localizedCompareBy` to sort strings and objects
|
|
@@ -11,10 +11,19 @@ export function localizedCompare(a: string, b: string): number;
|
|
|
11
11
|
* Creates a comparator function for sorting objects by a specific property or properties.
|
|
12
12
|
* The property values are compared using localized string comparison.
|
|
13
13
|
* When given an array of properties, sorts by the first property, then by the second if equal, etc.
|
|
14
|
-
*
|
|
14
|
+
* Each property can be a string or an object with a `key` and optional `order` ('asc' | 'desc', defaults to 'asc').
|
|
15
|
+
* @param {string|{key: string, order?: 'asc'|'desc'}|Array<string|{key: string, order?: 'asc'|'desc'}>} prop - The property name(s) to compare by.
|
|
15
16
|
* @returns {(a: Object, b: Object) => number} A comparator function that accepts two objects and returns their sort order.
|
|
16
17
|
* @example
|
|
17
18
|
* arr.sort(localizedCompareBy('title'))
|
|
18
19
|
* arr.sort(localizedCompareBy(['lastName', 'firstName']))
|
|
20
|
+
* arr.sort(localizedCompareBy({ key: 'firstName', order: 'desc' }))
|
|
21
|
+
* arr.sort(localizedCompareBy([{ key: 'lastName', order: 'asc' }, { key: 'firstName', order: 'desc' }]))
|
|
19
22
|
*/
|
|
20
|
-
export function localizedCompareBy(prop: string |
|
|
23
|
+
export function localizedCompareBy(prop: string | {
|
|
24
|
+
key: string;
|
|
25
|
+
order?: 'asc' | 'desc';
|
|
26
|
+
} | Array<string | {
|
|
27
|
+
key: string;
|
|
28
|
+
order?: 'asc' | 'desc';
|
|
29
|
+
}>): (a: any, b: any) => number;
|
|
@@ -82,20 +82,28 @@ export function localizedCompare(a, b) {
|
|
|
82
82
|
* Creates a comparator function for sorting objects by a specific property or properties.
|
|
83
83
|
* The property values are compared using localized string comparison.
|
|
84
84
|
* When given an array of properties, sorts by the first property, then by the second if equal, etc.
|
|
85
|
-
*
|
|
85
|
+
* Each property can be a string or an object with a `key` and optional `order` ('asc' | 'desc', defaults to 'asc').
|
|
86
|
+
* @param {string|{key: string, order?: 'asc'|'desc'}|Array<string|{key: string, order?: 'asc'|'desc'}>} prop - The property name(s) to compare by.
|
|
86
87
|
* @returns {(a: Object, b: Object) => number} A comparator function that accepts two objects and returns their sort order.
|
|
87
88
|
* @example
|
|
88
89
|
* arr.sort(localizedCompareBy('title'))
|
|
89
90
|
* arr.sort(localizedCompareBy(['lastName', 'firstName']))
|
|
91
|
+
* arr.sort(localizedCompareBy({ key: 'firstName', order: 'desc' }))
|
|
92
|
+
* arr.sort(localizedCompareBy([{ key: 'lastName', order: 'asc' }, { key: 'firstName', order: 'desc' }]))
|
|
90
93
|
*/
|
|
91
94
|
export function localizedCompareBy(prop) {
|
|
92
|
-
const props = Array.isArray(prop) ? prop : [prop]
|
|
95
|
+
const props = (Array.isArray(prop) ? prop : [prop])
|
|
96
|
+
.map((p) => (typeof p === 'string'
|
|
97
|
+
? { key: p, order: 'asc' }
|
|
98
|
+
: { key: p.key, order: p.order ?? 'asc' }
|
|
99
|
+
));
|
|
93
100
|
|
|
94
101
|
return (a, b) => {
|
|
95
102
|
for (let i = 0; i < props.length; i += 1) {
|
|
96
|
-
const
|
|
103
|
+
const { key, order } = props[i];
|
|
104
|
+
const result = localizedCompare(a[key], b[key]);
|
|
97
105
|
if (result !== 0) {
|
|
98
|
-
return result;
|
|
106
|
+
return order === 'desc' ? -result : result;
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
return 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.14.1",
|
|
4
4
|
"description": "Utility functions for WebApps, RESTApps and Widgets in Sitevision.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
@@ -16,14 +16,29 @@
|
|
|
16
16
|
"svelte"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@sitevision/api": "^
|
|
20
|
-
"svelte": "^5.
|
|
19
|
+
"@sitevision/api": "^2026.4.2",
|
|
20
|
+
"svelte": "^5.55.7"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@sitevision/api": "*"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"create-type-definitions": "node ../../utils/createTypeDefinitions.js ./common/index.js ./client/index.js ./client/svelte/index.js ./client/svelte/3/index.js ./client/svelte/4/index.js ./client/svelte/5/index.js ./server/index.js ./server/svelte/index.js ./server/svelte/3/index.js ./server/svelte/4/index.js ./server/svelte/5/index.js ./server/app-data/index.js ./server/global-app-data/index.js"
|
|
26
|
+
"create-type-definitions": "node ../../utils/createTypeDefinitions.js ./common/index.js ./common/localized-compare/index.js ./client/index.js ./client/svelte/index.js ./client/svelte/3/index.js ./client/svelte/4/index.js ./client/svelte/5/index.js ./server/index.js ./server/svelte/index.js ./server/svelte/3/index.js ./server/svelte/4/index.js ./server/svelte/5/index.js ./server/app-data/index.js ./server/global-app-data/index.js"
|
|
27
27
|
},
|
|
28
|
-
"
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./common/index.js",
|
|
30
|
+
"./client": "./client/index.js",
|
|
31
|
+
"./client/fetch-json": "./client/fetch-json/index.js",
|
|
32
|
+
"./client/prevent-default": "./client/prevent-default/index.js",
|
|
33
|
+
"./client/url-params": "./client/url-params/index.js",
|
|
34
|
+
"./client/svelte/3": "./client/svelte/3/index.js",
|
|
35
|
+
"./client/svelte/4": "./client/svelte/4/index.js",
|
|
36
|
+
"./client/svelte/5": "./client/svelte/5/index.js",
|
|
37
|
+
"./server": "./server/index.js",
|
|
38
|
+
"./server/app-data": "./server/app-data/index.js",
|
|
39
|
+
"./server/global-app-data": "./server/global-app-data/index.js",
|
|
40
|
+
"./server/svelte/3": "./server/svelte/3/index.js",
|
|
41
|
+
"./server/svelte/4": "./server/svelte/4/index.js",
|
|
42
|
+
"./server/svelte/5": "./server/svelte/5/index.js"
|
|
43
|
+
}
|
|
29
44
|
}
|
package/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Make native requires work with @sitevision/sitevision-scripts that uses Webpack */
|
|
2
|
-
/* eslint-disable camelcase, no-undef
|
|
2
|
+
/* eslint-disable camelcase, no-undef */
|
|
3
3
|
/**
|
|
4
4
|
* Require a module natively, bypassing Webpack bundling.
|
|
5
5
|
* This function behaves like CommonJS require() and is used to import
|
|
@@ -16,7 +16,7 @@ export function nativeRequire(module) {
|
|
|
16
16
|
if (typeof __non_webpack_require__ !== 'undefined') return __non_webpack_require__(module);
|
|
17
17
|
return require(module);
|
|
18
18
|
}
|
|
19
|
-
/* eslint-enable camelcase, no-undef
|
|
19
|
+
/* eslint-enable camelcase, no-undef */
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @typedef {import('@sitevision/api/types/javax/jcr/Node').Node} Node
|