Skip to content

Commit

Permalink
chore: add missing commit files
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Feb 28, 2024
1 parent 28944c7 commit 72fa1db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions global/packages/core/src/utils/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ export type ConnectionString = {
password: string
};

const regex = /(?:(user|robot|client):\/\/)(?:(\w+)(?::(\w+))@)(.*)$/;

export function isConnectionString(input: string) : boolean {
return regex.test(input);
}

export function parseConnectionString(
input: string,
) : ConnectionString | undefined {
const match = input
.match(/(?:(user|robot|client):\/\/)(?:(\w+)(?::(\w+))@)(.*)$/);
const match = input.match(regex);

if (!match) {
return undefined;
Expand Down
7 changes: 6 additions & 1 deletion global/packages/core/test/utils/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
* view the LICENSE file that was distributed with this source code.
*/

import { parseConnectionString } from '../../src';
import { isConnectionString, parseConnectionString } from '../../src';

describe('src/utils/connection', () => {
it('should determine if it is a connection string', () => {
expect(isConnectionString('user://admin:start123@http://localhost/')).toBeTruthy();
expect(isConnectionString('http://localhost/')).toBeFalsy();
});

it('should parse user connection string', () => {
const parsed = parseConnectionString('user://admin:start123@http://localhost/');
expect(parsed.type).toEqual('user');
Expand Down

0 comments on commit 72fa1db

Please sign in to comment.