diff --git a/README.md b/README.md index 2ad1cc8..fb0c63a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # array-string-map + ![node-current](https://img.shields.io/node/v/array-string-map) [![npm](https://img.shields.io/npm/v/array-string-map)](https://www.npmjs.com/package/array-string-map) [![npm](https://img.shields.io/npm/dt/array-string-map)](https://www.npmjs.com/package/array-string-map) @@ -9,4 +10,29 @@ A Map that internally encodes Arrays to strings so that two Arrays with the same ## Motivation -I was using a Map to store array values, and I kept on running into a bug where I could not get those values back. I got fed up, and then after some Googling, realized that array lookups will not work when two different arrays with the same elements are used (such as when I use array literal syntax to create them). My solution was to encode the values as string keys. +I was using a Map to store array values, and I kept on running into a bug where I could not get those values back. I got +fed up, and then after some Googling, realized that array lookups will not work when two different arrays with the same +elements are used (such as when I use array literal syntax to create them). My solution was to encode the values as +string keys. + +## Usage + +ESM modules or TypeScript scripts can just import the normal way, such as: + +```ts +import ArrayStringMap from 'array-string-map' +``` + +However, for CommonJS modules, you need to use the `require` function, such as: + +```js +const {default: ArrayStringMap} = require("./arrayStringMap") +``` + +## API + +### ArrayStringMap + +A class that implements the [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) +interface. All methods that can be used on a Map are available on the ArrayStringMap. + diff --git a/arrayStringMap.test.ts b/arrayStringMap.test.ts index 021656d..dfeb30a 100644 --- a/arrayStringMap.test.ts +++ b/arrayStringMap.test.ts @@ -1,5 +1,5 @@ import { assert } from "chai" -import ArrayStringMap from "./arrayStringMap.js" +import ArrayStringMap from "./arrayStringMap" type TwoNumberArray = [number, number] diff --git a/package-lock.json b/package-lock.json index 7c72f7f..b344849 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,23 @@ { "name": "array-string-map", - "version": "1.0.1", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "array-string-map", - "version": "1.0.1", + "version": "2.0.0", "license": "GNU General Public License v3.0", "devDependencies": { "@types/chai": "^4.3.0", "@types/mocha": "^9.0.0", + "@types/node": "^17.0.0", "chai": "^4.3.4", "mocha": "^9.1.3", "typescript": "^4.5.4" + }, + "engines": { + "node": ">=8.X.X" } }, "node_modules/@types/chai": { @@ -28,6 +32,12 @@ "integrity": "sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==", "dev": true }, + "node_modules/@types/node": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.0.tgz", + "integrity": "sha512-eMhwJXc931Ihh4tkU+Y7GiLzT/y/DBNpNtr4yU9O2w3SYBsr9NaOPhQlLKRmoWtI54uNwuo0IOUFQjVOTZYRvw==", + "dev": true + }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -1027,6 +1037,12 @@ "integrity": "sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==", "dev": true }, + "@types/node": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.0.tgz", + "integrity": "sha512-eMhwJXc931Ihh4tkU+Y7GiLzT/y/DBNpNtr4yU9O2w3SYBsr9NaOPhQlLKRmoWtI54uNwuo0IOUFQjVOTZYRvw==", + "dev": true + }, "@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", diff --git a/package.json b/package.json index d9fc8ec..c126d61 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "array-string-map", "version": "2.0.0", "description": "A Map that internally encodes Arrays to strings so that two Arrays with the same elements will return the same item.", - "type": "module", + "type": "commonjs", "main": "arrayStringMap.js", "types": "arrayStringMap.d.ts", "scripts": { @@ -29,6 +29,7 @@ "devDependencies": { "@types/chai": "^4.3.0", "@types/mocha": "^9.0.0", + "@types/node": "^17.0.0", "chai": "^4.3.4", "mocha": "^9.1.3", "typescript": "^4.5.4" diff --git a/tsconfig.json b/tsconfig.json index ea61249..ff2d5e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "module": "esnext", + "module": "commonjs", "target": "es2019", "strict": true, "allowJs": true,