asv-hlps 1.0.14 → 1.0.15

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.
@@ -2,6 +2,7 @@ import { SteGrp } from './SteGrp';
2
2
  export interface Ste {
3
3
  id: number;
4
4
  name: string;
5
+ shortname?: string;
5
6
  isValided?: boolean;
6
7
  isActive?: boolean;
7
8
  grp?: SteGrp;
@@ -1,3 +1,4 @@
1
+ import { Ste } from "./models/Ste";
1
2
  import { User } from "./models/User";
2
3
  export declare const inGrp: (grps: string[], user: User) => boolean;
3
4
  export declare const inSteGrp: (grps: string[], user: User) => boolean;
@@ -10,3 +11,5 @@ export declare const secureUser: (user: any, username: string, heads: any) => vo
10
11
  export declare const secureUserPassword: (user: any, heads: any) => void;
11
12
  export declare const userGrpCode: (user: User) => string;
12
13
  export declare const userCoef: (user: User) => number;
14
+ export declare const labelSteName: (ste: Ste, size?: number, tabs?: string[]) => string;
15
+ export declare const getSteShortname: (ste: Ste, [...steGrpNames]: Iterable<any>) => string;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.userCoef = exports.userGrpCode = exports.secureUserPassword = exports.secureUser = exports.entryDesignationUser = exports.getFullname = exports.isStaffSte = exports.isBillPeriod = exports.hasRole = exports.inSteGrp = exports.inGrp = void 0;
29
+ exports.getSteShortname = exports.labelSteName = exports.userCoef = exports.userGrpCode = exports.secureUserPassword = exports.secureUser = exports.entryDesignationUser = exports.getFullname = exports.isStaffSte = exports.isBillPeriod = exports.hasRole = exports.inSteGrp = exports.inGrp = void 0;
30
30
  const bcrypt = __importStar(require("bcryptjs"));
31
31
  const randomatic_1 = __importDefault(require("randomatic"));
32
32
  const shared_1 = require("../utils/shared");
@@ -104,3 +104,32 @@ const userCoef = (user) => {
104
104
  return user.grp.code.toLowerCase() === "st" ? user.ste.grp.coef : user.grp.coef;
105
105
  };
106
106
  exports.userCoef = userCoef;
107
+ const labelSteName = (ste, size = 20, tabs = ['pharmacie', 'clinique', 'hopital']) => {
108
+ const steNameLength = ste.name.length;
109
+ if (steNameLength > size) {
110
+ if (ste.shortname.length > size) {
111
+ const shortedName = (0, exports.getSteShortname)(ste, tabs);
112
+ if (shortedName.length > size) {
113
+ return (0, shared_1.limitTo)(shortedName, (size - 2), '..');
114
+ }
115
+ return shortedName;
116
+ }
117
+ return ste.shortname;
118
+ }
119
+ return ste.name;
120
+ };
121
+ exports.labelSteName = labelSteName;
122
+ const getSteShortname = (ste, [...steGrpNames]) => {
123
+ if (!ste) {
124
+ return null;
125
+ }
126
+ // const tabs = ['pharmacie', 'clinique', 'hopital'];
127
+ const name = ste.name.trimStart();
128
+ const firstWord = name.substring(0, name.indexOf(' '));
129
+ const restWords = name.substring(name.indexOf(' ') + 1);
130
+ return (steGrpNames.includes(firstWord.toLowerCase())) ?
131
+ // ste.grp.code.toLowerCase() + '. ' + restWords.trimLeft() :
132
+ ste.grp.code.toUpperCase() + '. ' + restWords.trimStart() :
133
+ name;
134
+ };
135
+ exports.getSteShortname = getSteShortname;
@@ -2,6 +2,7 @@ import { SteGrp } from './SteGrp';
2
2
  export interface Ste {
3
3
  id: number;
4
4
  name: string;
5
+ shortname?: string;
5
6
  isValided?: boolean;
6
7
  isActive?: boolean;
7
8
  grp?: SteGrp;
@@ -1,3 +1,4 @@
1
+ import { Ste } from "./models/Ste";
1
2
  import { User } from "./models/User";
2
3
  export declare const inGrp: (grps: string[], user: User) => boolean;
3
4
  export declare const inSteGrp: (grps: string[], user: User) => boolean;
@@ -10,3 +11,5 @@ export declare const secureUser: (user: any, username: string, heads: any) => vo
10
11
  export declare const secureUserPassword: (user: any, heads: any) => void;
11
12
  export declare const userGrpCode: (user: User) => string;
12
13
  export declare const userCoef: (user: User) => number;
14
+ export declare const labelSteName: (ste: Ste, size?: number, tabs?: string[]) => string;
15
+ export declare const getSteShortname: (ste: Ste, [...steGrpNames]: Iterable<any>) => string;
@@ -1,6 +1,6 @@
1
1
  import * as bcrypt from "bcryptjs";
2
2
  import randomatic from "randomatic";
3
- import { titleCase } from "../utils/shared";
3
+ import { limitTo, titleCase } from "../utils/shared";
4
4
  export const inGrp = (grps, user) => {
5
5
  return [...grps].includes(user.grp.code.toLowerCase()) ? true : false;
6
6
  };
@@ -64,3 +64,30 @@ export const userGrpCode = (user) => {
64
64
  export const userCoef = (user) => {
65
65
  return user.grp.code.toLowerCase() === "st" ? user.ste.grp.coef : user.grp.coef;
66
66
  };
67
+ export const labelSteName = (ste, size = 20, tabs = ['pharmacie', 'clinique', 'hopital']) => {
68
+ const steNameLength = ste.name.length;
69
+ if (steNameLength > size) {
70
+ if (ste.shortname.length > size) {
71
+ const shortedName = getSteShortname(ste, tabs);
72
+ if (shortedName.length > size) {
73
+ return limitTo(shortedName, (size - 2), '..');
74
+ }
75
+ return shortedName;
76
+ }
77
+ return ste.shortname;
78
+ }
79
+ return ste.name;
80
+ };
81
+ export const getSteShortname = (ste, [...steGrpNames]) => {
82
+ if (!ste) {
83
+ return null;
84
+ }
85
+ // const tabs = ['pharmacie', 'clinique', 'hopital'];
86
+ const name = ste.name.trimStart();
87
+ const firstWord = name.substring(0, name.indexOf(' '));
88
+ const restWords = name.substring(name.indexOf(' ') + 1);
89
+ return (steGrpNames.includes(firstWord.toLowerCase())) ?
90
+ // ste.grp.code.toLowerCase() + '. ' + restWords.trimLeft() :
91
+ ste.grp.code.toUpperCase() + '. ' + restWords.trimStart() :
92
+ name;
93
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",