Skip to content

Commit

Permalink
feat(core): migrate to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
SMAKSS committed Nov 4, 2023
1 parent faf79ca commit 681a19c
Show file tree
Hide file tree
Showing 22 changed files with 2,759 additions and 70 deletions.
11 changes: 11 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build files
dist

#prettier config
prettier.config.cjs

# lint-staged config
lint-staged.config.cjs

# commitlint config
commitlint.config.cjs
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"env": {
"browser": true,
"es6": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
// Specifying Parser
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"tsconfigRootDir": ".",
"project": ["./tsconfig.json"]
},
// Configuring third-party plugins
"plugins": ["@typescript-eslint"],
// Resolve imports
"rules": {
"linebreak-style": "off",
// Disallow the `any` type.
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true,
"types": {
"{}": false
}
}
],
"react-hooks/exhaustive-deps": "off",
// Enforce the use of the shorthand syntax.
"object-shorthand": "error",
"no-console": "warn"
}
}
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
Thank you for contributing by opening an issue! Please take a moment to review our Code of Conduct (found in the CODE_OF_CONDUCT.md file) to keep the community approachable and respectful.
For bug reports, please fill out the information below to help us understand the issue and address it in a timely manner. We value your feedback and contributions.
-->

# Brief Description
<!-- A brief description of the issue.-->

## Environment

