@pdg/api 1.0.12 → 1.0.13

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/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import axios from'axios';/******************************************************************************
1
+ import axios from'axios';import {urlJoin,notEmpty}from'@pdg/util';/******************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -91,46 +91,7 @@ var ApiError = /** @class */ (function (_super) {
91
91
  return _this;
92
92
  }
93
93
  return ApiError;
94
- }(Error));var empty = function (v) {
95
- var result = false;
96
- if (v == null) {
97
- result = true;
98
- }
99
- else if (typeof v === 'string') {
100
- result = v === '';
101
- }
102
- else if (typeof v === 'object') {
103
- if (Array.isArray(v)) {
104
- result = v.length === 0;
105
- }
106
- else if (!(v instanceof Date)) {
107
- result = Object.entries(v).length === 0;
108
- }
109
- }
110
- return result;
111
- };
112
- var notEmpty = function (v) {
113
- return !empty(v);
114
- };function joinUrl() {
115
- var parts = [];
116
- for (var _i = 0; _i < arguments.length; _i++) {
117
- parts[_i] = arguments[_i];
118
- }
119
- return parts.reduce(function (acc, part) {
120
- if (acc === '') {
121
- return part;
122
- }
123
- else if (part.startsWith('?')) {
124
- return "".concat(acc).concat(part);
125
- }
126
- else if (acc.endsWith('/')) {
127
- return "".concat(acc).concat(part.startsWith('/') ? part.substring(1) : part);
128
- }
129
- else {
130
- return "".concat(acc).concat(part.startsWith('/') ? part : "/".concat(part));
131
- }
132
- });
133
- }var _a;
94
+ }(Error));var _a;
134
95
  var AxiosCreate = axios.create ? axios.create : (_a = require('axios').default) === null || _a === void 0 ? void 0 : _a.create;
135
96
  var Api = /** @class */ (function () {
136
97
  // constructor -------------------------------------------------------------------------------------------------------
@@ -155,7 +116,7 @@ var Api = /** @class */ (function () {
155
116
  if (option === null || option === void 0 ? void 0 : option.raw) {
156
117
  requestConfig.responseType = (option === null || option === void 0 ? void 0 : option.rawResponseType) || 'arraybuffer';
157
118
  }
158
- requestConfig.url = joinUrl(_this.option.baseUrl, path.replace(/\./g, '/'));
119
+ requestConfig.url = urlJoin(_this.option.baseUrl, path.replace(/\./g, '/'));
159
120
  if (data) {
160
121
  if (method === 'get') {
161
122
  if (notEmpty(data)) {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var axios=require('axios');/******************************************************************************
1
+ 'use strict';var axios=require('axios'),util=require('@pdg/util');/******************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -91,46 +91,7 @@ var ApiError = /** @class */ (function (_super) {
91
91
  return _this;
92
92
  }
93
93
  return ApiError;
94
- }(Error));var empty = function (v) {
95
- var result = false;
96
- if (v == null) {
97
- result = true;
98
- }
99
- else if (typeof v === 'string') {
100
- result = v === '';
101
- }
102
- else if (typeof v === 'object') {
103
- if (Array.isArray(v)) {
104
- result = v.length === 0;
105
- }
106
- else if (!(v instanceof Date)) {
107
- result = Object.entries(v).length === 0;
108
- }
109
- }
110
- return result;
111
- };
112
- var notEmpty = function (v) {
113
- return !empty(v);
114
- };function joinUrl() {
115
- var parts = [];
116
- for (var _i = 0; _i < arguments.length; _i++) {
117
- parts[_i] = arguments[_i];
118
- }
119
- return parts.reduce(function (acc, part) {
120
- if (acc === '') {
121
- return part;
122
- }
123
- else if (part.startsWith('?')) {
124
- return "".concat(acc).concat(part);
125
- }
126
- else if (acc.endsWith('/')) {
127
- return "".concat(acc).concat(part.startsWith('/') ? part.substring(1) : part);
128
- }
129
- else {
130
- return "".concat(acc).concat(part.startsWith('/') ? part : "/".concat(part));
131
- }
132
- });
133
- }var _a;
94
+ }(Error));var _a;
134
95
  var AxiosCreate = axios.create ? axios.create : (_a = require('axios').default) === null || _a === void 0 ? void 0 : _a.create;
135
96
  var Api = /** @class */ (function () {
136
97
  // constructor -------------------------------------------------------------------------------------------------------
@@ -155,10 +116,10 @@ var Api = /** @class */ (function () {
155
116
  if (option === null || option === void 0 ? void 0 : option.raw) {
156
117
  requestConfig.responseType = (option === null || option === void 0 ? void 0 : option.rawResponseType) || 'arraybuffer';
157
118
  }
158
- requestConfig.url = joinUrl(_this.option.baseUrl, path.replace(/\./g, '/'));
119
+ requestConfig.url = util.urlJoin(_this.option.baseUrl, path.replace(/\./g, '/'));
159
120
  if (data) {
160
121
  if (method === 'get') {
161
- if (notEmpty(data)) {
122
+ if (util.notEmpty(data)) {
162
123
  var finalData = {};
163
124
  finalData[_this.option.timeParamName] = new Date().getTime();
164
125
  for (var key in data) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pdg/api",
3
3
  "title": "API Module",
4
- "version": "1.0.12",
4
+ "version": "1.0.13",
5
5
  "description": "API Module",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
@@ -36,6 +36,7 @@
36
36
  "javascript"
37
37
  ],
38
38
  "peerDependencies": {
39
+ "@pdg/util": "^1.0.0",
39
40
  "axios": "^1.0.0"
40
41
  },
41
42
  "devDependencies": {
@@ -1,3 +0,0 @@
1
- declare const empty: (v: any) => boolean;
2
- declare const notEmpty: (v: any) => boolean;
3
- export { empty, notEmpty };
@@ -1,2 +0,0 @@
1
- export * from './compare';
2
- export * from './url';
@@ -1 +0,0 @@
1
- export declare function joinUrl(...parts: string[]): string;