web-one 0.0.7 → 0.0.8

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/lib/index.js CHANGED
@@ -354,6 +354,35 @@ function buildSortSearch(params, fields, sortStr) {
354
354
  return sorts;
355
355
  }
356
356
  exports.buildSortSearch = buildSortSearch;
357
+ function buildSorts(sorts, prefix) {
358
+ const l = sorts.length;
359
+ for (let i = 0; i < l; i++) {
360
+ sorts[i].value = prefix + sorts[i].value;
361
+ }
362
+ }
363
+ exports.buildSorts = buildSorts;
364
+ function getSortText(sorts, sort, defaultText, textOnly) {
365
+ if (!sort) {
366
+ return defaultText;
367
+ }
368
+ const l = sorts.length;
369
+ if (textOnly) {
370
+ for (let i = 0; i < l; i++) {
371
+ if (sorts[i].value === sort) {
372
+ return sorts[i].text;
373
+ }
374
+ }
375
+ }
376
+ else {
377
+ for (let i = 0; i < l; i++) {
378
+ if (sorts[i].value === sort) {
379
+ return sorts[i].fulltext;
380
+ }
381
+ }
382
+ }
383
+ return defaultText;
384
+ }
385
+ exports.getSortText = getSortText;
357
386
  function formatInteger(v, groupSeparator = ",") {
358
387
  if (v == null || !Number.isFinite(v)) {
359
388
  return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-one",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Web utilities",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -336,6 +336,38 @@ export function buildSortSearch(params: Record<string, string | string[] | undef
336
336
  }
337
337
  return sorts
338
338
  }
339
+ export interface Item {
340
+ id?: string
341
+ value: string
342
+ text?: string
343
+ fulltext?: string
344
+ }
345
+ export function buildSorts(sorts: Item[], prefix: string) {
346
+ const l = sorts.length
347
+ for (let i = 0; i < l; i++) {
348
+ sorts[i].value = prefix + sorts[i].value
349
+ }
350
+ }
351
+ export function getSortText(sorts: Item[], sort: string | undefined, defaultText?: string, textOnly?: boolean): string | undefined {
352
+ if (!sort) {
353
+ return defaultText
354
+ }
355
+ const l = sorts.length
356
+ if (textOnly) {
357
+ for (let i = 0; i < l; i++) {
358
+ if (sorts[i].value === sort) {
359
+ return sorts[i].text
360
+ }
361
+ }
362
+ } else {
363
+ for (let i = 0; i < l; i++) {
364
+ if (sorts[i].value === sort) {
365
+ return sorts[i].fulltext
366
+ }
367
+ }
368
+ }
369
+ return defaultText
370
+ }
339
371
  export function formatInteger(v?: number | null, groupSeparator: string = ","): string {
340
372
  if (v == null || !Number.isFinite(v)) {
341
373
  return ""