react-hook-core 0.4.3 → 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 CHANGED
@@ -8,8 +8,11 @@ var resources = (function () {
8
8
  resources.phone = / |-|\.|\(|\)/g;
9
9
  resources._cache = {};
10
10
  resources.cache = true;
11
- resources.limit = 24;
12
- resources.pages = exports.pageSizes;
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
  }());
@@ -59,10 +62,10 @@ function message(gv, msg, title, yes, no) {
59
62
  }
60
63
  exports.message = message;
61
64
  function messageByHttpStatus(status, gv) {
62
- var k = 'status_' + status;
65
+ var k = 'error_' + status;
63
66
  var msg = getString(k, gv);
64
67
  if (!msg || msg.length === 0) {
65
- msg = getString('error_internal', gv);
68
+ msg = getString('error_500', gv);
66
69
  }
67
70
  return msg;
68
71
  }
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 = "fields";
413
+ fields = core_1.resources.fields;
414
414
  }
415
415
  if (!limit || limit.length === 0) {
416
- limit = "limit";
416
+ limit = core_1.resources.limit;
417
417
  }
418
- if (page && page > 1) {
419
- if (!ft.page || ft.page <= 1) {
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.limit) {
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 + "=" + encodeURI(objValue));
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(encodeURI(subValue));
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 + "=" + encodeURI(objValueLvl2));
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.limit;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-core",
3
- "version": "0.4.3",
3
+ "version": "0.4.6",
4
4
  "description": "react",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
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 limit = 24;
11
- static pages = pageSizes;
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;
@@ -209,10 +212,10 @@ export function message(gv: StringMap | ((key: string) => string), msg: string,
209
212
  return m;
210
213
  }
211
214
  export function messageByHttpStatus(status: number, gv: StringMap | ((key: string) => string)): string {
212
- const k = 'status_' + status;
215
+ const k = 'error_' + status;
213
216
  let msg = getString(k, gv);
214
217
  if (!msg || msg.length === 0) {
215
- msg = getString('error_internal', gv);
218
+ msg = getString('error_500', gv);
216
219
  }
217
220
  return msg;
218
221
  }
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 = "fields"
417
+ fields = resources.fields
418
418
  }
419
419
  if (!limit || limit.length === 0) {
420
- limit = "limit"
420
+ limit = resources.limit
421
421
  }
422
- if (page && page > 1) {
423
- if (!ft.page || ft.page <= 1) {
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.limit) {
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}=${encodeURI(objValue)}`
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(encodeURI(subValue))
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}=${encodeURI(objValueLvl2)}`
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.limit;
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);