Skip to content

Commit

Permalink
refactor: setup project for TypeScript (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadjih-bencheikh18 committed Mar 24, 2024
1 parent ae3eafb commit 23e5f7f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends: cheminfo
extends: cheminfo-typescript
env:
jest: true
node: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
with:
node-version-matrix: '[14, 16, 18]'
lint-check-types: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ dist
.DS_Store

lib
lib-esm
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
presets: ['@babel/preset-typescript'],
plugins: ['@babel/plugin-transform-modules-commonjs'],
};
31 changes: 18 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
"name": "dynamic-typing",
"version": "1.0.0",
"description": "Dynamically type a string",
"main": "lib/index.js",
"module": "src/index.js",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"files": [
"src",
"lib",
"src"
"lib-esm"
],
"scripts": {
"build": "cheminfo-build --entry src/index.js --root DynamicTyping",
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "rollup -c",
"prepack": "npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-coverage && npm run eslint && npm run prettier",
"test": "npm run test-coverage && npm run eslint && npm run prettier && npm run check-types",
"test-coverage": "jest --coverage",
"test-only": "jest"
"test-only": "jest",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json"
},
"repository": {
"type": "git",
Expand All @@ -30,17 +37,15 @@
"url": "https://github.com/cheminfo/dynamic-typing/issues"
},
"homepage": "https://github.com/cheminfo/dynamic-typing#readme",
"jest": {
"testEnvironment": "node"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@types/jest": "^29.2.2",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.12",
"cheminfo-build": "^1.1.11",
"eslint": "^8.27.0",
"eslint-config-cheminfo": "^8.1.3",
"eslint-config-cheminfo-typescript": "^12.2.0",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"rollup": "^3.3.0"
"typescript": "^5.4.2"
}
}
7 changes: 0 additions & 7 deletions rollup.config.js

This file was deleted.

File renamed without changes.
File renamed without changes.
11 changes: 3 additions & 8 deletions src/parseString.js → src/parseString.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/**
* Dynamically type a string
* @param {string} value String to dynamically type
* @returns {boolean|string|number}
*/
export function parseString(value) {
export function parseString(value: string): boolean | string | number {
if (value.length === 4 || value.length === 5) {
let lowercase = value.toLowerCase();
const lowercase = value.toLowerCase();

if (lowercase === 'true') return true;
if (lowercase === 'false') return false;
}
let number = Number(value);
const number = Number(value);
if (number === 0 && !value.includes('0')) {
return value;
}
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"declarationMap": true
},
"exclude": ["./src/**/__tests__"]
}
7 changes: 7 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.cjs.json",
"compilerOptions": {
"module": "es2020",
"outDir": "lib-esm"
}
}
12 changes: 12 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2020"
},
"include": ["./src/**/*"]
}

0 comments on commit 23e5f7f

Please sign in to comment.