Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Make back into a cjs package#6

Merged
PythonCoderAS merged 1 commit intomasterfromcjs
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionarrayStringMap.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionspackage-lock.json
View file
Open in desktop

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

3 changes: 2 additions & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletiontsconfig.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "esnext",
"module": "commonjs",
"target": "es2019",
"strict": true,
"allowJs": true,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp