Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Make back into a cjs package #6

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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.

2 changes: 1 addition & 1 deletion arrayStringMap.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from "chai"
import ArrayStringMap from "./arrayStringMap.js"
import ArrayStringMap from "./arrayStringMap"

type TwoNumberArray = [number, number]

Expand Down
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "esnext",
"module": "commonjs",
"target": "es2019",
"strict": true,
"allowJs": true,
Expand Down