loginterface 1.0.6 → 1.1.0

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.js CHANGED
@@ -41,13 +41,16 @@ const generateInterfaces = (obj, rootName = 'Generated') => {
41
41
  const resolveType = (value, parentName, propName) => {
42
42
  if (value === null)
43
43
  return 'any';
44
+ if (value instanceof Date) {
45
+ return 'Date'; // <-- treat Date as primitive type
46
+ }
44
47
  if (Array.isArray(value)) {
45
48
  if (value.length === 0)
46
49
  return 'any[]';
47
- const firstItem = value.find((v) => v !== null);
50
+ const firstItem = value.find((v) => v !== null && v !== undefined);
48
51
  if (!firstItem)
49
52
  return 'any[]';
50
- if (typeof firstItem === 'object' && !Array.isArray(firstItem)) {
53
+ if (typeof firstItem === 'object' && !(firstItem instanceof Date) && !Array.isArray(firstItem)) {
51
54
  const interfaceName = parentName + capitalize(propName);
52
55
  generateInterface(firstItem, interfaceName);
53
56
  return `${interfaceName}[]`;
@@ -55,6 +58,8 @@ const generateInterfaces = (obj, rootName = 'Generated') => {
55
58
  return `${resolvePrimitive(firstItem)}[]`;
56
59
  }
57
60
  if (typeof value === 'object') {
61
+ if (value instanceof Date)
62
+ return 'Date'; // double check
58
63
  const interfaceName = parentName + capitalize(propName);
59
64
  generateInterface(value, interfaceName);
60
65
  return interfaceName;
package/index.ts CHANGED
@@ -47,32 +47,37 @@ const generateInterfaces = (obj: any, rootName = 'Generated') => {
47
47
  };
48
48
 
49
49
  const resolveType = (value: any, parentName: string, propName: string) => {
50
- if (value === null) return 'any';
50
+ if (value === null) return 'any';
51
51
 
52
- if (Array.isArray(value)) {
53
- if (value.length === 0) return 'any[]';
52
+ if (value instanceof Date) {
53
+ return 'Date'; // <-- treat Date as primitive type
54
+ }
54
55
 
55
- const firstItem = value.find((v) => v !== null);
56
+ if (Array.isArray(value)) {
57
+ if (value.length === 0) return 'any[]';
56
58
 
57
- if (!firstItem) return 'any[]';
59
+ const firstItem = value.find((v) => v !== null && v !== undefined);
58
60
 
59
- if (typeof firstItem === 'object' && !Array.isArray(firstItem)) {
60
- const interfaceName = parentName + capitalize(propName);
61
- generateInterface(firstItem, interfaceName);
62
- return `${interfaceName}[]`;
63
- }
61
+ if (!firstItem) return 'any[]';
64
62
 
65
- return `${resolvePrimitive(firstItem)}[]`;
66
- }
67
-
68
- if (typeof value === 'object') {
63
+ if (typeof firstItem === 'object' && !(firstItem instanceof Date) && !Array.isArray(firstItem)) {
69
64
  const interfaceName = parentName + capitalize(propName);
70
- generateInterface(value, interfaceName);
71
- return interfaceName;
65
+ generateInterface(firstItem, interfaceName);
66
+ return `${interfaceName}[]`;
72
67
  }
73
68
 
74
- return resolvePrimitive(value);
75
- };
69
+ return `${resolvePrimitive(firstItem)}[]`;
70
+ }
71
+
72
+ if (typeof value === 'object') {
73
+ if (value instanceof Date) return 'Date'; // double check
74
+ const interfaceName = parentName + capitalize(propName);
75
+ generateInterface(value, interfaceName);
76
+ return interfaceName;
77
+ }
78
+
79
+ return resolvePrimitive(value);
80
+ };
76
81
 
77
82
  const generateInterface = (obj: any, name: any) => {
78
83
  if (processed.has(name)) return;
package/package.json CHANGED
@@ -1,18 +1,21 @@
1
1
  {
2
2
  "name": "loginterface",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
- "build": "tsc"
8
+ "build": "tsc",
9
+ "publish:patch": "npm run build && npm version patch && npm publish --access public",
10
+ "publish:minor": "npm run build && npm version minor && npm publish --access public",
11
+ "publish:major": "npm run build && npm version major && npm publish --access public"
9
12
  },
10
13
  "author": "Milan Cakic",
11
14
  "license": "MIT",
12
15
  "description": "",
13
16
  "dependencies": {
14
- "rxjs": "^7.0.0"
15
- },
17
+ "rxjs": "^7.0.0"
18
+ },
16
19
  "peerDependencies": {
17
20
  "rxjs": "^7.0.0"
18
21
  },
package/readme.md CHANGED
@@ -3,6 +3,8 @@ RxJS operator that generates interfaces and logs them into console with styling.
3
3
 
4
4
  ### Example usage (Angular)
5
5
  ```ts
6
+ import { logInterface } from 'logInterface';
7
+
6
8
  this.http.get('/endpoint').pipe(logInterface('Interface name'))
7
9
  ```
8
10
  #### Example