bx-rest 0.0.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.
Files changed (31) hide show
  1. package/.editorconfig +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +0 -0
  4. package/package.json +36 -0
  5. package/src/const/time.ts +3 -0
  6. package/src/index.ts +0 -0
  7. package/src/rest/user/user.ts +341 -0
  8. package/src/services/base.ts +187 -0
  9. package/src/services/http/HttpData.ts +142 -0
  10. package/src/services/http/base/HttpData.ts +140 -0
  11. package/src/services/http/base/base.ts +39 -0
  12. package/src/services/http/base/http.ts +67 -0
  13. package/src/services/http/http.ts +182 -0
  14. package/src/services/snack-bar/snack-bar.service.ts +40 -0
  15. package/src/services/snack-bar/toast-message/toast-message.component.html +13 -0
  16. package/src/services/snack-bar/toast-message/toast-message.component.scss +53 -0
  17. package/src/services/snack-bar/toast-message/toast-message.component.spec.ts +24 -0
  18. package/src/services/snack-bar/toast-message/toast-message.component.ts +26 -0
  19. package/src/typification/rest/base/ApiPaginationBX.ts +3 -0
  20. package/src/typification/rest/base/OrderOptions.ts +3 -0
  21. package/src/typification/rest/base/YesNo.ts +1 -0
  22. package/src/typification/rest/base/fieldBXType.ts +1 -0
  23. package/src/typification/rest/base/filterGenerator.ts +3 -0
  24. package/src/typification/rest/base/httpAnswerBX.ts +15 -0
  25. package/src/typification/rest/settings.ts +7 -0
  26. package/src/typification/rest/support/param.ts +8 -0
  27. package/src/typification/rest/user/CustomUserFieldInfo.ts +70 -0
  28. package/src/typification/rest/user/UserFilterSearch.ts +43 -0
  29. package/src/typification/rest/user/get.ts +17 -0
  30. package/src/typification/rest/user/user.ts +68 -0
  31. package/tsconfig.json +9 -0
