-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d5aeb37
Showing
11 changed files
with
3,778 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
coverage | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
|
||
### 1.0.0 (2023-01-04) | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 - Dominik Opyd (Oritwoen) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<h1 align='center'>nordi</h1> | ||
|
||
<p align="center"> | ||
<a href="https://www.npmjs.com/package/nordi" target="_blank"><img src="https://img.shields.io/npm/v/nordi?style=flat&colorA=130f40&colorB=474787" alt="npm version"></a> | ||
<a href="https://www.npmjs.com/package/nordi" target="_blank"><img src="https://img.shields.io/bundlephobia/min/nordi?style=flat&colorA=130f40&colorB=474787" alt="npm size"></a> | ||
<a href="https://www.npmjs.com/package/nordi" target="_blank"><img src="https://img.shields.io/npm/dm/nordi?flat&colorA=130f40&colorB=474787" alt="npm downloads"></a> | ||
<a href="https://github.com/oritwoen/nordi" target="_blank"><img src="https://img.shields.io/github/stars/oritwoen/nordi?flat&colorA=130f40&colorB=474787" lt="github stars"></a> | ||
</p> | ||
|
||
<p align="center"> | ||
Normalize data with interfaces. | ||
</p> | ||
|
||
## Why? | ||
|
||
In many projects where it is necessary to use different APIs for the same purpose, there is a huge problem with standardization. | ||
|
||
It is always a waste of time and almost always writing new functions and data normalization separately for each project. | ||
|
||
What if there was a simple function that normalizes data according to a predetermined pattern? – it was on the basis of this thought that `nordi` was created. | ||
|
||
|
||
## Install | ||
|
||
```bash | ||
npm install --save nordi | ||
|
||
# Using pnpm | ||
pnpm add nordi | ||
|
||
# Using yarn | ||
yarn add nordi | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
### 1. Define Interface | ||
|
||
To normalize data, you need to create an interface/schema beforehand. | ||
|
||
The principle of operation is very simple. `catch` grabs the appropriate variable from the object and `transform` converts it to the selected format. | ||
|
||
```ts | ||
const blockInterface = { | ||
hash: { | ||
catch: ['hash', 'blockhash'], | ||
transform: (value: any) => String(value) | ||
}, | ||
|
||
number: { | ||
catch: ['height', 'number', 'blockHeight'], | ||
transform: (value: any) => Number(value) | ||
}, | ||
} | ||
``` | ||
|
||
### 2. Prepare a dataset | ||
|
||
Of course, different data sets are required to normalize different data. | ||
|
||
For example, I used blocks of various cryptocurrencies here. | ||
|
||
```ts | ||
const solanaBlock = { | ||
"blockhash": "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZAMdL4VZHirAn", | ||
"blockHeight": 0 | ||
} | ||
|
||
const bitcoinBlock = { | ||
"hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", | ||
"height": 0 | ||
} | ||
|
||
const ethereumBlock = { | ||
"hash": "0x0000000000000000000000000000000000000000", | ||
"number": 0, | ||
} | ||
``` | ||
|
||
### 3. Normalization | ||
|
||
Of course, different data sets are required to normalize different data. | ||
|
||
For example, I used blocks of various cryptocurrencies here. | ||
|
||
```ts | ||
const { useNormalizedData } from 'nordi' | ||
|
||
const normalizedSolanaBlock = useNormalizedData(blockInterface, solanaBlock) | ||
const normalizedBitcoinBlock = useNormalizedData(blockInterface, bitcoinBlock) | ||
const normalizedEthereumBlock = useNormalizedData(blockInterface, ethereumBlock) | ||
|
||
console.log(normalizedSolanaBlock) | ||
|
||
//{ | ||
// hash: "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZAMdL4VZHirAn" | ||
// number: 0 | ||
//} | ||
``` | ||
|
||
## License | ||
|
||
MIT License © 2023 [Dominik Opyd](https://github.com/oritwoen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "nordi", | ||
"version": "1.0.0", | ||
"description": "Normalize data with interfaces.", | ||
"repository": "oritwoen/nordi", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"dev": "vitest dev", | ||
"lint": "eslint --ext .ts,.js,.mjs,.cjs .", | ||
"test": "pnpm lint && vitest run --coverage", | ||
"build": "unbuild", | ||
"prepack": "unbuild", | ||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish" | ||
}, | ||
"devDependencies": { | ||
"vitest": "0.26.3", | ||
"eslint": "8.31.0", | ||
"unbuild": "1.0.2", | ||
"typescript": "4.9.4", | ||
"standard-version": "9.5.0", | ||
"@vitest/coverage-c8": "0.26.3" | ||
}, | ||
"packageManager": "pnpm@7.22.0" | ||
} |
Oops, something went wrong.