@webitel/ui-sdk 23.9.5 → 23.9.6

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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "23.09.5",
3
+ "version": "23.09.6",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -0,0 +1,7 @@
1
+ Validator for WebSocket URL string
2
+ ```javascript
3
+ import websocketValidator from '@webitel/ui-sdk/src/validators/websocketValidator/websocketValidator';
4
+
5
+ websocketValidator('wss://example.com') // true
6
+ websocketValidator('krokoziabra') // false
7
+ ```
@@ -0,0 +1,28 @@
1
+ import websocketValidator from '../websocketValidator';
2
+
3
+ describe('websocketValidator', () => {
4
+ it('truthy case 1: localhost ws', () => {
5
+ expect(websocketValidator('ws://localhost:8080')).toBe(true);
6
+ });
7
+ it('truthy case 2: localhost wss', () => {
8
+ expect(websocketValidator('wss://localhost:8080')).toBe(true);
9
+ });
10
+ it('truthy case 3: ip ws', () => {
11
+ expect(websocketValidator('ws://10.10.10.10:8080')).toBe(true);
12
+ });
13
+ it('truthy case 4: dns name', () => {
14
+ expect(websocketValidator('wss://example.com')).toBe(true);
15
+ });
16
+ it('truthy case 5: dns name', () => {
17
+ expect(websocketValidator('wss://example')).toBe(true);
18
+ });
19
+ it('truthy case 6: dns name', () => {
20
+ expect(websocketValidator('wss://example.com/ws')).toBe(true);
21
+ });
22
+ it('truthy case 7: dns name', () => {
23
+ expect(websocketValidator('wss://socket.socket.com/v3/channel_123?api_key=123')).toBe(true);
24
+ });
25
+ it('falsy case 1: empty string', () => {
26
+ expect(websocketValidator('')).toBe(false);
27
+ });
28
+ });
@@ -0,0 +1,9 @@
1
+ // That's strange but i haven't found any npm package with websocket validator
2
+ export default (value) => {
3
+ try {
4
+ const url = new URL(value);
5
+ return (/^(wss?)/i).test(url.protocol);
6
+ } catch (e) {
7
+ return false;
8
+ }
9
+ };
Binary file