├── .eslintrc ├── .githooks └── pre-commit ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Cargo.toml ├── LICENSE ├── README.md ├── build.js ├── build.rs ├── eslint.config.mjs ├── jest.config.json ├── package.json ├── pnpm-lock.yaml ├── rustfmt.toml ├── src ├── lib.rs └── lib.ts ├── tests └── tests.test.ts ├── tsconfig.build.json └── tsconfig.json /.eslintrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/magiclen/node-crc/a01c2103f53bffcce59e8ccacaeb5c650b6b0313/.eslintrc -------------------------------------------------------------------------------- /.githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | npm run lint -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [ push, pull_request ] 4 | 5 | env: 6 | CARGO_TERM_COLOR: always 7 | 8 | jobs: 9 | rustfmt: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v4 13 | - uses: actions-rust-lang/setup-rust-toolchain@v1 14 | with: 15 | toolchain: nightly 16 | components: rustfmt 17 | - uses: actions-rust-lang/rustfmt@v1 18 | 19 | clippy: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v4 23 | - uses: actions-rust-lang/setup-rust-toolchain@v1 24 | with: 25 | components: clippy 26 | - run: cargo clippy --all-targets --all-features -- -D warnings 27 | 28 | tests: 29 | strategy: 30 | fail-fast: false 31 | matrix: 32 | os: 33 | - ubuntu-latest 34 | - macos-latest 35 | - windows-latest 36 | toolchain: 37 | - 1.65 38 | - stable 39 | - nightly 40 | node-version: 41 | - 20.x 42 | - 22.x 43 | name: Use ${{ matrix.node-version }} on ${{ matrix.os }} (Rust ${{ matrix.toolchain }}) 44 | runs-on: ${{ matrix.os }} 45 | steps: 46 | - uses: actions/checkout@v4 47 | - uses: actions-rust-lang/setup-rust-toolchain@v1 48 | with: 49 | toolchain: ${{ matrix.toolchain }} 50 | - uses: actions/setup-node@v4 51 | with: 52 | node-version: ${{ matrix.node-version }} 53 | - uses: pnpm/action-setup@v4 54 | with: 55 | version: latest 56 | - run: pnpm install 57 | - run: npm run build --if-present 58 | - run: npm test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /index.* 2 | /lib 3 | 4 | ### Intellij+all ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | # User-specific stuff 9 | .idea/**/workspace.xml 10 | .idea/**/tasks.xml 11 | .idea/**/usage.statistics.xml 12 | .idea/**/dictionaries 13 | .idea/**/shelf 14 | 15 | # AWS User-specific 16 | .idea/**/aws.xml 17 | 18 | # Generated files 19 | .idea/**/contentModel.xml 20 | 21 | # Sensitive or high-churn files 22 | .idea/**/dataSources/ 23 | .idea/**/dataSources.ids 24 | .idea/**/dataSources.local.xml 25 | .idea/**/sqlDataSources.xml 26 | .idea/**/dynamic.xml 27 | .idea/**/uiDesigner.xml 28 | .idea/**/dbnavigator.xml 29 | 30 | # Gradle 31 | .idea/**/gradle.xml 32 | .idea/**/libraries 33 | 34 | # Gradle and Maven with auto-import 35 | # When using Gradle or Maven with auto-import, you should exclude module files, 36 | # since they will be recreated, and may cause churn. Uncomment if using 37 | # auto-import. 38 | # .idea/artifacts 39 | # .idea/compiler.xml 40 | # .idea/jarRepositories.xml 41 | # .idea/modules.xml 42 | # .idea/*.iml 43 | # .idea/modules 44 | # *.iml 45 | # *.ipr 46 | 47 | # CMake 48 | cmake-build-*/ 49 | 50 | # Mongo Explorer plugin 51 | .idea/**/mongoSettings.xml 52 | 53 | # File-based project format 54 | *.iws 55 | 56 | # IntelliJ 57 | out/ 58 | 59 | # mpeltonen/sbt-idea plugin 60 | .idea_modules/ 61 | 62 | # JIRA plugin 63 | atlassian-ide-plugin.xml 64 | 65 | # Cursive Clojure plugin 66 | .idea/replstate.xml 67 | 68 | # SonarLint plugin 69 | .idea/sonarlint/ 70 | 71 | # Crashlytics plugin (for Android Studio and IntelliJ) 72 | com_crashlytics_export_strings.xml 73 | crashlytics.properties 74 | crashlytics-build.properties 75 | fabric.properties 76 | 77 | # Editor-based Rest Client 78 | .idea/httpRequests 79 | 80 | # Android studio 3.1+ serialized cache file 81 | .idea/caches/build_file_checksums.ser 82 | 83 | ### Intellij+all Patch ### 84 | # Ignore everything but code style settings and run configurations 85 | # that are supposed to be shared within teams. 86 | 87 | .idea/* 88 | 89 | !.idea/codeStyles 90 | !.idea/runConfigurations 91 | 92 | ### Node ### 93 | # Logs 94 | logs 95 | *.log 96 | npm-debug.log* 97 | yarn-debug.log* 98 | yarn-error.log* 99 | lerna-debug.log* 100 | .pnpm-debug.log* 101 | 102 | # Diagnostic reports (https://nodejs.org/api/report.html) 103 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 104 | 105 | # Runtime data 106 | pids 107 | *.pid 108 | *.seed 109 | *.pid.lock 110 | 111 | # Directory for instrumented libs generated by jscoverage/JSCover 112 | lib-cov 113 | 114 | # Coverage directory used by tools like istanbul 115 | coverage 116 | *.lcov 117 | 118 | # nyc test coverage 119 | .nyc_output 120 | 121 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 122 | .grunt 123 | 124 | # Bower dependency directory (https://bower.io/) 125 | bower_components 126 | 127 | # node-waf configuration 128 | .lock-wscript 129 | 130 | # Compiled binary addons (https://nodejs.org/api/addons.html) 131 | build/ 132 | 133 | # Dependency directories 134 | node_modules/ 135 | jspm_packages/ 136 | 137 | # Snowpack dependency directory (https://snowpack.dev/) 138 | web_modules/ 139 | 140 | # TypeScript cache 141 | *.tsbuildinfo 142 | 143 | # Optional npm cache directory 144 | .npm 145 | 146 | # Optional eslint cache 147 | .eslintcache 148 | 149 | # Optional stylelint cache 150 | .stylelintcache 151 | 152 | # Microbundle cache 153 | .rpt2_cache/ 154 | .rts2_cache_cjs/ 155 | .rts2_cache_es/ 156 | .rts2_cache_umd/ 157 | 158 | # Optional REPL history 159 | .node_repl_history 160 | 161 | # Output of 'npm pack' 162 | *.tgz 163 | 164 | # Yarn Integrity file 165 | .yarn-integrity 166 | 167 | # dotenv environment variable files 168 | .env 169 | .env.development.local 170 | .env.test.local 171 | .env.production.local 172 | .env.local 173 | 174 | # parcel-bundler cache (https://parceljs.org/) 175 | .cache 176 | .parcel-cache 177 | 178 | # Next.js build output 179 | .next 180 | out 181 | 182 | # Nuxt.js build / generate output 183 | .nuxt 184 | dist 185 | 186 | # Gatsby files 187 | .cache/ 188 | # Comment in the public line in if your project uses Gatsby and not Next.js 189 | # https://nextjs.org/blog/next-9-1#public-directory-support 190 | # public 191 | 192 | # vuepress build output 193 | .vuepress/dist 194 | 195 | # vuepress v2.x temp and cache directory 196 | .temp 197 | 198 | # Docusaurus cache and generated files 199 | .docusaurus 200 | 201 | # Serverless directories 202 | .serverless/ 203 | 204 | # FuseBox cache 205 | .fusebox/ 206 | 207 | # DynamoDB Local files 208 | .dynamodb/ 209 | 210 | # TernJS port file 211 | .tern-port 212 | 213 | # Stores VSCode versions used for testing VSCode extensions 214 | .vscode-test 215 | 216 | # yarn v2 217 | .yarn/cache 218 | .yarn/unplugged 219 | .yarn/build-state.yml 220 | .yarn/install-state.gz 221 | .pnp.* 222 | 223 | ### Node Patch ### 224 | # Serverless Webpack directories 225 | .webpack/ 226 | 227 | # Optional stylelint cache 228 | 229 | # SvelteKit build / generate output 230 | .svelte-kit 231 | 232 | ### Rust ### 233 | # Generated by Cargo 234 | # will have compiled files and executables 235 | debug/ 236 | target/ 237 | 238 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 239 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 240 | Cargo.lock 241 | 242 | # These are backup files generated by rustfmt 243 | **/*.rs.bk 244 | 245 | # MSVC Windows builds of rustc generate these, which store debugging information 246 | *.pdb 247 | 248 | ### Vim ### 249 | # Swap 250 | [._]*.s[a-v][a-z] 251 | !*.svg # comment out if you don't need vector files 252 | [._]*.sw[a-p] 253 | [._]s[a-rt-v][a-z] 254 | [._]ss[a-gi-z] 255 | [._]sw[a-p] 256 | 257 | # Session 258 | Session.vim 259 | Sessionx.vim 260 | 261 | # Temporary 262 | .netrwhist 263 | *~ 264 | # Auto-generated tag files 265 | tags 266 | # Persistent undo 267 | [._]*.un~ 268 | 269 | ### VisualStudioCode ### 270 | .vscode/* 271 | !.vscode/settings.json 272 | !.vscode/tasks.json 273 | !.vscode/launch.json 274 | !.vscode/extensions.json 275 | !.vscode/*.code-snippets 276 | 277 | # Local History for Visual Studio Code 278 | .history/ 279 | 280 | # Built Visual Studio Code Extensions 281 | *.vsix 282 | 283 | ### VisualStudioCode Patch ### 284 | # Ignore all local history of files 285 | .history 286 | .ionide -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "node-terminal", 6 | "name": "test", 7 | "request": "launch", 8 | "command": "npm test" 9 | }, 10 | { 11 | "type": "node", 12 | "name": "test:inspect-brk", 13 | "request": "attach", 14 | "port": 9230 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "script": "build", 7 | "label": "Build", 8 | "group": { 9 | "kind": "build", 10 | "isDefault": true 11 | } 12 | }, 13 | { 14 | "type": "npm", 15 | "script": "test", 16 | "label": "Test", 17 | "group": { 18 | "kind": "test", 19 | "isDefault": true 20 | } 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "node-crc" 3 | version = "4.0.0" 4 | authors = ["Magic Len "] 5 | edition = "2021" 6 | rust-version = "1.65" 7 | repository = "https://github.com/magiclen/node-crc" 8 | homepage = "https://magiclen.org/node-js-crc/" 9 | keywords = ["nodejs", "crc8", "crc16", "crc32", "crc64"] 10 | categories = [] 11 | description = "To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions." 12 | license = "MIT" 13 | publish = false 14 | 15 | [lib] 16 | crate-type = ["cdylib"] 17 | 18 | [profile.release] 19 | lto = true 20 | codegen-units = 1 21 | 22 | [dependencies] 23 | napi = "2" 24 | napi-derive = "2" 25 | 26 | [build-dependencies] 27 | napi-build = "2" 28 | 29 | [dependencies.crc-any] 30 | version = "2" 31 | default-features = false 32 | features = ["heapless"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 magiclen.org (Ron Li) 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 | CRC For Node.js 2 | ================================= 3 | 4 | [![CI](https://github.com/magiclen/node-crc/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/node-crc/actions/workflows/ci.yml) 5 | 6 | To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions. 7 | 8 | You need to set up the Rust development environment: [rustup](https://rustup.rs/) 9 | 10 | ## Usage 11 | 12 | You can use `crc` function to compute a CRC value by providing the length of bits, expression, reflection, an initial value and a final xor value. For example, if you want to compute a CRC-24 value. 13 | 14 | ```typescript 15 | import { crc } from "node-crc"; 16 | 17 | const result = crc(0x00864cfb, 0x00000000, 24, 0x00b704ce, 0x00000000, 0x00000000, 0x00000000, false, Buffer.from("hello", "utf8")).toString("hex"); 18 | // Arguments: low bits of expression, high bits of expression, the length of bits, low bits of the initial value, high bits of the initial value, low bits of the final xor value, high bits of the final xor value, reflection, the source data buffer 19 | ``` 20 | 21 | To simplify the usage, there are several common versions of CRC whose computing functions are already built-in. 22 | 23 | * crc3gsm 24 | * crc4itu 25 | * crc4interlaken 26 | * crc5epc 27 | * crc5itu 28 | * crc5usb 29 | * crc6cdma2000_a 30 | * crc6cdma2000_b 31 | * crc6darc 32 | * crc6gsm 33 | * crc6itu 34 | * crc7 35 | * crc7umts 36 | * crc8 37 | * crc8cdma2000 38 | * crc8darc 39 | * crc8dvb_s2 40 | * crc8ebu 41 | * crc8icode 42 | * crc8itu 43 | * crc8maxim 44 | * crc8rohc 45 | * crc8wcdma 46 | * crc10 47 | * crc10cdma2000 48 | * crc10gsm 49 | * crc11 50 | * crc12 51 | * crc12cdma2000 52 | * crc12gsm 53 | * crc13bbc 54 | * crc14darc 55 | * crc14gsm 56 | * crc15can 57 | * crc15mpt1327 58 | * crc16 59 | * crc16ccitt_false 60 | * crc16aug_ccitt 61 | * crc16buypass 62 | * crc16cdma2000 63 | * crc16dds_110 64 | * crc16dect_r 65 | * crc16dect_x 66 | * crc16dnp 67 | * crc16en_13757 68 | * crc16genibus 69 | * crc16maxim 70 | * crc16mcrf4cc 71 | * crc16riello 72 | * crc16t10_dif 73 | * crc16teledisk 74 | * crc16tms13157 75 | * crc16usb 76 | * crc_a 77 | * crc16kermit 78 | * crc16modbus 79 | * crc16_x25 80 | * crc16xmodem 81 | * crc17can 82 | * crc21can 83 | * crc24 84 | * crc24ble 85 | * crc24flexray_a 86 | * crc24flexray_b 87 | * crc24lte_a 88 | * crc24lte_b 89 | * crc24os9 90 | * crc30cdma 91 | * crc32 92 | * It also called `crc32b` in `mhash`. 93 | * crc32mhash 94 | * `mhash` is a common library which has two weird versions of CRC32 called `crc32` and `crc32b`. `crc32` and `crc32mhash` in this module are `crc32b` and `crc32` in mhash respectively. 95 | * crc32bzip2 96 | * crc32c 97 | * crc32d 98 | * crc32mpeg2 99 | * crc32posix 100 | * crc32q 101 | * crc32jamcrc 102 | * crc32xfer 103 | * crc40gsm 104 | * crc64 105 | * crc64iso 106 | * crc64we 107 | * crc64jones 108 | 109 | Input data and output data are buffers. 110 | 111 | For instance, 112 | 113 | ```typescript 114 | import { crc32, crc64 } from "node-crc"; 115 | 116 | const result = crc32(Buffer.from("hello", "utf8")).toString("hex"); 117 | const result2 = crc64(Buffer.from("world", "utf8")).toString("hex"); 118 | ``` 119 | 120 | ## TODO 121 | 122 | 1. CRC class to compute large data 123 | 124 | ## License 125 | 126 | [MIT](LICENSE) 127 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | import fs from "node:fs"; 2 | 3 | const FILE_PATH = "./index.d.cts"; 4 | 5 | let s = fs.readFileSync(FILE_PATH, { 6 | encoding: "utf8" 7 | }); 8 | 9 | s = s.replaceAll("*r\"", "*"); 10 | 11 | fs.writeFileSync(FILE_PATH, s); -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | napi_build::setup(); 3 | } 4 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import eslint from '@eslint/js'; 2 | import stylistic from "@stylistic/eslint-plugin"; 3 | 4 | import * as importPlugin from "eslint-plugin-import"; 5 | import globals from "globals"; 6 | import tseslint from "typescript-eslint"; 7 | 8 | export default tseslint.config( 9 | eslint.configs.recommended, 10 | ...tseslint.configs.strictTypeChecked, 11 | ...tseslint.configs.stylisticTypeChecked, 12 | { 13 | languageOptions: { 14 | ecmaVersion: 2023, 15 | sourceType: "module", 16 | globals: { 17 | ...globals.browser, 18 | ...globals.node, 19 | }, 20 | parserOptions: { 21 | projectService: true, 22 | tsconfigRootDir: import.meta.dirname, 23 | }, 24 | }, 25 | rules: { 26 | // These rules relate to possible logic errors in code: 27 | 28 | "array-callback-return": "error", 29 | "no-constructor-return": "error", 30 | "no-inner-declarations": ["error", "both"], 31 | "no-promise-executor-return": "error", 32 | "no-self-compare": "error", 33 | "no-template-curly-in-string": "warn", 34 | "no-unmodified-loop-condition": "warn", 35 | "no-unreachable-loop": "error", 36 | "require-atomic-updates": "error", 37 | 38 | // These rules suggest alternate ways of doing things: 39 | 40 | "accessor-pairs": "error", 41 | "arrow-body-style": ["error", "as-needed"], 42 | "block-scoped-var": "error", 43 | 44 | "camelcase": ["error", { 45 | properties: "never", 46 | }], 47 | 48 | "consistent-this": ["error", "self"], 49 | "curly": "error", 50 | "default-case-last": "error", 51 | 52 | "eqeqeq": "error", 53 | "func-names": ["error", "as-needed"], 54 | "func-style": ["error", "expression"], 55 | 56 | "grouped-accessor-pairs": "error", 57 | "guard-for-in": "error", 58 | 59 | "logical-assignment-operators": ["error", "always", { 60 | enforceForIfStatements: true 61 | }], 62 | 63 | "new-cap": ["error", { 64 | newIsCap: true, 65 | capIsNew: true, 66 | }], 67 | 68 | "no-bitwise": ["error", { 69 | int32Hint: true, 70 | }], 71 | 72 | "no-caller": "error", 73 | "no-div-regex": "error", 74 | "no-eq-null": "error", 75 | "no-eval": "error", 76 | "no-extend-native": "error", 77 | "no-extra-bind": "error", 78 | "no-extra-label": "error", 79 | "no-implicit-coercion": "error", 80 | "no-implicit-globals": "error", 81 | "no-invalid-this": "error", 82 | "no-iterator": "error", 83 | "no-label-var": "error", 84 | "no-lone-blocks": "error", 85 | "no-lonely-if": "error", 86 | "no-multi-assign": "error", 87 | "no-nested-ternary": "error", 88 | "no-new": "error", 89 | "no-new-func": "error", 90 | "no-new-wrappers": "error", 91 | "no-object-constructor": "error", 92 | "no-octal-escape": "error", 93 | 94 | "no-plusplus": ["error", { 95 | allowForLoopAfterthoughts: true, 96 | }], 97 | 98 | "no-proto": "error", 99 | "no-return-assign": "error", 100 | "no-sequences": "error", 101 | "no-unneeded-ternary": "error", 102 | "one-var": ["error", "never"], 103 | "operator-assignment": "error", 104 | "prefer-arrow-callback": "error", 105 | "prefer-const": "error", 106 | "prefer-exponentiation-operator": "error", 107 | "prefer-numeric-literals": "error", 108 | "prefer-object-has-own": "error", 109 | "prefer-object-spread": "error", 110 | "prefer-regex-literals": "error", 111 | "prefer-rest-params": "error", 112 | "prefer-spread": "error", 113 | "prefer-template": "error", 114 | "radix": ["error", "as-needed"], 115 | "require-unicode-regexp": "error", 116 | 117 | "sort-imports": ["error", { 118 | ignoreDeclarationSort: true, 119 | }], 120 | 121 | "symbol-description": "error", 122 | "vars-on-top": "error", 123 | 124 | // These rules care about how the code looks rather than how it executes: 125 | 126 | "unicode-bom": "error", 127 | } 128 | }, 129 | { 130 | rules: { 131 | // override 132 | "@typescript-eslint/no-require-imports": ["error", { 133 | allowAsImport: true, 134 | }], 135 | 136 | "@typescript-eslint/no-unused-vars": ["error", { 137 | args: "all", 138 | argsIgnorePattern: "^_", 139 | caughtErrors: "all", 140 | caughtErrorsIgnorePattern: "^_", 141 | destructuredArrayIgnorePattern: "^_", 142 | varsIgnorePattern: "^_", 143 | ignoreRestSiblings: true, 144 | }], 145 | 146 | "@typescript-eslint/restrict-template-expressions": ["error", { 147 | allowBoolean: true, 148 | allowNullish: true, 149 | allowNumber: true, 150 | allowRegExp: true, 151 | }], 152 | 153 | // switch on 154 | 155 | "@typescript-eslint/consistent-type-exports": "error", 156 | 157 | "@typescript-eslint/consistent-type-imports": ["error", { 158 | disallowTypeAnnotations: false, 159 | fixStyle: "separate-type-imports", 160 | prefer: "type-imports", 161 | }], 162 | 163 | "@typescript-eslint/default-param-last": "error", 164 | "@typescript-eslint/explicit-function-return-type": "error", 165 | 166 | "@typescript-eslint/explicit-member-accessibility": ["error", { 167 | accessibility: "no-public", 168 | }], 169 | 170 | "@typescript-eslint/explicit-module-boundary-types": "error", 171 | "@typescript-eslint/method-signature-style": "error", 172 | "@typescript-eslint/no-import-type-side-effects": "error", 173 | "@typescript-eslint/no-loop-func": "error", 174 | "@typescript-eslint/no-unnecessary-parameter-property-assignment": "error", 175 | "@typescript-eslint/no-unnecessary-qualifier": "error", 176 | "@typescript-eslint/no-use-before-define": "error", 177 | "@typescript-eslint/no-useless-empty-export": "error", 178 | }, 179 | }, 180 | stylistic.configs['recommended-flat'], 181 | { 182 | rules: { 183 | // override 184 | 185 | "@stylistic/arrow-parens": ["error", "always"], 186 | "@stylistic/brace-style": ["error", "1tbs", {}], 187 | 188 | "@stylistic/indent": ["error", 4, { 189 | SwitchCase: 1, 190 | }], 191 | 192 | "@stylistic/indent-binary-ops": ["error", 4], 193 | "@stylistic/lines-between-class-members": "off", 194 | "@stylistic/member-delimiter-style": ["error", {}], 195 | "@stylistic/multiline-ternary": ["error", "never"], 196 | 197 | "@stylistic/no-extra-parens": ["error", "all", { 198 | nestedBinaryExpressions: false, 199 | }], 200 | 201 | "@stylistic/no-mixed-operators": ["error", {}], 202 | 203 | "@stylistic/no-multiple-empty-lines": ["error", { 204 | max: 2, 205 | maxEOF: 0, 206 | maxBOF: 0, 207 | }], 208 | 209 | "@stylistic/no-trailing-spaces": ["error", { 210 | skipBlankLines: true, 211 | }], 212 | 213 | "@stylistic/object-curly-spacing": ["error", "always", { 214 | arraysInObjects: true, 215 | objectsInObjects: true, 216 | }], 217 | 218 | "@stylistic/quote-props": ["error", "as-needed"], 219 | "@stylistic/quotes": ["error", "double", {}], 220 | "@stylistic/semi": ["error", "always"], 221 | 222 | "@stylistic/semi-spacing": ["error", { 223 | before: false, 224 | after: false, 225 | }], 226 | 227 | "@stylistic/spaced-comment": ["error", "always", {}], 228 | "@stylistic/wrap-iife": ["error", "outside", {}], 229 | "@stylistic/yield-star-spacing": ["error", "after"], 230 | 231 | // switch on 232 | 233 | "@stylistic/array-bracket-newline": ["error", { 234 | minItems: 4, 235 | multiline: true, 236 | }], 237 | 238 | "@stylistic/array-element-newline": ["error", "consistent"], 239 | "@stylistic/function-call-argument-newline": ["error", "consistent"], 240 | "@stylistic/function-call-spacing": "error", 241 | "@stylistic/function-paren-newline": ["error", "multiline-arguments"], 242 | 243 | "@stylistic/generator-star-spacing": ["error", { 244 | before: false, 245 | after: true, 246 | }], 247 | 248 | "@stylistic/implicit-arrow-linebreak": "error", 249 | "@stylistic/jsx-quotes": ["error", "prefer-double"], 250 | "@stylistic/linebreak-style": "error", 251 | 252 | "@stylistic/newline-per-chained-call": ["error", { 253 | ignoreChainWithDepth: 3, 254 | }], 255 | 256 | "@stylistic/no-extra-semi": "error", 257 | "@stylistic/nonblock-statement-body-position": "error", 258 | 259 | "@stylistic/object-curly-newline": ["error", { 260 | "ObjectExpression": { "multiline": true, "minProperties": 4 }, 261 | "ObjectPattern": { "multiline": true, "minProperties": 4 }, 262 | "ImportDeclaration": { "multiline": true, "minProperties": 4 }, 263 | "ExportDeclaration": { "multiline": true, "minProperties": 4 } 264 | }], 265 | 266 | "@stylistic/object-property-newline": ["error", { 267 | allowAllPropertiesOnSameLine: true, 268 | }], 269 | 270 | "@stylistic/semi-style": "error", 271 | "@stylistic/switch-colon-spacing": "error", 272 | "@stylistic/wrap-regex": "error", 273 | } 274 | }, 275 | importPlugin.flatConfigs.recommended, 276 | importPlugin.flatConfigs.typescript, 277 | { 278 | settings: { 279 | "import/resolver": { 280 | "typescript": true, 281 | "node": true, 282 | } 283 | }, 284 | rules: { 285 | // override 286 | 287 | // switch on 288 | 289 | "import/no-empty-named-blocks": "error", 290 | 291 | "import/no-extraneous-dependencies": ["error", { 292 | devDependencies: [ 293 | "tests/**/*", 294 | "**/*.test.ts", 295 | "**/*.spec.ts", 296 | ], 297 | }], 298 | 299 | "import/no-mutable-exports": "error", 300 | 301 | "import/no-unused-modules": ["warn", { 302 | unusedExports: true, 303 | src: [ 304 | "src/**/*", 305 | ], 306 | ignoreExports: [ 307 | "src/lib.ts", 308 | ], 309 | }], 310 | 311 | "import/no-absolute-path": "error", 312 | "import/no-cycle": "error", 313 | "import/no-self-import": "error", 314 | "import/consistent-type-specifier-style": ["error", "prefer-top-level"], 315 | "import/first": "error", 316 | "import/newline-after-import": "error", 317 | "import/no-named-default": "error", 318 | "import/no-namespace": "warn", 319 | 320 | "import/order": ["error", { 321 | "newlines-between": "always-and-inside-groups", 322 | alphabetize: { 323 | order: "asc", 324 | }, 325 | warnOnUnassignedImports: true, 326 | }], 327 | } 328 | }, 329 | { ignores: ["eslint.config.mjs", "lib/*"], }, 330 | ); -------------------------------------------------------------------------------- /jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extensionsToTreatAsEsm": [ 3 | ".ts" 4 | ], 5 | "transform": { 6 | "^.+\\.[jt]sx?$": [ 7 | "ts-jest", 8 | { 9 | "useESM": true 10 | } 11 | ] 12 | }, 13 | "moduleNameMapper": { 14 | "^(\\.\\.?\\/.+)\\.jsx?$": "$1" 15 | } 16 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-crc", 3 | "version": "4.0.0", 4 | "description": "To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions.", 5 | "type": "module", 6 | "exports": "./lib/lib.js", 7 | "types": "./lib/lib.d.ts", 8 | "engines": { 9 | "node": ">=20" 10 | }, 11 | "files": [ 12 | "lib", 13 | "src", 14 | "build.js", 15 | "build.rs", 16 | "Cargo.toml" 17 | ], 18 | "scripts": { 19 | "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", 20 | "test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage", 21 | "test:inspect-brk": "node --experimental-vm-modules --inspect-brk=0.0.0.0:9230 node_modules/jest/bin/jest.js --testTimeout 0 --runInBand", 22 | "clean": "rimraf lib", 23 | "install": "napi build --release --platform --js index.cjs --dts index.d.cts && node build.js", 24 | "build": "npm run clean && npm run install && tsc -p tsconfig.build.json", 25 | "build:watch": "npm run build -- -w", 26 | "lint": "eslint src tests", 27 | "lint:fix": "npm run lint -- --fix", 28 | "prepare": "git config core.hooksPath .githooks || exit 0", 29 | "prepack": "npm run build", 30 | "prepublishOnly": "npm run lint && npm run test" 31 | }, 32 | "repository": { 33 | "type": "git", 34 | "url": "git+https://github.com/magiclen/node-crc.git" 35 | }, 36 | "keywords": [ 37 | "node.js", 38 | "crc", 39 | "crc8", 40 | "crc16", 41 | "crc32", 42 | "crc64" 43 | ], 44 | "author": "Magic Len", 45 | "license": "MIT", 46 | "bugs": { 47 | "url": "https://github.com/magiclen/node-crc/issues" 48 | }, 49 | "homepage": "https://magiclen.org/node-js-crc/", 50 | "devDependencies": { 51 | "@eslint/js": "^9.13.0", 52 | "@stylistic/eslint-plugin": "^2.9.0", 53 | "@types/eslint__js": "^8.42.3", 54 | "@types/jest": "^29.5.13", 55 | "eslint": "^9.13.0", 56 | "eslint-import-resolver-typescript": "^3.6.3", 57 | "eslint-plugin-import": "^2.31.0", 58 | "globals": "^15.11.0", 59 | "jest": "^29.7.0", 60 | "rimraf": "^6.0.1", 61 | "ts-jest": "^29.2.5", 62 | "typescript": "~5.6.3", 63 | "typescript-eslint": "^8.11.0" 64 | }, 65 | "dependencies": { 66 | "@napi-rs/cli": "^2.18.4", 67 | "@types/node": "^22.7.8" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # array_width = 60 2 | # attr_fn_like_width = 70 3 | binop_separator = "Front" 4 | blank_lines_lower_bound = 0 5 | blank_lines_upper_bound = 1 6 | brace_style = "PreferSameLine" 7 | # chain_width = 60 8 | color = "Auto" 9 | # comment_width = 100 10 | condense_wildcard_suffixes = true 11 | control_brace_style = "AlwaysSameLine" 12 | empty_item_single_line = true 13 | enum_discrim_align_threshold = 80 14 | error_on_line_overflow = false 15 | error_on_unformatted = false 16 | # fn_call_width = 60 17 | fn_params_layout = "Tall" 18 | fn_single_line = false 19 | force_explicit_abi = true 20 | force_multiline_blocks = false 21 | format_code_in_doc_comments = true 22 | doc_comment_code_block_width = 80 23 | format_generated_files = true 24 | format_macro_matchers = true 25 | format_macro_bodies = true 26 | skip_macro_invocations = [] 27 | format_strings = true 28 | hard_tabs = false 29 | hex_literal_case = "Upper" 30 | imports_indent = "Block" 31 | imports_layout = "Mixed" 32 | indent_style = "Block" 33 | inline_attribute_width = 0 34 | match_arm_blocks = true 35 | match_arm_leading_pipes = "Never" 36 | match_block_trailing_comma = true 37 | max_width = 100 38 | merge_derives = true 39 | imports_granularity = "Crate" 40 | newline_style = "Unix" 41 | normalize_comments = false 42 | normalize_doc_attributes = true 43 | overflow_delimited_expr = true 44 | remove_nested_parens = true 45 | reorder_impl_items = true 46 | reorder_imports = true 47 | group_imports = "StdExternalCrate" 48 | reorder_modules = true 49 | short_array_element_width_threshold = 10 50 | # single_line_if_else_max_width = 50 51 | space_after_colon = true 52 | space_before_colon = false 53 | spaces_around_ranges = false 54 | struct_field_align_threshold = 80 55 | struct_lit_single_line = false 56 | # struct_lit_width = 18 57 | # struct_variant_width = 35 58 | tab_spaces = 4 59 | trailing_comma = "Vertical" 60 | trailing_semicolon = true 61 | type_punctuation_density = "Wide" 62 | use_field_init_shorthand = true 63 | use_small_heuristics = "Max" 64 | use_try_shorthand = true 65 | where_single_line = false 66 | wrap_comments = false -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use crc_any::{CRCu16, CRCu32, CRCu64, CRCu8, CRC}; 2 | use napi::bindgen_prelude::*; 3 | use napi_derive::napi; 4 | 5 | #[inline] 6 | fn to_buffer_1(u: u8) -> Buffer { 7 | Buffer::from(vec![u]) 8 | } 9 | 10 | #[inline] 11 | fn to_buffer_2(u: u16) -> Buffer { 12 | Buffer::from(u.to_be_bytes().to_vec()) 13 | } 14 | 15 | #[inline] 16 | fn to_buffer_3(u: u32) -> Buffer { 17 | Buffer::from(u.to_be_bytes()[1..].to_vec()) 18 | } 19 | 20 | #[inline] 21 | fn to_buffer_4(u: u32) -> Buffer { 22 | Buffer::from(u.to_be_bytes().to_vec()) 23 | } 24 | 25 | #[inline] 26 | fn to_buffer_5(u: u64) -> Buffer { 27 | Buffer::from(u.to_be_bytes()[3..].to_vec()) 28 | } 29 | 30 | #[inline] 31 | fn to_buffer_8(u: u64) -> Buffer { 32 | Buffer::from(u.to_be_bytes().to_vec()) 33 | } 34 | 35 | macro_rules! crc_functions_1 { 36 | (@inner $(#[$attr:meta])* $f:ident) => { 37 | $(#[$attr])* 38 | #[napi(js_name = $f)] 39 | pub fn $f(data: Buffer) -> Buffer { 40 | let crc = { 41 | let mut crc = CRCu8::$f(); 42 | 43 | crc.digest(data.as_ref()); 44 | 45 | crc.get_crc() 46 | }; 47 | 48 | to_buffer_1(crc) 49 | } 50 | }; 51 | ($($(#[$attr:meta])* $f:ident),+ $(,)* ) => { 52 | $( 53 | crc_functions_1!(@inner $(#[$attr])* $f); 54 | )+ 55 | }; 56 | } 57 | 58 | macro_rules! crc_functions_2 { 59 | (@inner $(#[$attr:meta])* $f:ident) => { 60 | $(#[$attr])* 61 | #[napi(js_name = $f)] 62 | pub fn $f(data: Buffer) -> Buffer { 63 | let crc = { 64 | let mut crc = CRCu16::$f(); 65 | 66 | crc.digest(data.as_ref()); 67 | 68 | crc.get_crc() 69 | }; 70 | 71 | to_buffer_2(crc) 72 | } 73 | }; 74 | ($($(#[$attr:meta])* $f:ident),+ $(,)* ) => { 75 | $( 76 | crc_functions_2!(@inner $(#[$attr])* $f); 77 | )+ 78 | }; 79 | } 80 | 81 | macro_rules! crc_functions_3 { 82 | (@inner $(#[$attr:meta])* $f:ident) => { 83 | $(#[$attr])* 84 | #[napi(js_name = $f)] 85 | pub fn $f(data: Buffer) -> Buffer { 86 | let crc = { 87 | let mut crc = CRCu32::$f(); 88 | 89 | crc.digest(data.as_ref()); 90 | 91 | crc.get_crc() 92 | }; 93 | 94 | to_buffer_3(crc) 95 | } 96 | }; 97 | ($($(#[$attr:meta])* $f:ident),+ $(,)* ) => { 98 | $( 99 | crc_functions_3!(@inner $(#[$attr])* $f); 100 | )+ 101 | }; 102 | } 103 | 104 | macro_rules! crc_functions_4 { 105 | (@inner $(#[$attr:meta])* $f:ident) => { 106 | $(#[$attr])* 107 | #[napi(js_name = $f)] 108 | pub fn $f(data: Buffer) -> Buffer { 109 | let crc = { 110 | let mut crc = CRCu32::$f(); 111 | 112 | crc.digest(data.as_ref()); 113 | 114 | crc.get_crc() 115 | }; 116 | 117 | to_buffer_4(crc) 118 | } 119 | }; 120 | ($($(#[$attr:meta])* $f:ident),+ $(,)* ) => { 121 | $( 122 | crc_functions_4!(@inner $(#[$attr])* $f); 123 | )+ 124 | }; 125 | } 126 | 127 | macro_rules! crc_functions_5 { 128 | (@inner $(#[$attr:meta])* $f:ident) => { 129 | $(#[$attr])* 130 | #[napi(js_name = $f)] 131 | pub fn $f(data: Buffer) -> Buffer { 132 | let crc = { 133 | let mut crc = CRCu64::$f(); 134 | 135 | crc.digest(data.as_ref()); 136 | 137 | crc.get_crc() 138 | }; 139 | 140 | to_buffer_5(crc) 141 | } 142 | }; 143 | ($($(#[$attr:meta])* $f:ident),+ $(,)* ) => { 144 | $( 145 | crc_functions_5!(@inner $(#[$attr])* $f); 146 | )+ 147 | }; 148 | } 149 | 150 | macro_rules! crc_functions_8 { 151 | (@inner $(#[$attr:meta])* $f:ident) => { 152 | $(#[$attr])* 153 | #[napi(js_name = $f)] 154 | pub fn $f(data: Buffer) -> Buffer { 155 | let crc = { 156 | let mut crc = CRCu64::$f(); 157 | 158 | crc.digest(data.as_ref()); 159 | 160 | crc.get_crc() 161 | }; 162 | 163 | to_buffer_8(crc) 164 | } 165 | }; 166 | ($($(#[$attr:meta])* $f:ident),+ $(,)* ) => { 167 | $( 168 | crc_functions_8!(@inner $(#[$attr])* $f); 169 | )+ 170 | }; 171 | } 172 | 173 | crc_functions_1!( 174 | /// |Check|Poly|Init|Ref|XorOut| 175 | /// |---|---|---|---|---| 176 | /// |0x4|0x3|0x0|false|0x7| 177 | crc3gsm, 178 | /// |Check|Poly|Init|Ref|XorOut| 179 | /// |---|---|---|---|---| 180 | /// |0x7|0x3 (rev: 0xC)|0x0|true|0x0| 181 | crc4itu, 182 | /// |Check|Poly|Init|Ref|XorOut| 183 | /// |---|---|---|---|---| 184 | /// |0xB|0x3|0xF|false|0xF| 185 | crc4interlaken, 186 | /// |Check|Poly|Init|Ref|XorOut| 187 | /// |---|---|---|---|---| 188 | /// |0x00|0x09|0x09|false|0x00| 189 | crc5epc, 190 | /// |Check|Poly|Init|Ref|XorOut| 191 | /// |---|---|---|---|---| 192 | /// |0x07|0x15 (rev: 0x15)|0x00|true|0x00| 193 | crc5itu, 194 | /// |Check|Poly|Init|Ref|XorOut| 195 | /// |---|---|---|---|---| 196 | /// |0x19|0x05 (rev: 0x14)|0x1F|true|0x1F| 197 | crc5usb, 198 | /// |Check|Poly|Init|Ref|XorOut| 199 | /// |---|---|---|---|---| 200 | /// |0x0D|0x27|0x3F|false|0x00| 201 | crc6cdma2000_a, 202 | /// |Check|Poly|Init|Ref|XorOut| 203 | /// |---|---|---|---|---| 204 | /// |0x3B|0x07|0x3F|false|0x00| 205 | crc6cdma2000_b, 206 | /// |Check|Poly|Init|Ref|XorOut| 207 | /// |---|---|---|---|---| 208 | /// |0x26|0x19 (rev: 0x26)|0x00|true|0x00| 209 | crc6darc, 210 | /// |Check|Poly|Init|Ref|XorOut| 211 | /// |---|---|---|---|---| 212 | /// |0x13|0x2F|0x00|false|0x3F| 213 | crc6gsm, 214 | /// |Check|Poly|Init|Ref|XorOut| 215 | /// |---|---|---|---|---| 216 | /// |0x06|0x03 (rev: 0x30)|0x00|true|0x00| 217 | crc6itu, 218 | /// |Check|Poly|Init|Ref|XorOut| 219 | /// |---|---|---|---|---| 220 | /// |0x75|0x09|0x00|false|0x00| 221 | crc7, 222 | /// |Check|Poly|Init|Ref|XorOut| 223 | /// |---|---|---|---|---| 224 | /// |0x61|0x45|0x00|false|0x00| 225 | crc7umts, 226 | /// |Check|Poly|Init|Ref|XorOut| 227 | /// |---|---|---|---|---| 228 | /// |0xF4|0x07|0x00|false|0x00| 229 | crc8, 230 | /// |Check|Poly|Init|Ref|XorOut| 231 | /// |---|---|---|---|---| 232 | /// |0xDA|0x9B|0xFF|false|0x00| 233 | crc8cdma2000, 234 | /// |Check|Poly|Init|Ref|XorOut| 235 | /// |---|---|---|---|---| 236 | /// |0x15|0x39 (rev: 0x9C)|0x00|true|0x00| 237 | crc8darc, 238 | /// |Check|Poly|Init|Ref|XorOut| 239 | /// |---|---|---|---|---| 240 | /// |0xBC|0xD5|0x00|false|0x00| 241 | crc8dvb_s2, 242 | /// |Check|Poly|Init|Ref|XorOut| 243 | /// |---|---|---|---|---| 244 | /// |0x97|0x1D (rev: 0xB8)|0xFF|true|0x00| 245 | crc8ebu, 246 | /// |Check|Poly|Init|Ref|XorOut| 247 | /// |---|---|---|---|---| 248 | /// |0x7E|0x1D|0xFD|false|0x00| 249 | crc8icode, 250 | /// |Check|Poly|Init|Ref|XorOut| 251 | /// |---|---|---|---|---| 252 | /// |0xA1|0x07|0x00|false|0x55| 253 | crc8itu, 254 | /// |Check|Poly|Init|Ref|XorOut| 255 | /// |---|---|---|---|---| 256 | /// |0xA1|0x31 (rev: 0x8C)|0x00|true|0x00| 257 | crc8maxim, 258 | /// |Check|Poly|Init|Ref|XorOut| 259 | /// |---|---|---|---|---| 260 | /// |0xD0|0x07 (rev: 0xE0)|0xFF|true|0x00| 261 | crc8rohc, 262 | /// |Check|Poly|Init|Ref|XorOut| 263 | /// |---|---|---|---|---| 264 | /// |0x25|0x9B (rev: 0xD9)|0x00|true|0x00| 265 | crc8wcdma, 266 | ); 267 | 268 | crc_functions_2!( 269 | /// |Check|Poly|Init|Ref|XorOut| 270 | /// |---|---|---|---|---| 271 | /// |0x199|0x233|0x000|false|0x000| 272 | crc10, 273 | /// |Check|Poly|Init|Ref|XorOut| 274 | /// |---|---|---|---|---| 275 | /// |0x233|0x3D9|0x3FF|false|0x000| 276 | crc10cdma2000, 277 | /// |Check|Poly|Init|Ref|XorOut| 278 | /// |---|---|---|---|---| 279 | /// |0x12A|0x175|0x000|false|0x3FF| 280 | crc10gsm, 281 | /// |Check|Poly|Init|Ref|XorOut| 282 | /// |---|---|---|---|---| 283 | /// |0x5A3|0x385|0x01a|false|0x000| 284 | crc11, 285 | /// |Check|Poly|Init|Ref|XorOut| 286 | /// |---|---|---|---|---| 287 | /// |0xF5B|0x80F|0x000|false|0x000| 288 | crc12, 289 | /// |Check|Poly|Init|Ref|XorOut| 290 | /// |---|---|---|---|---| 291 | /// |0xD4D|0xF13|0xFFF|false|0x000| 292 | crc12cdma2000, 293 | /// |Check|Poly|Init|Ref|XorOut| 294 | /// |---|---|---|---|---| 295 | /// |0xB34|0xD31|0x000|false|0xFFF| 296 | crc12gsm, 297 | /// |Check|Poly|Init|Ref|XorOut| 298 | /// |---|---|---|---|---| 299 | /// |0x04FA|0x1CF5|0x0000|false|0x0000| 300 | crc13bbc, 301 | /// |Check|Poly|Init|Ref|XorOut| 302 | /// |---|---|---|---|---| 303 | /// |0x082D|0x0805 (rev: 0x2804)|0x0000|true|0x0000| 304 | crc14darc, 305 | /// |Check|Poly|Init|Ref|XorOut| 306 | /// |---|---|---|---|---| 307 | /// |0x30AE|0x202D|0x0000|false|0x3FFF| 308 | crc14gsm, 309 | /// |Check|Poly|Init|Ref|XorOut| 310 | /// |---|---|---|---|---| 311 | /// |0x059E|0x4599|0x0000|false|0x0000| 312 | crc15can, 313 | /// |Check|Poly|Init|Ref|XorOut| 314 | /// |---|---|---|---|---| 315 | /// |0x2566|0x6815|0x0000|false|0x0001| 316 | crc15mpt1327, 317 | /// |Check|Poly|Init|Ref|XorOut| 318 | /// |---|---|---|---|---| 319 | /// |0xBB3D|0x8005 (rev: 0xA001)|0x0000|true|0x0000| 320 | crc16, 321 | /// |Check|Poly|Init|Ref|XorOut| 322 | /// |---|---|---|---|---| 323 | /// |0x29B1|0x1021|0xFFFF|false|0x0000| 324 | crc16ccitt_false, 325 | /// |Check|Poly|Init|Ref|XorOut| 326 | /// |---|---|---|---|---| 327 | /// |0xE5CC|0x1021|0x1D0F|false|0x0000| 328 | crc16aug_ccitt, 329 | /// |Check|Poly|Init|Ref|XorOut| 330 | /// |---|---|---|---|---| 331 | /// |0xFEE8|0x8005|0x0000|false|0x0000| 332 | crc16buypass, 333 | /// |Check|Poly|Init|Ref|XorOut| 334 | /// |---|---|---|---|---| 335 | /// |0x4C06|0xC867|0xFFFF|false|0x0000| 336 | crc16cdma2000, 337 | /// |Check|Poly|Init|Ref|XorOut| 338 | /// |---|---|---|---|---| 339 | /// |0x9ECF|0x8005|0x800D|false|0x0000| 340 | crc16dds_110, 341 | /// |Check|Poly|Init|Ref|XorOut| 342 | /// |---|---|---|---|---| 343 | /// |0x007E|0x0589|0x0000|false|0x0001| 344 | crc16dect_r, 345 | /// |Check|Poly|Init|Ref|XorOut| 346 | /// |---|---|---|---|---| 347 | /// |0x007F|0x0589|0x0000|false|0x0000| 348 | crc16dect_x, 349 | /// |Check|Poly|Init|Ref|XorOut| 350 | /// |---|---|---|---|---| 351 | /// |0xEA82|0x3D65 (rev: 0xA6BC)|0x0000|true|0xFFFF| 352 | crc16dnp, 353 | /// |Check|Poly|Init|Ref|XorOut| 354 | /// |---|---|---|---|---| 355 | /// |0xC2B7|0x3D65|0x0000|false|0xFFFF| 356 | crc16en_13757, 357 | /// |Check|Poly|Init|Ref|XorOut| 358 | /// |---|---|---|---|---| 359 | /// |0xD64E|0x1021|0xFFFF|false|0xFFFF| 360 | crc16genibus, 361 | /// |Check|Poly|Init|Ref|XorOut| 362 | /// |---|---|---|---|---| 363 | /// |0x44C2|0x8005 (rev: 0xA001)|0xFFFF|true|0xFFFF| 364 | crc16maxim, 365 | /// |Check|Poly|Init|Ref|XorOut| 366 | /// |---|---|---|---|---| 367 | /// |0x6F91|0x1021 (rev: 0x8408)|0xFFFF|true|0x0000| 368 | crc16mcrf4cc, 369 | /// |Check|Poly|Init|Ref|XorOut| 370 | /// |---|---|---|---|---| 371 | /// |0x63D0|0x1021 (rev: 0x8408)|0xB2AA|true|0x0000| 372 | crc16riello, 373 | /// |Check|Poly|Init|Ref|XorOut| 374 | /// |---|---|---|---|---| 375 | /// |0xD0DB|0x8BB7|0x0000|false|0x0000| 376 | crc16t10_dif, 377 | /// |Check|Poly|Init|Ref|XorOut| 378 | /// |---|---|---|---|---| 379 | /// |0x0FB3|0xA097|0x0000|false|0x0000| 380 | crc16teledisk, 381 | /// |Check|Poly|Init|Ref|XorOut| 382 | /// |---|---|---|---|---| 383 | /// |0x26B1|0x1021 (rev: 0x8408)|0x89EC|true|0x0000| 384 | crc16tms13157, 385 | /// |Check|Poly|Init|Ref|XorOut| 386 | /// |---|---|---|---|---| 387 | /// |0xB4C8|0x8005 (rev: 0xA001)|0xFFFF|true|0xFFFF| 388 | crc16usb, 389 | /// |Check|Poly|Init|Ref|XorOut| 390 | /// |---|---|---|---|---| 391 | /// |0xBF05|0x1021 (rev: 0x8408)|0xC6C6|true|0x0000| 392 | crc_a, 393 | /// |Check|Poly|Init|Ref|XorOut| 394 | /// |---|---|---|---|---| 395 | /// |0x2189|0x1021 (rev: 0x8408)|0x0000|true|0x0000| 396 | crc16kermit, 397 | /// |Check|Poly|Init|Ref|XorOut| 398 | /// |---|---|---|---|---| 399 | /// |0x4B37|0x8005 (rev: 0xA001)|0xFFFF|true|0x0000| 400 | crc16modbus, 401 | /// |Check|Poly|Init|Ref|XorOut| 402 | /// |---|---|---|---|---| 403 | /// |0x906E|0x8005 (rev: 0xA001)|0xFFFF|true|0xFFFF| 404 | crc16_x25, 405 | /// |Check|Poly|Init|Ref|XorOut| 406 | /// |---|---|---|---|---| 407 | /// |0x31C3|0x1021|0x0000|false|0x0000| 408 | crc16xmodem, 409 | ); 410 | 411 | crc_functions_3!( 412 | /// |Check|Poly|Init|Ref|XorOut| 413 | /// |---|---|---|---|---| 414 | /// |0x04F03|0x1685B|0x00000|false|0x00000| 415 | crc17can, 416 | /// |Check|Poly|Init|Ref|XorOut| 417 | /// |---|---|---|---|---| 418 | /// |0x0ED841|0x102899|0x000000|false|0x000000| 419 | crc21can, 420 | /// |Check|Poly|Init|Ref|XorOut| 421 | /// |---|---|---|---|---| 422 | /// |0x21CF02|0x864CFB|0xB704CE|false|0x000000| 423 | crc24, 424 | /// |Check|Poly|Init|Ref|XorOut| 425 | /// |---|---|---|---|---| 426 | /// |0xC25A56|0x00065B (rev: 0xDA6000)|0x555555|true|0x000000| 427 | crc24ble, 428 | /// |Check|Poly|Init|Ref|XorOut| 429 | /// |---|---|---|---|---| 430 | /// |0x7979BD|0x5D6DCB|0xFEDCBA|false|0x000000| 431 | crc24flexray_a, 432 | /// |Check|Poly|Init|Ref|XorOut| 433 | /// |---|---|---|---|---| 434 | /// |0x1F23B8|0x5D6DCB|0xABCDEF|false|0x000000| 435 | crc24flexray_b, 436 | /// |Check|Poly|Init|Ref|XorOut| 437 | /// |---|---|---|---|---| 438 | /// |0xCDE703|0x864CFB|0x000000|false|0x000000| 439 | crc24lte_a, 440 | /// |Check|Poly|Init|Ref|XorOut| 441 | /// |---|---|---|---|---| 442 | /// |0x23EF52|0x800063|0x000000|false|0x000000| 443 | crc24lte_b, 444 | /// |Check|Poly|Init|Ref|XorOut| 445 | /// |---|---|---|---|---| 446 | /// |0x200FA5|0x800063|0xFFFFFF|false|0xFFFFFF| 447 | crc24os9, 448 | ); 449 | 450 | crc_functions_4!( 451 | /// |Check|Poly|Init|Ref|XorOut| 452 | /// |---|---|---|---|---| 453 | /// |0x04C34ABF|0x2030B9C7|0x3FFFFFFF|false|0x3FFFFFFF| 454 | crc30cdma, 455 | /// |Check|Poly|Init|Ref|XorOut| 456 | /// |---|---|---|---|---| 457 | /// |0xCBF43926|0x04C11DB7 (rev: 0xEDB88320)|0xFFFFFFFF|true|0xFFFFFFFF| 458 | crc32, 459 | /// |Check|Poly|Init|Ref|XorOut| 460 | /// |---|---|---|---|---| 461 | /// |0x181989FC|0x04C11DB7|0xFFFFFFFF|false|0xFFFFFFFF| 462 | crc32mhash, 463 | /// |Check|Poly|Init|Ref|XorOut| 464 | /// |---|---|---|---|---| 465 | /// |0xFC891918|0x04C11DB7|0xFFFFFFFF|false|0xFFFFFFFF| 466 | crc32bzip2, 467 | /// |Check|Poly|Init|Ref|XorOut| 468 | /// |---|---|---|---|---| 469 | /// |0xE3069283|0x1EDC6F41 (rev: 0x82F63B78)|0xFFFFFFFF|true|0xFFFFFFFF| 470 | crc32c, 471 | /// |Check|Poly|Init|Ref|XorOut| 472 | /// |---|---|---|---|---| 473 | /// |0x87315576|0xA833982B (rev: 0xD419CC15)|0xFFFFFFFF|true|0xFFFFFFFF| 474 | crc32d, 475 | /// |Check|Poly|Init|Ref|XorOut| 476 | /// |---|---|---|---|---| 477 | /// |0x0376E6E7|0x04C11DB7|0xFFFFFFFF|false|0x00000000| 478 | crc32mpeg2, 479 | /// |Check|Poly|Init|Ref|XorOut| 480 | /// |---|---|---|---|---| 481 | /// |0x765E7680|0x04C11DB7|0x00000000|false|0xFFFFFFFF| 482 | crc32posix, 483 | /// |Check|Poly|Init|Ref|XorOut| 484 | /// |---|---|---|---|---| 485 | /// |0x3010BF7F|0x814141AB|0x00000000|false|0x00000000| 486 | crc32q, 487 | /// |Check|Poly|Init|Ref|XorOut| 488 | /// |---|---|---|---|---| 489 | /// |0x340BC6D9|0x04C11DB7 (rev: 0xEDB88320)|0xFFFFFFFF|true|0x00000000| 490 | crc32jamcrc, 491 | /// |Check|Poly|Init|Ref|XorOut| 492 | /// |---|---|---|---|---| 493 | /// |0xBD0BE338|0x000000AF|0x00000000|false|0x00000000| 494 | crc32xfer, 495 | ); 496 | 497 | crc_functions_5!( 498 | /// |Check|Poly|Init|Ref|XorOut| 499 | /// |---|---|---|---|---| 500 | /// |0xD4164FC646|0x0004820009|0x0000000000|false|0xFFFFFFFFFF| 501 | crc40gsm, 502 | ); 503 | 504 | crc_functions_8!( 505 | /// |Check|Poly|Init|Ref|XorOut| 506 | /// |---|---|---|---|---| 507 | /// |0x6C40DF5F0B497347|0x42F0E1EBA9EA3693|0x0000000000000000|false|0x0000000000000000| 508 | crc64, 509 | /// |Check|Poly|Init|Ref|XorOut| 510 | /// |---|---|---|---|---| 511 | /// |0xB90956C775A41001|0x000000000000001B (rev: 0xD800000000000000)|0xFFFFFFFFFFFFFFFF|true|0xFFFFFFFFFFFFFFFF| 512 | crc64iso, 513 | /// |Check|Poly|Init|Ref|XorOut| 514 | /// |---|---|---|---|---| 515 | /// |0x62EC59E3F1A4F00A|0x42F0E1EBA9EA3693|0xFFFFFFFFFFFFFFFF|false|0xFFFFFFFFFFFFFFFF| 516 | crc64we, 517 | /// |Check|Poly|Init|Ref|XorOut| 518 | /// |---|---|---|---|---| 519 | /// |0xE9C6D914C4B8D9CA|0xAD93D23594C935A9 (rev: 0x95AC9329AC4BC9B5)|0x0000000000000000|true|0x0000000000000000| 520 | crc64jones, 521 | ); 522 | 523 | #[inline] 524 | fn u32_2_u64(low: u32, high: u32) -> u64 { 525 | ((high as u64) << 32) | (low as u64) 526 | } 527 | 528 | #[allow(clippy::too_many_arguments)] 529 | /// Create a CRC instance by providing the length of bits, expression, reflection, an initial value and a final xor value. 530 | #[napi] 531 | pub fn crc( 532 | poly_low: u32, 533 | poly_high: u32, 534 | bit: u8, 535 | initial_low: u32, 536 | initial_high: u32, 537 | final_xor_low: u32, 538 | final_xor_high: u32, 539 | reflect: bool, 540 | data: Buffer, 541 | ) -> Buffer { 542 | let poly = u32_2_u64(poly_low, poly_high); 543 | let initial = u32_2_u64(initial_low, initial_high); 544 | let final_xor = u32_2_u64(final_xor_low, final_xor_high); 545 | 546 | let crc = { 547 | let mut crc = CRC::create_crc(poly, bit, initial, final_xor, reflect); 548 | 549 | crc.digest(data.as_ref()); 550 | 551 | crc.get_crc_heapless_vec_be() 552 | }; 553 | 554 | Buffer::from(crc.to_vec()) 555 | } 556 | -------------------------------------------------------------------------------- /src/lib.ts: -------------------------------------------------------------------------------- 1 | export * from "../index.cjs"; 2 | -------------------------------------------------------------------------------- /tests/tests.test.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable camelcase */ 2 | 3 | import { 4 | crc, 5 | crc16, 6 | crc16ccitt_false, 7 | crc24, 8 | crc32, 9 | crc32c, 10 | crc32mhash, 11 | crc64, 12 | crc64iso, 13 | crc64jones, 14 | crc64we, 15 | crc8, 16 | crc8cdma2000, 17 | } from "../src/lib.js"; 18 | 19 | describe("CRC-8 Family", () => { 20 | it("should calculate CRC-8(CRC-8-ATM)", () => { 21 | const result = crc8(Buffer.from("hello", "utf8")).toString("hex"); 22 | expect(result).toBe("92"); 23 | }); 24 | 25 | it("should calculate CRC-8-CDMA", () => { 26 | const result = crc8cdma2000(Buffer.from("hello", "utf8")).toString( 27 | "hex", 28 | ); 29 | expect(result).toBe("4c"); 30 | }); 31 | }); 32 | 33 | describe("CRC-16 Family", () => { 34 | it("should calculate CRC-16(CRC-16-IBM)", () => { 35 | const result = crc16(Buffer.from("hello", "utf8")).toString("hex"); 36 | expect(result).toBe("34d2"); 37 | }); 38 | 39 | it("should calculate CRC-16-CCITT(CRC-CCITT)", () => { 40 | const result = crc16ccitt_false(Buffer.from("hello", "utf8")).toString( 41 | "hex", 42 | ); 43 | expect(result).toBe("d26e"); 44 | }); 45 | }); 46 | 47 | describe("CRC-24 Family", () => { 48 | it("should calculate CRC-24", () => { 49 | const result = crc24(Buffer.from("hello", "utf8")).toString("hex"); 50 | expect(result).toBe("47f58a"); 51 | }); 52 | 53 | it("should calculate CRC-24 (using poly)", () => { 54 | const result = crc( 55 | 0x00864cfb, 56 | 0x00000000, 57 | 24, 58 | 0x00b704ce, 59 | 0x00000000, 60 | 0x00000000, 61 | 0x00000000, 62 | false, 63 | Buffer.from("hello", "utf8"), 64 | ).toString("hex"); 65 | expect(result).toBe("47f58a"); 66 | }); 67 | }); 68 | 69 | describe("CRC-32 Family", () => { 70 | it("should calculate CRC-32(CRC-32-IEEE) which is also called crc32b in mhash library", () => { 71 | const result = crc32(Buffer.from("hello", "utf8")).toString("hex"); 72 | expect(result).toBe("3610a686"); 73 | }); 74 | 75 | it("should calculate crc32 according to the mhash library", () => { 76 | const result = crc32mhash(Buffer.from("hello", "utf8")).toString("hex"); 77 | expect(result).toBe("3d653119"); 78 | }); 79 | 80 | it("should calculate CRC-32-C", () => { 81 | const result = crc32c(Buffer.from("hello", "utf8")).toString("hex"); 82 | expect(result).toBe("9a71bb4c"); 83 | }); 84 | }); 85 | 86 | describe("CRC-64 Family", () => { 87 | it("should calculate CRC-64(CRC-64-ECMA)", () => { 88 | const result = crc64(Buffer.from("hello", "utf8")).toString("hex"); 89 | expect(result).toBe("40544a306137b6ec"); 90 | }); 91 | it("should calculate CRC-64-ISO", () => { 92 | const result = crc64iso(Buffer.from("hello", "utf8")).toString("hex"); 93 | expect(result).toBe("3c3eeee2d8100000"); 94 | }); 95 | it("should calculate CRC-64-WE", () => { 96 | const result = crc64we(Buffer.from("hello", "utf8")).toString("hex"); 97 | expect(result).toBe("ec5388479a7c913f"); 98 | }); 99 | it("should calculate CRC-64-JONES", () => { 100 | const result = crc64jones(Buffer.from("123456789", "utf8")).toString( 101 | "hex", 102 | ); 103 | expect(result).toBe("e9c6d914c4b8d9ca"); 104 | }); 105 | }); 106 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": [ 4 | "src/**/*", 5 | ], 6 | "exclude": [ 7 | "**/*.spec.ts", 8 | "**/*.test.ts" 9 | ] 10 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "ES2023", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "Node16", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | "moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | "outDir": "./lib", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | --------------------------------------------------------------------------------