typof 1.0.7 → 1.0.8

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/README.md CHANGED
@@ -87,9 +87,9 @@ Typof
87
87
  ├── number(value)
88
88
  ├── integer(value)
89
89
  ├── boolean(value)
90
+ ├── date(value)
90
91
  ├── object(value)
91
92
  ├── array(value)
92
- ├── date(value)
93
93
  ├── _null(value)
94
94
  ├── _undefined(value)
95
95
 
@@ -136,15 +136,15 @@ Infer types.
136
136
  > typof('true'); // [ "string", "boolean" ]
137
137
  > typof(true); // [ "boolean" ]
138
138
  >
139
+ > typof('2025-01-01'); // [ "string", "date" ]
140
+ > typof(new Date('2025-01-01')); // [ "object", "date" ]
141
+ >
139
142
  > typof('{"key":"value"}'); // [ "string", "object" ]
140
143
  > typof({ key: 'value' }); // [ "object" ]
141
144
  >
142
145
  > typof('["test"]'); // [ "string", "array" ]
143
146
  > typof(['test']); // [ "array" ]
144
147
  >
145
- > typof('2025-01-01'); // [ "string", "date" ]
146
- > typof(new Date('2025-01-01')); // [ "object", "date" ]
147
- >
148
148
  > typof('null'); // [ "string", "null" ]
149
149
  > typof(null); // [ "null" ]
150
150
  >
@@ -169,9 +169,9 @@ Convert to string.
169
169
  > ```typescript
170
170
  > string(0.5); // "0.5"
171
171
  > string(true); // "true"
172
+ > string(new Date('2025-01-01')); // "2025-01-01T00:00:00.000Z"
172
173
  > string({ key: 'value' }); // '{"key":"value"}'
173
174
  > string(['test']); // '["test"]'
174
- > string(new Date('2025-01-01')); // "2025-01-01T00:00:00.000Z"
175
175
  > string(null); // "null"
176
176
  > string(undefined); // "undefined"
177
177
  > ```
@@ -238,60 +238,60 @@ Convert to boolean.
238
238
 
239
239
  <br/>
240
240
 
241
- `object(value)`
241
+ `date(value)`
242
242
 
243
- Convert to object.
243
+ Convert to date.
244
244
 
245
245
  > | Parameter | Type | Default | Description |
246
246
  > | --------- | ------- | ------- | ----------------- |
247
247
  > | value | Unknown | | Value to convert. |
248
248
  >
249
- > returns [Object] | Value
249
+ > returns [Date] | Value
250
250
  >
251
251
  > Example:
252
252
  >
253
253
  > ```typescript
254
- > object('{"key":"value"}'); // { key: "value" }
255
- > object('["test"]'); // '["test"]'
254
+ > date('2025-01-01'); // 2025-01-01T00:00:00.000Z
255
+ > date(new Date('2025-01-01')); // 2025-01-01T00:00:00.000Z
256
+ > date('test'); // "test"
256
257
  > ```
257
258
 
258
259
  <br/>
259
260
 
260
- `array(value)`
261
+ `object(value)`
261
262
 
262
- Convert to array.
263
+ Convert to object.
263
264
 
264
265
  > | Parameter | Type | Default | Description |
265
266
  > | --------- | ------- | ------- | ----------------- |
266
267
  > | value | Unknown | | Value to convert. |
267
268
  >
268
- > returns Unknown\[] | Value
269
+ > returns [Object] | Value
269
270
  >
270
271
  > Example:
271
272
  >
272
273
  > ```typescript
273
- > array('["test"]'); // [ "test" ]
274
- > array('{"key":"value"}'); // '{"key":"value"}'
274
+ > object('{"key":"value"}'); // { key: "value" }
275
+ > object('["test"]'); // '["test"]'
275
276
  > ```
276
277
 
277
278
  <br/>
278
279
 
279
- `date(value)`
280
+ `array(value)`
280
281
 
281
- Convert to date.
282
+ Convert to array.
282
283
 
283
284
  > | Parameter | Type | Default | Description |
284
285
  > | --------- | ------- | ------- | ----------------- |
285
286
  > | value | Unknown | | Value to convert. |
286
287
  >
287
- > returns [Date] | Value
288
+ > returns Unknown\[] | Value
288
289
  >
289
290
  > Example:
290
291
  >
291
292
  > ```typescript
292
- > date('2025-01-01'); // 2025-01-01T00:00:00.000Z
293
- > date(new Date('2025-01-01')); // 2025-01-01T00:00:00.000Z
294
- > date('test'); // "test"
293
+ > array('["test"]'); // [ "test" ]
294
+ > array('{"key":"value"}'); // '{"key":"value"}'
295
295
  > ```
296
296
 
297
297
  <br/>
package/dist/main.d.mts CHANGED
@@ -1,13 +1,13 @@
1
- type Types = 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'object' | 'array' | 'date' | 'null' | 'undefined';
1
+ type Types = 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'date' | 'object' | 'array' | 'null' | 'undefined';
2
2
 
