├── LICENSE ├── README.md ├── calc.jpg └── source ├── app.js ├── build.cmd ├── calc.js └── jsc.cmd /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 DosX 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JS-Calculator 2 | Console Windows-calculator written with Microsoft JScript .NET 3 | 4 | # How to build? 5 | You don't need to download or install anything to build. Just run "build.cmd". 6 | 7 | # What is JScript .NET? 8 | https://en.wikipedia.org/wiki/JScript_.NET 9 | 10 | 11 | ![](https://raw.githubusercontent.com/DosX-dev/JS-Calculator/main/calc.jpg) 12 | -------------------------------------------------------------------------------- /calc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DosX-dev/JS-Calculator/e10af3db2f0dddab208e57eaf50355e696a1425e/calc.jpg -------------------------------------------------------------------------------- /source/app.js: -------------------------------------------------------------------------------- 1 | // Coded by DosX 2 | // https://github.com/DosX-dev 3 | 4 | import System; 5 | import System.IO; 6 | import System.Diagnostics; 7 | 8 | if (Console.CursorTop == 0 && 9 | Console.CursorLeft == 0 && 10 | Process.GetCurrentProcess().MainModule.FileName.Contains(":\\")) { 11 | Console.ForegroundColor = ConsoleColor.Red; 12 | print("It's a console app! Use it through any terminal.\n------------------------------------------------\n"); 13 | Console.ResetColor(); 14 | showHelp(); 15 | Console.ReadKey(true); 16 | } 17 | 18 | var args = Environment.GetCommandLineArgs(); 19 | if (args.Length !== 2) { 20 | showHelp(); 21 | Environment.Exit(-1); 22 | } 23 | 24 | try { 25 | var expression: String = args[1].Replace(",", ".").Replace(" ", "").Trim(); 26 | var result: int = calculate(expression); 27 | 28 | Console.Write(expression + "=") 29 | Console.ForegroundColor = ConsoleColor.Green; 30 | print(result.toString("0.00")); 31 | Console.ResetColor(); 32 | } catch (error) { 33 | Console.ForegroundColor = ConsoleColor.Red; 34 | print(error.message); 35 | Console.ResetColor(); 36 | } 37 | 38 | function showHelp() { 39 | var currentProgramFileName: String = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName); 40 | Console.ResetColor(); 41 | print("Usage: \"" + currentProgramFileName + "\" \"expression\""); 42 | Console.ForegroundColor = ConsoleColor.DarkGray; 43 | print("Allowed characters: \"0123456789.,+-*/()\""); 44 | Console.ResetColor(); 45 | } 46 | -------------------------------------------------------------------------------- /source/build.cmd: -------------------------------------------------------------------------------- 1 | @md "bin">nul 2>&1 & "jsc" /utf8output+ /nologo /platform:x86 /nostdlib- /debug- /out:"bin\calculator.exe" "calc.js" "app.js" 2 | -------------------------------------------------------------------------------- /source/calc.js: -------------------------------------------------------------------------------- 1 | // Coded by DosX 2 | // https://github.com/DosX-dev 3 | 4 | function calculate(ex) { 5 | var allowedChars = '0123456789+-*/(). '; 6 | for (var i = 0; i < ex.length; i++) { 7 | if (allowedChars.indexOf(ex[i]) === -1) { 8 | throw new Error('Invalid char.'); 9 | } 10 | } 11 | 12 | try { 13 | var result = eval(ex); 14 | if (result == undefined || result == NaN) { 15 | throw new Error(); 16 | } 17 | return result; 18 | } catch (error) { throw new Error('Invalid expression.'); } 19 | } 20 | -------------------------------------------------------------------------------- /source/jsc.cmd: -------------------------------------------------------------------------------- 1 | @"%windir%\Microsoft.NET\Framework\v4.0.30319\jsc.exe" %* 2 | --------------------------------------------------------------------------------