react-hook-core 0.4.5 → 0.4.6
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/core.js +5 -2
- package/lib/search.js +9 -11
- package/lib/useSearch.js +1 -1
- package/package.json +1 -1
- package/src/core.ts +5 -2
- package/src/search.ts +9 -11
- package/src/useSearch.ts +1 -1
package/lib/core.js
CHANGED
|
@@ -8,8 +8,11 @@ var resources = (function () {
|
|
|
8
8
|
resources.phone = / |-|\.|\(|\)/g;
|
|
9
9
|
resources._cache = {};
|
|
10
10
|
resources.cache = true;
|
|
11
|
-
resources.
|
|
12
|
-
resources.
|
|
11
|
+
resources.fields = "fields";
|
|
12
|
+
resources.page = "page";
|
|
13
|
+
resources.limit = "limit";
|
|
14
|
+
resources.defaultLimit = 24;
|
|
15
|
+
resources.limits = exports.pageSizes;
|
|
13
16
|
resources.pageMaxSize = 7;
|
|
14
17
|
return resources;
|
|
15
18
|
}());
|
package/lib/search.js
CHANGED
|
@@ -410,17 +410,15 @@ function getPrefix(url) {
|
|
|
410
410
|
function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
411
411
|
if (!isFirstLoad) {
|
|
412
412
|
if (!fields || fields.length === 0) {
|
|
413
|
-
fields =
|
|
413
|
+
fields = core_1.resources.fields;
|
|
414
414
|
}
|
|
415
415
|
if (!limit || limit.length === 0) {
|
|
416
|
-
limit =
|
|
416
|
+
limit = core_1.resources.limit;
|
|
417
417
|
}
|
|
418
|
-
if (page
|
|
419
|
-
|
|
420
|
-
ft.page = page;
|
|
421
|
-
}
|
|
418
|
+
if (page) {
|
|
419
|
+
ft[core_1.resources.page] = page;
|
|
422
420
|
}
|
|
423
|
-
var pageIndex = ft.page;
|
|
421
|
+
var pageIndex = ft[core_1.resources.page];
|
|
424
422
|
if (pageIndex && !isNaN(pageIndex) && pageIndex <= 1) {
|
|
425
423
|
delete ft.page;
|
|
426
424
|
}
|
|
@@ -434,13 +432,13 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
434
432
|
if (key !== fields) {
|
|
435
433
|
if (typeof objValue === "string" || typeof objValue === "number") {
|
|
436
434
|
if (key === limit) {
|
|
437
|
-
if (objValue !== core_1.resources.
|
|
435
|
+
if (objValue !== core_1.resources.defaultLimit) {
|
|
438
436
|
url += getPrefix(url) + (key + "=" + objValue);
|
|
439
437
|
}
|
|
440
438
|
}
|
|
441
439
|
else {
|
|
442
440
|
if (typeof objValue === "string") {
|
|
443
|
-
url += getPrefix(url) + (key + "=" +
|
|
441
|
+
url += getPrefix(url) + (key + "=" + encodeURIComponent(objValue));
|
|
444
442
|
}
|
|
445
443
|
else {
|
|
446
444
|
url += getPrefix(url) + (key + "=" + objValue);
|
|
@@ -458,7 +456,7 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
458
456
|
for (var _a = 0, objValue_1 = objValue; _a < objValue_1.length; _a++) {
|
|
459
457
|
var subValue = objValue_1[_a];
|
|
460
458
|
if (typeof subValue === "string") {
|
|
461
|
-
strs.push(
|
|
459
|
+
strs.push(encodeURIComponent(subValue));
|
|
462
460
|
}
|
|
463
461
|
else if (typeof subValue === "number") {
|
|
464
462
|
strs.push(subValue.toString());
|
|
@@ -478,7 +476,7 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
478
476
|
}
|
|
479
477
|
else {
|
|
480
478
|
if (typeof objValueLvl2 === "string") {
|
|
481
|
-
url += getPrefix(url) + (key + "." + key2 + "=" +
|
|
479
|
+
url += getPrefix(url) + (key + "." + key2 + "=" + encodeURIComponent(objValueLvl2));
|
|
482
480
|
}
|
|
483
481
|
else {
|
|
484
482
|
url += getPrefix(url) + (key + "." + key2 + "=" + objValueLvl2);
|
package/lib/useSearch.js
CHANGED
|
@@ -26,7 +26,7 @@ exports.callSearch = function (se, search3, showResults3, searchError3, lc, next
|
|
|
26
26
|
page = 1;
|
|
27
27
|
}
|
|
28
28
|
if (!se.limit || se.limit <= 0) {
|
|
29
|
-
se.limit = core_1.resources.
|
|
29
|
+
se.limit = core_1.resources.defaultLimit;
|
|
30
30
|
}
|
|
31
31
|
var limit = (page <= 1 && se.firstLimit && se.firstLimit > 0 ? se.firstLimit : se.limit);
|
|
32
32
|
var next = (nextPageToken && nextPageToken.length > 0 ? nextPageToken : page);
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -7,8 +7,11 @@ export class resources {
|
|
|
7
7
|
static phone = / |-|\.|\(|\)/g;
|
|
8
8
|
static _cache: any = {};
|
|
9
9
|
static cache = true;
|
|
10
|
-
static
|
|
11
|
-
static
|
|
10
|
+
static fields = "fields";
|
|
11
|
+
static page = "page";
|
|
12
|
+
static limit = "limit";
|
|
13
|
+
static defaultLimit = 24;
|
|
14
|
+
static limits = pageSizes;
|
|
12
15
|
static pageMaxSize = 7;
|
|
13
16
|
}
|
|
14
17
|
export const size = pageSizes;
|
package/src/search.ts
CHANGED
|
@@ -414,17 +414,15 @@ function getPrefix(url: string): string {
|
|
|
414
414
|
export function addParametersIntoUrl<S extends Filter>(ft: S, isFirstLoad?: boolean, page?: number, fields?: string, limit?: string): void {
|
|
415
415
|
if (!isFirstLoad) {
|
|
416
416
|
if (!fields || fields.length === 0) {
|
|
417
|
-
fields =
|
|
417
|
+
fields = resources.fields
|
|
418
418
|
}
|
|
419
419
|
if (!limit || limit.length === 0) {
|
|
420
|
-
limit =
|
|
420
|
+
limit = resources.limit
|
|
421
421
|
}
|
|
422
|
-
if (page
|
|
423
|
-
|
|
424
|
-
ft.page = page
|
|
425
|
-
}
|
|
422
|
+
if (page) {
|
|
423
|
+
(ft as any)[resources.page] = page;
|
|
426
424
|
}
|
|
427
|
-
const pageIndex = ft.page
|
|
425
|
+
const pageIndex = (ft as any)[resources.page]
|
|
428
426
|
if (pageIndex && !isNaN(pageIndex) && pageIndex <= 1) {
|
|
429
427
|
delete ft.page
|
|
430
428
|
}
|
|
@@ -437,12 +435,12 @@ export function addParametersIntoUrl<S extends Filter>(ft: S, isFirstLoad?: bool
|
|
|
437
435
|
if (key !== fields) {
|
|
438
436
|
if (typeof objValue === "string" || typeof objValue === "number") {
|
|
439
437
|
if (key === limit) {
|
|
440
|
-
if (objValue !== resources.
|
|
438
|
+
if (objValue !== resources.defaultLimit) {
|
|
441
439
|
url += getPrefix(url) + `${key}=${objValue}`
|
|
442
440
|
}
|
|
443
441
|
} else {
|
|
444
442
|
if (typeof objValue === "string") {
|
|
445
|
-
url += getPrefix(url) + `${key}=${
|
|
443
|
+
url += getPrefix(url) + `${key}=${encodeURIComponent(objValue)}`
|
|
446
444
|
} else {
|
|
447
445
|
url += getPrefix(url) + `${key}=${objValue}`
|
|
448
446
|
}
|
|
@@ -456,7 +454,7 @@ export function addParametersIntoUrl<S extends Filter>(ft: S, isFirstLoad?: bool
|
|
|
456
454
|
const strs: string[] = []
|
|
457
455
|
for (const subValue of objValue) {
|
|
458
456
|
if (typeof subValue === "string") {
|
|
459
|
-
strs.push(
|
|
457
|
+
strs.push(encodeURIComponent(subValue))
|
|
460
458
|
} else if (typeof subValue === "number") {
|
|
461
459
|
strs.push(subValue.toString())
|
|
462
460
|
}
|
|
@@ -472,7 +470,7 @@ export function addParametersIntoUrl<S extends Filter>(ft: S, isFirstLoad?: bool
|
|
|
472
470
|
url += getPrefix(url) + `${key}.${key2}=${objValueLvl2.toISOString()}`
|
|
473
471
|
} else {
|
|
474
472
|
if (typeof objValueLvl2 === "string") {
|
|
475
|
-
url += getPrefix(url) + `${key}.${key2}=${
|
|
473
|
+
url += getPrefix(url) + `${key}.${key2}=${encodeURIComponent(objValueLvl2)}`
|
|
476
474
|
} else {
|
|
477
475
|
url += getPrefix(url) + `${key}.${key2}=${objValueLvl2}`
|
|
478
476
|
}
|
package/src/useSearch.ts
CHANGED
|
@@ -19,7 +19,7 @@ export const callSearch = <T, S extends Filter>(se: S, search3: (s: S, limit?: n
|
|
|
19
19
|
page = 1;
|
|
20
20
|
}
|
|
21
21
|
if (!se.limit || se.limit <= 0) {
|
|
22
|
-
se.limit = resources.
|
|
22
|
+
se.limit = resources.defaultLimit;
|
|
23
23
|
}
|
|
24
24
|
const limit = (page <= 1 && se.firstLimit && se.firstLimit > 0 ? se.firstLimit : se.limit);
|
|
25
25
|
const next = (nextPageToken && nextPageToken.length > 0 ? nextPageToken : page);
|