@rsdk/common 3.5.0 → 4.0.0-next.3
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/CHANGELOG.md +14 -0
- package/dist/functions/misc.js +1 -1
- package/dist/functions/misc.js.map +1 -1
- package/package.json +5 -2
- package/src/functions/misc.spec.ts +56 -0
- package/src/functions/misc.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.0-next.3](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.2...v4.0.0-next.3) (2023-11-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* common: Added tests for the isRecord method ([02dc7ce](https://github.com/R-Vision/rsdk/commit/02dc7ce2a8edaac8bec9e63e4200d55a4987ced5))
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* lint ([a16e4e9](https://github.com/R-Vision/rsdk/commit/a16e4e91b77474226209a9ac15dcfa4abe724283))
|
|
15
|
+
|
|
16
|
+
## [4.0.0-next.2](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.1...v4.0.0-next.2) (2023-11-10)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @rsdk/common
|
|
19
|
+
|
|
6
20
|
## [3.5.0](https://github.com/R-Vision/rsdk/compare/v3.5.0-next.9...v3.5.0) (2023-10-03)
|
|
7
21
|
|
|
8
22
|
**Note:** Version bump only for package @rsdk/common
|
package/dist/functions/misc.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.noop = exports.isOneOf = exports.hasKey = exports.isUndefined = exports.
|
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
|
|
15
15
|
const unreachable = (_value) => { };
|
|
16
16
|
exports.unreachable = unreachable;
|
|
17
|
-
const isRecord = (x) =>
|
|
17
|
+
const isRecord = (x) => !!x && x.constructor === Object;
|
|
18
18
|
exports.isRecord = isRecord;
|
|
19
19
|
const isUndefined = (value) => value === undefined;
|
|
20
20
|
exports.isUndefined = isUndefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/functions/misc.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;GASG;AACH,mGAAmG;AAC5F,MAAM,WAAW,GAAG,CAAC,MAAa,EAAO,EAAE,GAAE,CAAC,CAAC;AAAzC,QAAA,WAAW,eAA8B;AAE/C,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAgC,EAAE,CACnE,
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/functions/misc.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;GASG;AACH,mGAAmG;AAC5F,MAAM,WAAW,GAAG,CAAC,MAAa,EAAO,EAAE,GAAE,CAAC,CAAC;AAAzC,QAAA,WAAW,eAA8B;AAE/C,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAgC,EAAE,CACnE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC;AADrB,QAAA,QAAQ,YACa;AAE3B,MAAM,WAAW,GAAG,CAAI,KAAoB,EAAc,EAAE,CACjE,KAAK,KAAK,SAAS,CAAC;AADT,QAAA,WAAW,eACF;AAEf,MAAM,MAAM,GAAG,CAAmB,GAAM,EAAE,GAAY,EAAW,EAAE,CACxE,GAAG,IAAI,GAAG,CAAC;AADA,QAAA,MAAM,UACN;AAEN,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,KAAoB,EAAW,EAAE,CACvE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC;AADjC,QAAA,OAAO,WAC0B;AAE9C,gEAAgE;AACzD,MAAM,IAAI,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AAAtB,QAAA,IAAI,QAAkB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-next.3",
|
|
4
4
|
"description": "Useful common classes, functions and types",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,5 +13,8 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"prepublishOnly": "npm run build"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"rxjs": "^7.8.1"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "313c39a379ea9ace9d94939223a53c46c12d77f9"
|
|
17
20
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-array-constructor */
|
|
2
|
+
/* eslint-disable unicorn/new-for-builtins */
|
|
3
|
+
/* eslint-disable prettier/prettier */
|
|
4
|
+
|
|
5
|
+
import { isRecord } from './misc';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable sort-keys */
|
|
8
|
+
describe('misc', () => {
|
|
9
|
+
describe('isRecord', () => {
|
|
10
|
+
interface Case {
|
|
11
|
+
name: string;
|
|
12
|
+
input: any;
|
|
13
|
+
success: boolean;
|
|
14
|
+
output: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const tt: Case[] = [
|
|
18
|
+
// Positive
|
|
19
|
+
{ name: 'Correct object (literal)', input: {}, success: true, output: true },
|
|
20
|
+
{ name: 'Correct object (Object())', input: new Object(), success: true, output: true },
|
|
21
|
+
{ name: 'Correct object (new Object())', input: new Object(), success: true, output: true },
|
|
22
|
+
{ name: 'Correct object (Object.create())', input: Object.create({}), success: true, output: true },
|
|
23
|
+
{ name: 'Correct object (Object.assign())', input: Object.assign({}, {}), success: true, output: true },
|
|
24
|
+
|
|
25
|
+
{ name: 'Function (declarative)', input: function t(): void {}, success: true, output: false },
|
|
26
|
+
{ name: 'new Function() instance', input: new Function(), success: true, output: false },
|
|
27
|
+
{ name: 'Function constructor', input: new (function t() {})(), success: true, output: false },
|
|
28
|
+
{ name: 'Class', input: class T {}, success: true, output: false },
|
|
29
|
+
{ name: 'Class constructor', input: new (class T{})(), success: true, output: false },
|
|
30
|
+
{ name: 'Array (literal)', input: [], success: true, output: false },
|
|
31
|
+
{ name: 'Array() instance', input: Array(), success: true, output: false },
|
|
32
|
+
{ name: 'new Array() instance', input: new Array(), success: true, output: false },
|
|
33
|
+
{ name: 'The Map (new Map())', input: new Map(), success: true, output: false },
|
|
34
|
+
{ name: 'The Set (new Set())', input: new Set(), success: true, output: false },
|
|
35
|
+
{ name: 'Date object', input: new Date(), success: true, output: false },
|
|
36
|
+
{ name: 'String oject', input: new String('str'), success: true, output: false },
|
|
37
|
+
{ name: 'Number object', input: new Number(1), success: true, output: false },
|
|
38
|
+
{ name: 'Boolean object', input: new Boolean(true), success: true, output: false },
|
|
39
|
+
{ name: 'BigInt', input: BigInt(999999999999), success: true, output: false },
|
|
40
|
+
{ name: 'Symbol', input: Symbol(), success: true, output: false },
|
|
41
|
+
{ name: 'null', input: null, success: true, output: false },
|
|
42
|
+
{ name: 'undefined', input: undefined, success: true, output: false },
|
|
43
|
+
{ name: 'true', input: true, success: true, output: false },
|
|
44
|
+
{ name: 'number', input: 12, success: true, output: false },
|
|
45
|
+
{ name: 'string', input: 'str', success: true, output: false },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
for (const { name, input, success, output } of tt) {
|
|
49
|
+
if (success) {
|
|
50
|
+
it(name, () => expect(isRecord(input)).toBe(output));
|
|
51
|
+
} else {
|
|
52
|
+
it(name, () => expect(() => isRecord(input)).toThrow());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
package/src/functions/misc.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { Constructor } from '../types';
|
|
|
14
14
|
export const unreachable = (_value: never): any => {};
|
|
15
15
|
|
|
16
16
|
export const isRecord = (x: unknown): x is Record<string, unknown> =>
|
|
17
|
-
|
|
17
|
+
!!x && x.constructor === Object;
|
|
18
18
|
|
|
19
19
|
export const isUndefined = <T>(value: T | undefined): value is T =>
|
|
20
20
|
value === undefined;
|