@gkucmierz/utils 1.1.5 → 1.1.7

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/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@gkucmierz/utils",
9
- "version": "1.1.5",
9
+ "version": "1.1.7",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "husky": "^8.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "src/main.mjs",
6
6
  "scripts": {
@@ -2,15 +2,74 @@
2
2
  import { getType } from '../src/get-type.mjs';
3
3
 
4
4
  describe('get-type', () => {
5
- it('getType', function() {
5
+
6
+ it('should undefined', () => {
6
7
  expect(getType(undefined)).toEqual('undefined');
8
+ });
9
+
10
+ it('should null', () => {
7
11
  expect(getType(null)).toEqual('null');
12
+ });
13
+
14
+ it('should boolean', () => {
8
15
  expect(getType(true)).toEqual('boolean');
16
+ expect(getType(false)).toEqual('boolean');
17
+ expect(getType(new Boolean)).toEqual('boolean');
18
+ });
19
+
20
+ it('should number', () => {
9
21
  expect(getType(1)).toEqual('number');
22
+ expect(getType(1e3)).toEqual('number');
23
+ expect(getType(1_000)).toEqual('number');
24
+ expect(getType(NaN)).toEqual('number');
25
+ expect(getType(Infinity)).toEqual('number');
26
+ });
27
+
28
+ it('should bigint', () => {
10
29
  expect(getType(1n)).toEqual('bigint');
11
- expect(getType('1')).toEqual('string');
30
+ });
31
+
32
+ it('should string', () => {
33
+ expect(getType('hello')).toEqual('string');
34
+ expect(getType(new String)).toEqual('string');
35
+ });
36
+
37
+ it('should Symbol', () => {
12
38
  expect(getType(Symbol())).toEqual('symbol');
39
+ });
40
+
41
+ it('should function', () => {
13
42
  expect(getType(() => 0)).toEqual('function');
43
+ expect(getType(function() { })).toEqual('function');
44
+ expect(getType(new Function)).toEqual('function');
45
+ });
46
+
47
+ it('should generatorfunction', () => {
48
+ expect(getType(function*() { })).toEqual('generatorfunction');
49
+ });
50
+
51
+ it('should date', () => {
52
+ expect(getType(new Date)).toEqual('date');
53
+ });
54
+
55
+ it('should array', () => {
56
+ expect(getType([])).toEqual('array');
57
+ expect(getType(new Array)).toEqual('array');
58
+ });
59
+
60
+ it('should object', () => {
14
61
  expect(getType({})).toEqual('object');
62
+ expect(getType(new Object)).toEqual('object');
63
+ expect(getType(new Proxy({}, {}))).toEqual('object');
64
+ });
65
+
66
+ it('should map', () => {
67
+ expect(getType(new Map)).toEqual('map');
68
+ expect(getType(new WeakMap)).toEqual('weakmap');
69
+ });
70
+
71
+ it('should set', () => {
72
+ expect(getType(new Set)).toEqual('set');
73
+ expect(getType(new WeakSet)).toEqual('weakset');
15
74
  });
16
75
  });
package/src/main.mjs CHANGED
@@ -1,2 +1,25 @@
1
1
 
2
- console.log('hello world!');
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ const files = fs.readdirSync(__dirname);
10
+
11
+ const utilsFiles = files
12
+ .filter(name => name.match(/\.mjs$/))
13
+ .filter(name => name !== 'main.mjs');
14
+
15
+ const methods = {};
16
+
17
+ for (const file of utilsFiles) {
18
+ const obj = await import(`./${file}`);
19
+ Object.keys(obj).map(key => {
20
+ if (key in methods) throw Error('Duplicate method name');
21
+ methods[key] = obj[key];
22
+ });
23
+ };
24
+
25
+ export default methods;