- `@smakss/convert-numbers` version:
- Framework version (`react`, `react-native`, `Next.js`, `Remix` etc.`):
- `node.js` version:
- `npm` (or `yarn`) version:

## Code Snippet
<!-- Please provide any relevant code snippets or examples here -->

```javascript
// Your code here
```

## Steps to Reproduce
<!-- What steps did we need to take to encounter the problem? -->

## Expected Behavior
<!-- What you expected to happen -->

## Actual Behavior
<!-- What actually happened. Include the full error message/screenshots/anything that might help understanding the issue -->

## Reproduction Repository
<!--
If possible, please provide a repository link where the issue can be reproduced. A minimal test case would be greatly appreciated and can significantly speed up the resolution process.
-->

## Problem Description
<!-- A clear and concise description of what the problem is. Include any additional context that might help us understand the issue. -->

## Suggested Solution
<!-- If you have any suggestion on how to fix the issue please provide it here. If not, just leave this section blank. -->
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: PR Checks

on:
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Print head and base refs
run: |
echo "Head ref: ${{ github.head_ref }}"
echo "Base ref: ${{ github.base_ref }}"
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-node-18-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-18-yarn-
- name: Install dependencies
run: yarn install

- name: Type check
run: yarn typecheck

- name: Check code quality
run: |
yarn lint
yarn format:check
yarn run --if-present generate
- name: Security Audit
run: yarn audit --level moderate || true
continue-on-error: true

- name: Security Audit Summary
if: success() || failure()
run: yarn audit --summary

- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: ./build/

- name: Error handling
if: failure()
run: echo "CI failed. Please check the logs."
46 changes: 39 additions & 7 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "@smakss/convert-numbers"
name: "@smakss/react-scroll-direction"

on:
release:
Expand All @@ -11,32 +11,64 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: yarn
- run: yarn generate
- uses: actions/upload-artifact@v3
with:
name: built-package
path: |
./path-to-your-build-folder
package.json
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: built-package
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: https://registry.npmjs.org/
scope: "@smakss"
- run: npm publish
- run: yarn install
- run: yarn generate
- run: |
if grep -q "beta" package.json; then
echo "Publishing Beta to npm"
npm publish --tag beta
else
echo "Publishing Release to npm"
npm publish
fi
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
publish-gpr:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: built-package
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: https://npm.pkg.github.com/
scope: "@smakss"
- run: npm publish
- run: yarn install
- run: yarn generate
- run: |
if grep -q "beta" package.json; then
echo "Publishing Beta to GitHub Package Registry"
npm publish --tag beta
else
echo "Publishing Release to GitHub Package Registry"
npm publish
fi
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Logs
logs
*.log
yarn-debug.log*
yarn-error.log*

# Dependency directories
node_modules

# Generate output
dist

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit ${1}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package.json
.cache
.shadowenv.d
.vscode
build
dist
node_modules
public
.github
tmp
*.yml
File renamed without changes.
File renamed without changes.
54 changes: 27 additions & 27 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
# Convert numbers
# Convert Numbers

![npm](https://img.shields.io/npm/v/@smakss/convert-numbers) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@smakss/convert-numbers) ![NPM](https://img.shields.io/npm/l/@smakss/convert-numbers) ![npm](https://img.shields.io/npm/dt/@smakss/convert-numbers) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@smakss/convert-numbers)
![npm](https://img.shields.io/npm/v/@smakss/convert-numbers) ![NPM](https://img.shields.io/npm/l/@smakss/convert-numbers) ![npm](https://img.shields.io/npm/dt/@smakss/convert-numbers) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@smakss/convert-numbers)

Due to keeping consistency in our data transfer with API's we need to make sure digits or numbers entered by user inputs have always transferred by English. Since users could always fill data with different keyboard settings we need to make sure that we don't send Arabic or Persian numbers to our database. So to avoid such an inconsistency we should always translate our numbers or prevent a user from entering unwanted data. Convert numbers created for this cause to make sure every digit input is in standard format of it.
Convert Numbers is a utility package that helps ensure consistency in data transfer by converting Arabic and Persian numerals to English numerals. This is particularly useful when user inputs can come from different keyboard settings, and there's a need to standardize all digits to English format before sending data to a database or processing it further.

## Demo

You can check the [working demo](https://runkit.com/smakss/convert-numbers) in runkit.
You can check the [working demo](https://runkit.com/smakss/convert-numbers) on RunKit.

or
Or

[![View @smakss/convert-numbers](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/smakss-convert-numbers-bstmfj?fontsize=14&hidenavigation=1&theme=dark)

## How it works?
## Installation

To install it you can simply do the following command:
To install the package, you can use npm or yarn with the following commands:

```bash
npm i @smakss/convert-numbers
or
# or
yarn add @smakss/convert-numbers
```

to include it with common js module you should do this:
## Usage

```js
var ConvertNumbers = require("@smakss/convert-numbers");
```
Import the `convertNumbers` function into your project using CommonJS or ECMAScript modules:

and to include it with ECMAscript module you can simply do this one:
CommonJS:

```js
import ConvertNumbers from "@smakss/convert-numbers";
const ConvertNumbers = require('@smakss/convert-numbers');
```

then to use it within your application you can do it just like this:
ECMAScript Modules:

```js
ConvertNumbers();

// Result: undefined
// If you don't provide any input it will return undefined.
import ConvertNumbers from '@smakss/convert-numbers';
```

Then, use the function as follows:

```js
ConvertNumbers("۱۲۳۴۵۶۷۸۹۰");
// Returns '1234567890' for Persian numbers
console.log(ConvertNumbers('۱۲۳۴۵۶۷۸۹۰'));

// Result: '1234567890'
// Returns '1234567890' for Arabic numbers
console.log(ConvertNumbers('١٢٣٤٥٦٧٨٩٠'));

// Returns "" for no input
console.log(ConvertNumbers());
```

```js
ConvertNumbers("١٢٣٤٥٦٧٨٩٠");
## Documentation

// Result: '1234567890'
```
For more detailed examples and function usage, please refer to the JSDoc comments within the code.

## Contributing

Interested in making contributions to this project? Please see [CONTRIBUTING.md](https://github.com/SMAKSS/convert-numbers/blob/master/.github/CONTRIBUTING.md) for guidelines and details.
Contributions to the project are welcome! Please refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.

## Code of Conduct

We value and prioritize the well-being of all our contributors and users. To ensure that this project remains a welcoming space for everyone, please refer to our [Code of Conduct](https://github.com/SMAKSS/convert-numbers/blob/master/.github/CODE_OF_CONDUCT.md).
To maintain a welcoming and positive community, please see our [Code of Conduct](./CODE_OF_CONDUCT.md).
3 changes: 3 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};
13 changes: 0 additions & 13 deletions index.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions index.mjs

This file was deleted.

4 changes: 4 additions & 0 deletions lint-staged.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
"*.+(js|ts)": ["yarn lint", () => "yarn typecheck"],
"*.+(js|json|yml|yaml|ts|md)": ["yarn format"],
};
Loading

0 comments on commit 681a19c

Please sign in to comment.