diff --git a/gulpfile.js b/gulpfile.js index 5f3d905..beff616 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -77,15 +77,15 @@ function replaceDocBlockInfo() { ) .pipe( replace( - /version: string = "([\w\d:\/\.\-]+)"/g, - `version: string = "${pkg.version}"` + /VERSION: string = "([\w\d:\/\.\-]+)"/g, + `VERSION: string = "${pkg.version}"` ) ) .pipe(gulp.dest("src/")); } function cleanCompile(cb) { - return del(["dist"], cb); + return del(["dist", "src/browser"], cb); } function compileCjs(cb) { @@ -125,17 +125,10 @@ function concatBrowserTS() { return gulp .src(["./src/languages/**/*.ts", "./src/parser/**/*.ts", "src/*.ts"]) .pipe(concat("shdate.ts")) - .pipe(replace(/export default (function|class)/g, "$1")) - .pipe(replace(/import [a-zA-Z_]* from [0-9a-zA-Z_/\.\"]*;/g, " ")) - .pipe(replace(/extends (Language)/g, "extends SHDate$1")) - .pipe(replace(/class ([a-z]{2,3}_[A-Z]{2})/g, "class SHDateLanguage_$1")) - .pipe(replace(/ ([a-z]{2,3}_[A-Z]{2})\./g, " SHDateLanguage_$1.")) - .pipe(replace(/ Language_([a-z]{2,3}_[A-Z]{2})/g, " SHDateLanguage_$1")) - .pipe(replace(/\((Languages)\)/g, "(SHDate$1)")) - .pipe(replace(/class (Language|Word)/g, "class SHDate$1")) - .pipe(replace(/(Language\.|Word\.)/g, "SHDate$1")) - .pipe(replace(/enum (Language)/g, "enum SHDate$1")) - .pipe(replace(/ Languages.([a-z]{2,3}_[A-Z]{2})/g, " SHDateLanguages.$1")) + .pipe(replace(/export (default)?/g, "")) + .pipe(replace(/import [a-zA-Z_,{ }]* from [0-9a-zA-Z_\/\.\"]*;/g, "")) + .pipe(replace(/(Languages?|Word)(\.)?/g, "SHDate$1$2")) + .pipe(replace(/ ([a-z]{2,3}_[A-Z]{2})(\.)?/g, " SHDateLanguage_$1$2")) .pipe(replace(/SH(Parser|Lexer|Token)/g, "SHDate$1")) .pipe(gulp.dest("src/browser")); } @@ -187,7 +180,7 @@ exports.default = gulp.task( ) ); -function cleanDev(cb) { +function cleanTest(cb) { return del(["dist/src", "dist/tests"], cb); } @@ -203,6 +196,20 @@ function compileTest(cb) { } gulp.task(compileTest); +function copyTestBrowser(cb) { + return gulp.src(["tests/browser/*"]).pipe(gulp.dest("dist/tests/browser")); +} +function installTestsBrowser(cb) { + return exec( + "(cd dist/tests/browser && npm i && npm test)", + function (err, stdout, stderr) { + // console.log(stdout); + // console.log(stderr); + cb(err); + } + ); +} + function copyTestCJS(cb) { return gulp.src(["tests/cjs/*"]).pipe(gulp.dest("dist/tests/cjs")); } @@ -216,6 +223,7 @@ function installTestsCJS(cb) { } ); } + function copyTestMJS(cb) { return gulp.src(["tests/mjs/*"]).pipe(gulp.dest("dist/tests/mjs")); } @@ -246,9 +254,10 @@ function installTestsPKGS(cb) { gulp.task( "test", gulp.series( - cleanDev, + cleanTest, compileTest, gulp.parallel( + gulp.series(copyTestBrowser, installTestsBrowser), gulp.series(copyTestCJS, installTestsCJS), gulp.series(copyTestMJS, installTestsMJS), gulp.series(copyTestPKG, installTestsPKGS) @@ -256,7 +265,7 @@ gulp.task( ) ); -gulp.task("testRelease", gulp.series(cleanDev, compileTest)); +gulp.task("testRelease", gulp.series(cleanTest, compileTest)); // buildUntilTests.displayName = 'clean:all'; // buildUntilTests.description = 'Build the project'; diff --git a/package.json b/package.json index 34500cd..999a0b8 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "watch": "tsc -w", "build": "gulp build", "test": "gulp test && mocha", - "test:release": "gulp testRelease && mocha", "dev:test": "nodemon --exec npm test", + "test:release": "gulp testRelease && mocha", "test:build": "gulp compileTest && node dist/tests/build-test.js > tests/build-test.log", "prepare": "husky install" }, @@ -127,13 +127,11 @@ "gulp-header": "^2.0.9", "gulp-rename": "^2.0.0", "gulp-replace": "^1.1.4", - "gulp-typescript": "^6.0.0-alpha.1", "gulp-uglify": "^3.0.2", "husky": "^8.0.3", "lint-staged": "^14.0.1", "mocha": "^10.2.0", "nodemon": "^3.0.1", - "npm-run-all": "^4.1.5", "prettier": "^3.0.3", "tslib": "^2.6.2", "typescript": "^5.2.2" diff --git a/src/base.ts b/src/base.ts index 8c21863..ccdf589 100644 --- a/src/base.ts +++ b/src/base.ts @@ -29,7 +29,7 @@ export default class SHDate { /** * version of SHDate */ - static VERSION: string = "2.1.05"; + static VERSION: string = "2.1.24"; /** * @type {number[]} days in month without leap year diff --git a/src/languages/i18n/fa_IR.ts b/src/languages/i18n/fa_IR.ts index c16e670..e64c935 100644 --- a/src/languages/i18n/fa_IR.ts +++ b/src/languages/i18n/fa_IR.ts @@ -37,7 +37,7 @@ export default class fa_IR { "ارديبهشت", "خرداد", "تير", - "امرداد", + "مرداد", "شهريور", "مهر", "آبان", @@ -52,7 +52,7 @@ export default class fa_IR { "ارد", "خرد", "تير", - "امر", + "مرد", "شهر", "مهر", "آبا", diff --git a/src/languages/language.ts b/src/languages/language.ts index 68ded71..520b0c1 100644 --- a/src/languages/language.ts +++ b/src/languages/language.ts @@ -10,7 +10,7 @@ import Language_ckb_IR from "./l10n/ckb_IR.js"; /** * list of supported languages */ -enum Languages { +export enum Languages { //i18n fa_IR = "fa_IR", en_US = "en_US", diff --git a/src/tools.ts b/src/tools.ts index e59b17f..c46fdb6 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -4,7 +4,7 @@ * @link http://git.akhi.ir/js/SHDate | https://github.com/md-akhi/SHDateTime-js#readme */ -import Language from "./languages/language.js"; +import Language, { Languages } from "./languages/language.js"; /** * Convert a number to Persian digit @@ -14,27 +14,30 @@ import Language from "./languages/language.js"; * @returns {string} The converted string. */ export function toNumber( - source: string, - destination: string | string[] = "FA", - comma: string = "," + source: string | number, + destination: string = "FA" + // comma: string = "," ): string { - const EN: string[] = Language.getClass("en_US").DIGIT; - const FA: string[] = Language.getClass("fa_IR").DIGIT; - switch (destination) { + const EN: string[] = Language.getClass(Languages.en_US).DIGIT; + const FA: string[] = Language.getClass(Languages.fa_IR).DIGIT; + let digits: string[]; + switch (destination.toUpperCase()) { case "FA": - destination = FA; + case "FA_IR": + digits = FA; break; case "EN": - destination = EN; + case "EN_US": + digits = EN; break; default: - destination = FA; + digits = FA; break; } EN.forEach((value, index) => { - source = source.toString().replace(value, destination[index]); + source = `${source}`.replace(value, digits[index]); }); // for (const [index, value] of EN.entries()) { // source = source.split(value).join(destination[index]); - return source; + return `${source}`; } diff --git a/tests/browser/index.html b/tests/browser/index.html index 1a86d3c..6423d1f 100644 --- a/tests/browser/index.html +++ b/tests/browser/index.html @@ -9,8 +9,9 @@ +