package/.editorconfig ADDED
@@ -0,0 +1,17 @@
1
+ # Editor configuration, see https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 4
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.ts]
12
+ quote_type = single
13
+ semi = false
14
+
15
+ [*.md]
16
+ max_line_length = off
17
+ trim_trailing_whitespace = false
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Aricatofuka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "bx-rest",
3
+ "version": "0.0.1",
4
+ "description": "bitrix rest api",
5
+ "main": "index.ts",
6
+ "dependencies": {
7
+ "entities": "^4.5.0",
8
+ "luxon": "^3.3.0",
9
+ "parse5": "^7.1.2",
10
+ "just-clone": "^6.2.0",
11
+ "safevalues": "^0.3.4",
12
+ "just-compare": "^2.3.0",
13
+ "rxjs": "^7.8.1",
14
+ "zone.js": "^0.13.1",
15
+ "tslib": "^2.6.1"
16
+ },
17
+ "devDependencies": {},
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Aricatofuka/bx-rest.git"
24
+ },
25
+ "keywords": [
26
+ "bitrxi",
27
+ "rest",
28
+ "api"
29
+ ],
30
+ "author": "Aricatofuka",
31
+ "license": "ISC",
32
+ "bugs": {
33
+ "url": "https://github.com/Aricatofuka/bx-rest/issues"
34
+ },
35
+ "homepage": "https://github.com/Aricatofuka/bx-rest#readme"
36
+ }
@@ -0,0 +1,3 @@
1
+ export const time = {
2
+ oneDayMilliseconds: 1000 * 60 * 60 * 24
3
+ }
package/src/index.ts ADDED
File without changes
@@ -0,0 +1,341 @@
1
+ import { Observable, of, take } from 'rxjs'
2
+ import { first, map, mergeMap, tap } from 'rxjs/operators'
3
+ import clone from 'just-clone'
4
+ import compare from 'just-compare'
5
+ import { iBXGetParam } from '@/typification/rest/user/get'
6
+ import HttpBXServices from '@/lib/services/api/bitrix/http/HttpBX'
7
+ import UserFilterSearch from '@/lib/typification/bitrix/api/rest/user/UserFilterSearch'
8
+ import ImgServices from '@/lib/services/api/bitrix/custom/img'
9
+ import { Store } from '@ngrx/store'
10
+ import { loadAll, saveArr, saveIDLoadedDepartment, saveSelf, storeUsers } from '@/lib/store/users'
11
+ import { iCustomUserFieldInfo } from '@/lib/typification/bitrix/api/rest/user/CustomUserFieldInfo'
12
+ import { DatePipe } from '@angular/common'
13
+ import { BitrixApiUserMapServices } from '@/lib/services/map/bitrix/api/rest/user'
14
+ import DateTrace from '@/lib/services/api/trace/metods/date'
15
+ import { $get, $list, $search, $update, $user } from '@/lib/services/api/bitrix/rest/consts/part-name-metods'
16
+ import SnackBarService from '@/lib/services/snack-bar/snack-bar.service'
17
+ import iHttpAnswerBX from '@/lib/typification/bitrix/api/rest/base/httpAnswerBX'
18
+ import { iBXRestUser, iBXRestUserHttp, iBXRestUserHttpField } from '@/lib/typification/bitrix/api/rest/user/user'
19
+
20
+ export class BXRestUser {
21
+ url = {
22
+ admin: [$user, 'admin'],
23
+ get: [$user, $get],
24
+ self: [$user, 'current'],
25
+ update: [$user, $update],
26
+ search: [$user, $search],
27
+ access: [$user, 'access'], // U1 - пользователь с id =1
28
+ // AU - все авторизованные пользователи
29
+ // D1 - подразделение с id=1
30
+ // G1 - группа с id=1
31
+ fields: [$user, 'fields'],
32
+ userfield: {
33
+ list: [$user, 'userfield', $list]
34
+ }
35
+ }
36
+
37
+ def: { params: { ACTIVE: 1, start: 0 } } = {
38
+ params: {ACTIVE: 1, start: 0}
39
+ }
40
+
41
+ user$: Observable<storeUsers>
42
+
43
+ constructor(
44
+ private http: HttpBXServices,
45
+ private snackBar: SnackBarService,
46
+ private img: ImgServices,
47
+ private dateTrace: DateTrace,
48
+ private store: Store<{ users: storeUsers }>,
49
+ private userMap: BitrixApiUserMapServices,
50
+ private datePipe: DatePipe
51
+ ) {
52
+ this.user$ = this.store.select('users')
53
+ }
54
+
55
+ get(params: iBXGetParam = {}): Observable<iHttpAnswerBX<iBXRestUserHttp[]> | undefined> {
56
+ let copyParams = clone(params)
57
+ this.setDefParam(copyParams)
58
+ return this.http.post<iHttpAnswerBX<iBXRestUserHttp[]> | undefined>
59
+ (this.url.get, copyParams, 'Не удалось получить пользователей')
60
+ .pipe(
61
+ tap(v => {
62
+ if (v && v.result) {
63
+ this.saveArrUser(v.result)
64
+ }
65
+ })
66
+ )
67
+ }
68
+
69
+ getOnePage(page: number = 1) {
70
+ return this.get({start: (page - 1) * 50}).pipe(
71
+ map(v => {
72
+ let res = this.http.mapResult(v)
73
+ return (res) ? res.map(r => this.userMap.HttpToBX(r)) : undefined
74
+ })
75
+ )
76
+ }
77
+
78
+ getByID(id: number, reload = true): Observable<iBXRestUser | undefined> {
79
+ return this.getByIDs([id], reload).pipe(map(v => (v && v.length) ? v[0] : undefined))
80
+ }
81
+
82
+ getByIDs(ids: number[], reload = true): Observable<iBXRestUser[] | undefined> {
83
+ ids = Array.from(new Set(ids))
84
+ return this.user$.pipe(
85
+ take(1),
86
+ mergeMap(v => {
87
+ if (!reload) {
88
+ let find = v.data.filter(i => ids.includes(i.ID))
89
+ if (find && find.length === ids.length) {
90
+ return of(find)
91
+ }
92
+ }
93
+ return this.getAll({ID: ids, ACTIVE: 2}).pipe(map(v => (v && v.length) ? v : undefined))
94
+ })
95
+ )
96
+ }
97
+
98
+ getSelf(update = false) {
99
+ if (update) {
100
+ return this.getSelfHttp()
101
+ } else {
102
+ return this.user$.pipe(
103
+ mergeMap(v => {
104
+ if (v && v.self) {
105
+ return of(v.self)
106
+ } else {
107
+ return this.getSelfHttp()
108
+ }
109
+ }),
110
+ first()
111
+ )
112
+ }
113
+ }
114
+
115
+ getSelfHttp() {
116
+ return this.http.get<iHttpAnswerBX<iBXRestUserHttp>>
117
+ (this.url.self, {}, 'Не удалось получить пользователя')
118
+ .pipe(
119
+ map(v => {
120
+ if (v && v.result) {
121
+ return this.userMap.HttpToBX(v.result)
122
+ }
123
+ return undefined
124
+ }),
125
+ tap(v => {
126
+ if (v) {
127
+ this.store.dispatch(saveSelf({self: v}))
128
+ }
129
+ }),
130
+ )
131
+ }
132
+
133
+ access(access: string[], textError = 'Не удалось получить права') {
134
+ return this.http.get<iHttpAnswerBX<boolean> | undefined>(this.url.access, {ACCESS: access}, textError).pipe(
135
+ map(v => this.http.mapResult(v))
136
+ )
137
+ }
138
+
139
+ getByDepartment(id: number[] | number): Observable<iBXRestUser [] | undefined> {
140
+ const ids: number[] = (typeof id === 'number') ? [id] : id
141
+ return this.user$.pipe(
142
+ first(),
143
+ mergeMap(
144
+ v => {
145
+ if (v.load.all) {
146
+ return of(clone(v.data.filter(i => ids.find(id => i.UF_DEPARTMENT.includes(id)))))
147
+ }
148
+ if (ids.every(i => v.load.department.includes(i))) {
149
+ return of(clone(v.data.filter(i => ids.find(id => i.UF_DEPARTMENT.includes(id)))))
150
+ }
151
+ return this.getAll({UF_DEPARTMENT: ids}).pipe(tap(_ => {
152
+ this.store.dispatch(saveIDLoadedDepartment({id: ids}))
153
+ }))
154
+ })
155
+ )
156
+ }
157
+
158
+ getAll(params: iBXGetParam = {}): Observable<iBXRestUser [] | undefined> {
159
+ if (!Object.keys(params).length) {
160
+ params = clone(this.def.params)
161
+ }
162
+
163
+ const saveAllUser = compare(params, this.def.params)
164
+ return this.user$.pipe(
165
+ take(1),
166
+ mergeMap(v => {
167
+ if (v.load.all) {
168
+ if (compare(this.def.params, params)) {
169
+ return of(clone(v.data))
170
+ }
171
+ }
172
+
173
+ return this.getEndArray(params).pipe(
174
+ take(1),
175
+ map(v => {
176
+ if (v && v.result) {
177
+ let cl = clone(v.result)
178
+ return this.saveArrUser(cl)
179
+ }
180
+ return undefined
181
+ }),
182
+ )
183
+ }),
184
+ tap(v => {
185
+ if (v && v.length && saveAllUser) {
186
+ this.store.dispatch(loadAll({load: true}))
187
+ }
188
+ params.start = this.def.params.start
189
+ })
190
+ )
191
+ }
192
+
193
+ getAllByPersonalBirthday(day: number | undefined = undefined, month: number | undefined = undefined, checkWeekend = false) {
194
+ return this.http.timeNowOnServer().pipe(
195
+ mergeMap(date => {
196
+ if (date) {
197
+ let daySent = (day) ? day : date.getDate()
198
+ let start = date.getFullYear() + 1
199
+ let monthSent = (month) ? month : date.getMonth() + 1
200
+ let arr: string[] = Array.from(Array(200).keys()).map(_ => {
201
+ start--
202
+ let res = this.datePipe.transform(new Date(start, monthSent - 1, daySent), 'YYYY-MM-dd')
203
+ return (res) ? res : ''
204
+ })
205
+ // TODO: Упростить
206
+ if (checkWeekend && date.getDay() === 1) {
207
+ start = date.getFullYear() + 1
208
+ arr.push(
209
+ ...Array.from(Array(200).keys()).map(_ => {
210
+ start--
211
+ let res = this.datePipe.transform(new Date(start, monthSent - 1, daySent - 1), 'YYYY-MM-dd')
212
+ return (res) ? res : ''
213
+ })
214
+ )
215
+ start = date.getFullYear() + 1
216
+ arr.push(
217
+ ...Array.from(Array(200).keys()).map(_ => {
218
+ start--
219
+ let res = this.datePipe.transform(new Date(start, monthSent - 1, daySent - 2), 'YYYY-MM-dd')
220
+ return (res) ? res : ''
221
+ })
222
+ )
223
+ }
224
+ return this.getAll({PERSONAL_BIRTHDAY: arr})
225
+ }
226
+ this.snackBar.warning('Не удалось получить время сервера')
227
+ return of(undefined)
228
+ })
229
+ )
230
+ }
231
+
232
+ saveArrUser(users: iBXRestUserHttp[]) {
233
+ let result: iBXRestUser [] = []
234
+ for (const user of users) {
235
+ result.push(this.userMap.HttpToBX(user))
236
+ }
237
+ this.store.dispatch(saveArr({arr: result}))
238
+
239
+ return result
240
+ }
241
+
242
+ search(params: string | UserFilterSearch): Observable<iBXRestUser [] | undefined> {
243
+ if (typeof params === 'string') {
244
+ params = {FIND: params}
245
+ }
246
+ if (typeof params.ACTIVE !== 'boolean') {
247
+ params.ACTIVE = true
248
+ }
249
+ return this.http.get<iHttpAnswerBX<iBXRestUserHttp[]>>(this.url.search, params, 'Сервер не отвечает на запрос поиска')
250
+ .pipe(
251
+ map(v => {
252
+ if (v && v.result) {
253
+ const mapResult = this.http.mapResult(v)
254
+ if (mapResult) {
255
+ return this.saveArrUser(mapResult)
256
+ }
257
+ }
258
+ return undefined
259
+ })
260
+ )
261
+ }
262
+
263
+ fields(): Observable<iBXRestUserHttpField | undefined> {
264
+ return this.http.get<iHttpAnswerBX<iBXRestUserHttpField>>(this.url.fields).pipe(
265
+ map(v => this.http.mapResult(v))
266
+ )
267
+ }
268
+
269
+ update(user: iBXRestUser, fieldUpdate: string[]): Observable<iHttpAnswerBX<iBXRestUserHttp[]> | undefined> {
270
+ if (fieldUpdate && fieldUpdate.length) {
271
+ let sendData: any = {
272
+ ID: user.ID,
273
+ }
274
+ const userBX = this.userMap.BXtoHttp(user)
275
+ for (const field of fieldUpdate) {
276
+ if (userBX[field]) {
277
+ sendData[field] = userBX[field]
278
+ } else {
279
+ this.snackBar.error('Одно из указанных полей отправлено не верно')
280
+ }
281
+ }
282
+ return this.http.post(this.url.update, sendData, 'Не удалось обновить пользователя с ID' + user.ID)
283
+ } else {
284
+ this.snackBar.error('Не указано ни одно поле для редактирования пользователя')
285
+ return of({})
286
+ }
287
+ }
288
+
289
+ getEndArray(params: UserFilter = {}): Observable<iHttpAnswerBX<iBXRestUserHttp[]> | undefined> {
290
+ return this.get(params).pipe(
291
+ mergeMap(items => {
292
+ if (items && items.result && typeof items.result === 'object') {
293
+ if (items.next) {
294
+ params.start = items.next
295
+ return this.getEndArray(params).pipe(map(vEnd => {
296
+ if (vEnd && items.result && vEnd.result) {
297
+ return {result: [...items.result, ...vEnd.result]}
298
+ }
299
+ return (items) ? items : undefined
300
+ }))
301
+ }
302
+ return of(items)
303
+ } else {
304
+ return of(undefined)
305
+ }
306
+ }),
307
+ )
308
+ }
309
+
310
+ getUrlCompressedImage(url: string, width: number, height: number) {
311
+ return this.img.getUrlCompressed(url, width, height)
312
+ }
313
+
314
+ setDefParam(params: iBXGetParam) {
315
+ if (!params.hasOwnProperty('ACTIVE')) {
316
+ params.ACTIVE = this.def.params.ACTIVE
317
+ }
318
+ if (params.ACTIVE && params.ACTIVE === 2) {
319
+ delete params.ACTIVE
320
+ }
321
+ if (!params.hasOwnProperty('start')) {
322
+ params.start = this.def.params.start
323
+ }
324
+
325
+ if (params.UF_DEPARTMENT && !params.UF_DEPARTMENT.length) {
326
+ delete params.UF_DEPARTMENT
327
+ }
328
+ }
329
+
330
+ getInfoAboutCustomFieldsBX() {
331
+ return this.http.get<iHttpAnswerBX<iCustomUserFieldInfo[]>>(this.url.userfield.list).pipe(
332
+ map(v => this.http.mapResult(v))
333
+ )
334
+ }
335
+
336
+ itIsAdmin() {
337
+ return this.http.get<iHttpAnswerBX<boolean>>(this.url.admin).pipe(
338
+ map(v => this.http.mapResult(v))
339
+ )
340
+ }
341
+ }
@@ -0,0 +1,187 @@
1
+ import { Injectable } from '@angular/core'
2
+ import { time } from '@/const/time'
3
+ // import { environment } from '@/environments/environment'
4
+ import { DateTime } from 'luxon'
5
+ import { DateTimeOptions } from 'luxon/src/datetime'
6
+
7
+ @Injectable({
8
+ providedIn: 'root'
9
+ })
10
+ export class BaseServices {
11
+
12
+ toStr(val: any): string {
13
+ return (val) ? String(val) : ''
14
+ }
15
+
16
+ toNumber(val: any): number {
17
+ return (val && Number(val)) ? Number(val) : 0
18
+ }
19
+
20
+ toDate(val: number | string | Date, format?: string, opt?: DateTimeOptions): Date {
21
+ if (val instanceof Date) {
22
+ return val
23
+ } else if (typeof val == 'string') {
24
+ if (format) {
25
+ if (opt) {
26
+ return DateTime.fromFormat(val, format, opt).toJSDate()
27
+ }
28
+ return DateTime.fromFormat(val, format).toJSDate()
29
+ } else {
30
+ return new Date(val)
31
+ }
32
+ } else if (typeof val == 'number') {
33
+ return new Date(val)
34
+ }
35
+ console.error('Wrong date format', val, format)
36
+ throw 'Wrong date format'
37
+ }
38
+
39
+ getBXStrTime(date: Date): string {
40
+ return this.toISOStringWithTimezone(date)
41
+ }
42
+
43
+ toISOStringWithTimezone(date: Date): string {
44
+ const tzOffset = -date.getTimezoneOffset()
45
+ const diff = tzOffset >= 0 ? '+' : '-'
46
+ const pad = (n: number) => `${Math.floor(Math.abs(n))}`.padStart(2, '0')
47
+ return date.getFullYear() +
48
+ '-' + pad(date.getMonth() + 1) +
49
+ '-' + pad(date.getDate()) +
50
+ 'T' + pad(date.getHours()) +
51
+ ':' + pad(date.getMinutes()) +
52
+ ':' + pad(date.getSeconds()) +
53
+ diff + pad(tzOffset / 60) +
54
+ ':' + pad(tzOffset % 60)
55
+ };
56
+
57
+ toBool(val: any) {
58
+ switch (typeof val) {
59
+ case 'string':
60
+ val = val.toLowerCase()
61
+ if (val === 'n' || val === 'y') { // битриксовые понятия о bool
62
+ return val === 'y'
63
+ } else if (val === 'true' || val === 'false') { // битриксовые понятия о bool
64
+ return val === 'true'
65
+ } else {
66
+ return false
67
+ }
68
+ default:
69
+ return Boolean(val)
70
+ }
71
+ }
72
+
73
+ toBXYorN(val: boolean) {
74
+ return (val) ? 'Y' : 'N'
75
+ }
76
+
77
+ typeof(val: any) {
78
+ return typeof val
79
+ }
80
+
81
+ typeDefClass(val: object): undefined | null | 'date' {
82
+ if (val) {
83
+ if (val instanceof Date) {
84
+ return 'date'
85
+ }
86
+ return undefined
87
+ } else {
88
+ return null
89
+ }
90
+ }
91
+
92
+ toJSON(val: object) {
93
+ return JSON.stringify(val)
94
+ }
95
+
96
+ fromJSON<T>(val: string): T | undefined {
97
+ return JSON.parse(val)
98
+ }
99
+
100
+ prepareBaseAddress(url: string, add: string = '') {
101
+ if (url.search('https://') !== 0 && url.search('http://')) {
102
+ url = 'https://' + url
103
+ }
104
+
105
+ if (url.lastIndexOf('/') !== (url.length - 1)) {
106
+ url = url + '/'
107
+ }
108
+
109
+ url = url + add
110
+
111
+ return url
112
+ }
113
+
114
+ getHomeAddress() {
115
+ // return this.prepareBaseAddress(environment.urls.home)
116
+ return this.prepareBaseAddress('b24.trace-studio.com')
117
+ }
118
+
119
+ dateDiff(a: Date, b: Date) {
120
+ return new Date(a.valueOf() - b.valueOf())
121
+ }
122
+
123
+ dateDiffInDays(a: Date, b: Date) {
124
+ return Math.floor(this.dateDiff(a, b).valueOf() / time.oneDayMilliseconds);
125
+ }
126
+
127
+ getBase64File(file: File) {
128
+ return new Promise((resolve, reject) => {
129
+ const reader = new FileReader()
130
+ reader.readAsDataURL(file)
131
+ reader.onload = () => resolve(reader.result)
132
+ reader.onerror = error => reject(error)
133
+ })
134
+ }
135
+
136
+ async getBase64FileLikeStr(file: File): Promise<{ header: string, val: string } | undefined> {
137
+ let result = await this.getBase64File(file)
138
+ if (typeof result === 'string') {
139
+ let split = result.split(',')
140
+ return {
141
+ header: split[0],
142
+ val: split[1]
143
+ }
144
+ }
145
+ return undefined
146
+ }
147
+
148
+ sumArray(numbers: number[]) {
149
+ return numbers.reduce((a, b) => {
150
+ return a + b;
151
+ })
152
+ }
153
+
154
+ isItTheSameDate(date1: Date, date2: Date) {
155
+ return date1.getDate() === date2.getDate()
156
+ && date1.getMonth() === date2.getMonth()
157
+ && date1.getFullYear() === date2.getFullYear()
158
+ }
159
+
160
+ toUnix(date: Date) {
161
+ return Math.floor(date.valueOf() / 1000)
162
+ }
163
+
164
+ arrSum(x: number[]) {
165
+ let s = 0;
166
+ for (let i = 0; i < x.length; i++) {
167
+ s += x[i]
168
+ }
169
+ return s
170
+ }
171
+
172
+ getBaseUrlHttps(url: string, component = false) {
173
+ if (component) {
174
+ return encodeURI(this.cropUrl(url) + '/');
175
+ } else {
176
+ return encodeURI('https://' + this.cropUrl(url) + '/');
177
+ }
178
+ }
179
+
180
+ cropUrl(url: string) {
181
+ url = (url) ? url.replace('https://', '') : ''
182
+ url = (url) ? url.replace('http://', '') : ''
183
+ url = (url) ? url.replace('https:', '') : ''
184
+ url = (url) ? url.replace('http:', '') : ''
185
+ return url
186
+ }
187
+ }