3
3
  declare const typof: (value: unknown) => Types[];
4
4
  declare const string: (value: unknown) => string;
5
5
  declare const number: (value: unknown) => number;
6
6
  declare const integer: (value: unknown) => number;
7
7
  declare const boolean: <Value>(value: Value) => boolean | Value;
8
+ declare const date: <Value>(value: Value) => Date | Value;
8
9
  declare const object: <Value>(value: Value) => object | Value;
9
10
  declare const array: <Value>(value: Value) => unknown[] | Value;
10
- declare const date: <Value>(value: Value) => Date | Value;
11
11
  declare const _null: <Value>(value: Value) => null | Value;
12
12
  declare const _undefined: <Value>(value: Value) => undefined | Value;
13
13
 
package/dist/main.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- type Types = 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'object' | 'array' | 'date' | 'null' | 'undefined';
1
+ type Types = 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'date' | 'object' | 'array' | 'null' | 'undefined';
2
2
 
3
3
  declare const typof: (value: unknown) => Types[];
4
4
  declare const string: (value: unknown) => string;
5
5
  declare const number: (value: unknown) => number;
6
6
  declare const integer: (value: unknown) => number;
7
7
  declare const boolean: <Value>(value: Value) => boolean | Value;
8
+ declare const date: <Value>(value: Value) => Date | Value;
8
9
  declare const object: <Value>(value: Value) => object | Value;
9
10
  declare const array: <Value>(value: Value) => unknown[] | Value;
10
- declare const date: <Value>(value: Value) => Date | Value;
11
11
  declare const _null: <Value>(value: Value) => null | Value;
12
12
  declare const _undefined: <Value>(value: Value) => undefined | Value;
13
13
 
package/dist/main.js CHANGED
@@ -69,9 +69,9 @@ var typof = (value) => {
69
69
  } else types.push("float");
70
70
  }
71
71
  if (value === "true" || value === "false") types.push("boolean");
72
+ if (isISODate(value)) types.push("date");
72
73
  if (isObject(value) && !Array.isArray(JSON.parse(value))) types.push("object");
73
74
  if (isObject(value) && Array.isArray(JSON.parse(value))) types.push("array");
74
- if (isISODate(value)) types.push("date");
75
75
  if (value === "null") types.push("null");
76
76
  if (value === "undefined") types.push("undefined");
77
77
  } else if (typeof value === "number") {
@@ -112,6 +112,9 @@ var boolean = (value) => {
112
112
  } else return value;
113
113
  } else return value;
114
114
  };
115
+ var date = (value) => {
116
+ return typof(value).includes("date") ? new Date(value) : value;
117
+ };
115
118
  var object = (value) => {
116
119
  const types = typof(value);
117
120
  return types.includes("object") && types.includes("string") ? JSON.parse(value) : value;
@@ -120,9 +123,6 @@ var array = (value) => {
120
123
  const types = typof(value);
121
124
  return types.includes("array") && types.includes("string") ? JSON.parse(value) : value;
122
125
  };
123
- var date = (value) => {
124
- return typof(value).includes("date") ? new Date(value) : value;
125
- };
126
126
  var _null = (value) => {
127
127
  return typof(value).includes("null") ? null : value;
128
128
  };
package/dist/main.mjs CHANGED
@@ -34,9 +34,9 @@ var typof = (value) => {
34
34
  } else types.push("float");
35
35
  }
36
36
  if (value === "true" || value === "false") types.push("boolean");
37
+ if (isISODate(value)) types.push("date");
37
38
  if (isObject(value) && !Array.isArray(JSON.parse(value))) types.push("object");
38
39
  if (isObject(value) && Array.isArray(JSON.parse(value))) types.push("array");
39
- if (isISODate(value)) types.push("date");
40
40
  if (value === "null") types.push("null");
41
41
  if (value === "undefined") types.push("undefined");
42
42
  } else if (typeof value === "number") {
@@ -77,6 +77,9 @@ var boolean = (value) => {
77
77
  } else return value;
78
78
  } else return value;
79
79
  };
80
+ var date = (value) => {
81
+ return typof(value).includes("date") ? new Date(value) : value;
82
+ };
80
83
  var object = (value) => {
81
84
  const types = typof(value);
82
85
  return types.includes("object") && types.includes("string") ? JSON.parse(value) : value;
@@ -85,9 +88,6 @@ var array = (value) => {
85
88
  const types = typof(value);
86
89
  return types.includes("array") && types.includes("string") ? JSON.parse(value) : value;
87
90
  };
88
- var date = (value) => {
89
- return typof(value).includes("date") ? new Date(value) : value;
90
- };
91
91
  var _null = (value) => {
92
92
  return typof(value).includes("null") ? null : value;
93
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typof",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Infer types.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/keift/typof",