Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat!: upgrade node and rewrite approach #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

31 changes: 0 additions & 31 deletions .eslintrc.json

This file was deleted.

16 changes: 8 additions & 8 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm clean-install
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm clean-install
Expand All @@ -60,7 +60,7 @@ jobs:
- codelint
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x, 24.x]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -85,19 +85,19 @@ jobs:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use Node.js 20.x
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install deps
run: npm ci
- name: Test code
run: npm run test:coverage --silent -- npm run test:workflow
run: npm run test:coverage
- name: Report coverage
run: |
echo "# Code coverage" >> $GITHUB_STEP_SUMMARY
npx nyc report | sed --expression='1d;$d' >> $GITHUB_STEP_SUMMARY
npx c8 report | sed --expression='1d;$d' >> $GITHUB_STEP_SUMMARY
if: ${{ !cancelled() }}
release:
name: Release
Expand All @@ -121,7 +121,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
run: npm clean-install
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
1 change: 0 additions & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"include": ["src"],
"all": true
}
91 changes: 72 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,108 @@ The library also provides the ability to parse SQL Connection Strings.

## Parsing connection strings

The library comes with a generic connection string parser that will parse through valid connections strings and produce a key-value
map of the entries in that string. No additional validation is performed.
The library comes with a generic connection string parser that will parse through valid connection strings and produce a key-value
readonly Map of the entries in that string. No additional validation is performed.

```js
const { parseConnectionString } = require('@tediousjs/connection-string');
const { parse } = require('@tediousjs/connection-string');

const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';

const parsed = parseConnectionString(connectionString);
const parsed = parse(connectionString);

console.log(parsed);
```

Output to the console will be:

```json
{
"User id": "user",
"password": "password",
"initial catalog": "AdventureWorks",
"server": "MySqlServer"
```
Map(4) {
'user id' => 'user',
'password' => 'password',
'initial catalog' => 'AdventureWorks',
'server' => 'MySqlServer'
}
```

## Parsing SQL connection strings

There is a specific helper for parsing SQL connection strings and this comes with a value normaliser and validation. It also has an
option to "canonicalise" the properties. For many properties in an SQL connections string, there are aliases, when canonical properties
are being used, these aliases will be returned as the canonical property.
SQL connection strings can be parsed to a JSON object using the `toSchema()` method and the provided
`MSSQL_SCHEMA`.

```js
const { parseSqlConnectionString } = require('@tediousjs/connection-string');
const { parse, MSSQL_SCHEMA } = require('@tediousjs/connection-string');

const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';

const parsed = parseSqlConnectionString(connectionString, true);
const parsed = parse(connectionString);

console.log(parsed);
console.log(parsed.toSchema(MSSQL_SCHEMA));
```

Output to console will be:

```json
{
"user id": "user",
"password": "password",
"data source": "MySqlServer",
"initial catalog": "AdventureWorks",
"data source": "MySqlServer"
"password": "password",
"user id":"user"
}
```

NB: The `Server` property from the connection string has been re-written to the value `Data Source`

## Custom schemas

If you need to parse a connection string into a custom schema, the format is as follows:

```ts
import { parse } from '@tediousjs/connection-string';

// a keyed map of name => config
const schema = {
'a string': {
type: 'string',
default: 'a default value',
aliases: ['other', 'allowed', 'names'],
},
'a number': {
type: 'number',
default: 123,
},
'a boolean': {
type: 'boolean',
default: true,
},
};

const parsed = parse('a string=test;a number=987;a boolean=false;other value=missing');
console.log(parsed.toSchema(schema));
```

Output:

```json
{
"a string": "test",
"a number": 987,
"a boolean": false
}
```

## Accessing properties

The parsed connection string object is a readonly `Map` with an overloadded `get()` method allowing
coercion of the value:

```ts
import { parse } from '@tediousjs/connection-string';
const parsed = parse('a string=test;a number=987;a boolean=false;other value=missing');
// all values are strings by default
console.log(parsed.get('a number')); // "987"
// values can be coersed to an expected type
console.log(parsed.get('a number', 'number')); // 987
// coersion will be permissive in its type coersion
console.log(parsed.get('a number', 'boolean')); // true
```
37 changes: 37 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import eslint from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import tslint from 'typescript-eslint';

export default tslint.config(
{
plugins: {
'@stylistic': stylistic,
},
},
eslint.configs.recommended,
...tslint.configs.recommendedTypeChecked,
stylistic.configs.customize({
indent: 4,
quotes: 'single',
semi: true,
braceStyle: '1tbs',
arrowParens: true,
quoteProps: 'consistent-as-needed',
commaDangle: 'only-multiline',
}),
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ['./test/**'],
rules: {
'@typescript-eslint/no-floating-promises': ['off'],
'@typescript-eslint/no-unsafe-assignment': ['off'],
},
},
);
Loading