Skip to content

Commit

Permalink
Merge pull request #171 from webitel/feature/ws-validator
Browse files Browse the repository at this point in the history
23.12.31: ws validator [WTEL-3986]
  • Loading branch information
dlohvinov authored Oct 24, 2023
2 parents 8d5489f + 62f8645 commit ad453a8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "23.12.30",
"version": "23.12.31",
"private": false,
"scripts": {
"build": "vue-cli-service build --target lib --name ui-sdk ./src/install.js",
Expand Down
7 changes: 7 additions & 0 deletions src/validators/websocketValidator/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Validator for WebSocket URL string
```javascript
import websocketValidator from '@webitel/ui-sdk/src/validators/websocketValidator/websocketValidator';

websocketValidator('wss://example.com') // true
websocketValidator('krokoziabra') // false
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import websocketValidator from '../websocketValidator';

describe('websocketValidator', () => {
it('truthy case 1: localhost ws', () => {
expect(websocketValidator('ws://localhost:8080')).toBe(true);
});
it('truthy case 2: localhost wss', () => {
expect(websocketValidator('wss://localhost:8080')).toBe(true);
});
it('truthy case 3: ip ws', () => {
expect(websocketValidator('ws://10.10.10.10:8080')).toBe(true);
});
it('truthy case 4: dns name', () => {
expect(websocketValidator('wss://example.com')).toBe(true);
});
it('truthy case 5: dns name', () => {
expect(websocketValidator('wss://example.com/ws')).toBe(true);
});
it('truthy case 6: dns name', () => {
expect(websocketValidator('wss://socket.socket.com/v3/channel_123?api_key=123')).toBe(true);
});
it('falsy case 1: empty string', () => {
expect(websocketValidator('')).toBe(false);
});
it('falsy case 2: ws+ws', () => {
expect(websocketValidator('wss://example.com/wswss://example.com/ws')).toBe(false);
});
});
2 changes: 2 additions & 0 deletions src/validators/websocketValidator/websocketValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// That's strange but i haven't found any npm package with websocket validator
export default (value) => (/^(wss?:\/\/)([0-9]{1,3}(?:\.[0-9]{1,3}){3}|[^\/]+)(\:[0-9]{1,5})?(.*)$/i).test(value);
22 changes: 15 additions & 7 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ module.exports = {
// StyleGuideRenderer: path.join(__dirname, 'styleguide/components/style-guide'),
LogoRenderer: path.join(__dirname, 'styleguide/components/logo'),
},
// defaultExample: true,
// sections: [
// {
// name: 'First Section',
// components: 'src/components/**/[A-Z]*.vue'
// }
// ],
sections: [
{
name: 'Components',
components: 'src/components/**/*.vue',
},
{
name: 'Validators',
sections: [
{
name: 'Websocket Validator',
content: 'src/validators/websocketValidator/Readme.md',
},
],
},
],
// eslint-disable-next-line global-require,import/extensions
// webpackConfig: { ...output /* Custom config options */ },
// webpackConfig: {
Expand Down

0 comments on commit ad453a8

Please sign in to comment.