@ywfe/fe-tools 1.0.2-beta.1 → 1.0.2-beta.10

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,27 +1,30 @@
1
1
  {
2
+ "private": false,
2
3
  "name": "@ywfe/fe-tools",
3
- "version": "1.0.2-beta.1",
4
+ "version": "1.0.2-beta.10",
4
5
  "description": "工具函数库",
5
- "main": "./dist/bundle.js",
6
- "module": "./dist/bundle.js",
6
+ "main": "./lib/ywfe-tools.esm.js",
7
+ "module": "./lib/ywfe-tools.esm.js",
7
8
  "type": "module",
8
- "files": [
9
- "dist"
10
- ],
11
9
  "scripts": {
12
10
  "build": "rollup -c",
13
- "prepublishOnly": "npm run build"
11
+ "build:type": "tsc -p ./tsconfig.type.json",
12
+ "prepublishOnly": "npm run build",
13
+ "test": "jest --coverage"
14
14
  },
15
- "publishConfig": {
16
- "access": "public",
17
- "registry": "https://registry.npmjs.org/"
15
+ "repository": "ywfe",
16
+ "author": {
17
+ "name": "YWFE",
18
+ "email": "ywfe@ywwl.com",
19
+ "url": "http://ywfe.com"
18
20
  },
21
+ "license": "MIT",
19
22
  "dependencies": {
20
- "@ywfe/utils": "^0.10.74"
23
+ "crypto-js": "^4.0.0",
24
+ "ramda": "^0.27.1",
25
+ "strtok3": "^6.3.0",
26
+ "token-types": "^4.2.0",
27
+ "uuid": "^8.3.2"
21
28
  },
22
- "devDependencies": {
23
- "typescript": "^5.4.5"
24
- },
25
- "author": "",
26
- "license": "ISC"
27
- }
29
+ "gitHead": "795058c747c80a3a69f6904dccffb53c42acfcc7"
30
+ }
package/request.ts ADDED
@@ -0,0 +1,49 @@
1
+ // Ctrl-S保存代码
2
+ import {querystring} from '@ywfe/utils'
3
+ interface RequestOptions {
4
+ url:string,
5
+ method?:string,
6
+ params?:any
7
+ }
8
+ async function request({input}:{input:RequestOptions}){
9
+ const method = input.method || 'GET';
10
+ const basePathMap = new Map([
11
+ ['prod', 'https://gateway.ywwl.com'],
12
+ ['test', 'https://test-gateway.ywwl.com'],
13
+ ['test2', 'https://test2-gateway.ywwl.com'],
14
+ ['dev', 'https://dev-gateway.ywwl.com'],
15
+ ])
16
+ const getBasePath = () => {
17
+ const env = '{{env}}';
18
+ return basePathMap.get(env);
19
+ };
20
+ const isValidURL = (url:string)=> {
21
+ var pattern = new RegExp(
22
+ '^(https?:\\/\\/)?' + // protocol
23
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
24
+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
25
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
26
+ '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
27
+ '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
28
+ return !!pattern.test(url);
29
+ }
30
+ const prefix = getBasePath()
31
+ let requestUrl = isValidURL(input.url) ? input.url :`${prefix}${input.url}`
32
+ const fetchOption: {[key:string]:any} = {
33
+ method: method,
34
+ headers: {
35
+ 'Content-type': 'application/json',
36
+ 'x-token': '{{token}}',
37
+ },
38
+ };
39
+ if (method.toUpperCase() === 'POST') {
40
+ fetchOption.body = JSON.stringify(input.params);
41
+ }else if(method.toUpperCase() === 'GET'){
42
+ requestUrl = `${requestUrl}?${querystring.stringify(input.params || {})}`
43
+
44
+ }
45
+
46
+ const res = await fetch(requestUrl, fetchOption);
47
+ return res.json();
48
+ }
49
+ export default request
@@ -0,0 +1,73 @@
1
+ import nodeResolver from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import replace from '@rollup/plugin-replace';
4
+ import json from '@rollup/plugin-json';
5
+ import nodePolyfills from 'rollup-plugin-node-polyfills';
6
+ import clear from 'rollup-plugin-clear';
7
+ import progress from 'rollup-plugin-progress';
8
+ import typescript from '@rollup/plugin-typescript';
9
+ import { terser } from 'rollup-plugin-terser';
10
+ // import pkg from './package.json';
11
+
12
+ const isProd = process.env.NODE_ENV === 'production';
13
+
14
+ const formats = {
15
+ commonjs: {
16
+ format: 'cjs',
17
+ file: 'lib/ywfe-tools.esm.js',
18
+ sourcemap: true,
19
+ exports: 'named',
20
+ },
21
+ esm: {
22
+ format: 'esm',
23
+ file: 'lib/ywfe-tools.esm.js',
24
+ sourcemap: true,
25
+ exports: 'named',
26
+ },
27
+ umd: {
28
+ format: 'umd',
29
+ file: 'lib/ywfe-tools.umd.js',
30
+ name: 'YWTOOLS',
31
+ sourcemap: true,
32
+ exports: 'named',
33
+ globals: {
34
+ 'react': 'React',
35
+ 'react-dom': 'ReactDOM',
36
+ },
37
+ },
38
+ };
39
+
40
+ const config = {
41
+ input: './index.ts',
42
+ inlineDynamicImports: true,
43
+ output: [formats.esm, formats.commonjs],
44
+ external: ['react', 'react-dom'],
45
+ plugins: [
46
+ clear({
47
+ targets: ['lib'],
48
+ }),
49
+ progress({
50
+ clearLine: false,
51
+ }),
52
+ replace({
53
+ NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
54
+ }),
55
+ nodeResolver(),
56
+ commonjs(),
57
+ typescript(),
58
+ json(),
59
+ nodePolyfills(),
60
+ ],
61
+ };
62
+
63
+ if (isProd) {
64
+ const file = formats.umd.file;
65
+
66
+ config.output.push({
67
+ ...formats.umd,
68
+ file,
69
+ plugins: [terser()],
70
+ });
71
+ }
72
+
73
+ export default config;
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "ts-node": {
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "allowSyntheticDefaultImports": true,
6
+ "allowImportingTsExtensions": true,
7
+ "esModuleInterop": true
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationDir": "./lib",
6
+ "emitDeclarationOnly": true
7
+ }
8
+ }