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.

Commit81ae149

Browse files
committed
Make back into a cjs package
1 parent2b30852 commit81ae149

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

‎README.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#array-string-map
2+
23
![node-current](https://img.shields.io/node/v/array-string-map)
34
[![npm](https://img.shields.io/npm/v/array-string-map)](https://www.npmjs.com/package/array-string-map)
45
[![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
910

1011
##Motivation
1112

12-
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.
13+
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
14+
fed up, and then after some Googling, realized that array lookups will not work when two different arrays with the same
15+
elements are used (such as when I use array literal syntax to create them). My solution was to encode the values as
16+
string keys.
17+
18+
##Usage
19+
20+
ESM modules or TypeScript scripts can just import the normal way, such as:
21+
22+
```ts
23+
importArrayStringMapfrom'array-string-map'
24+
```
25+
26+
However, for CommonJS modules, you need to use the`require` function, such as:
27+
28+
```js
29+
const {default:ArrayStringMap}=require("./arrayStringMap")
30+
```
31+
32+
##API
33+
34+
###ArrayStringMap
35+
36+
A class that implements the[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
37+
interface. All methods that can be used on a Map are available on the ArrayStringMap.
38+

‎arrayStringMap.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{assert}from"chai"
2-
importArrayStringMapfrom"./arrayStringMap.js"
2+
importArrayStringMapfrom"./arrayStringMap"
33

44
typeTwoNumberArray=[number,number]
55

‎package-lock.json‎

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name":"array-string-map",
33
"version":"2.0.0",
44
"description":"A Map that internally encodes Arrays to strings so that two Arrays with the same elements will return the same item.",
5-
"type":"module",
5+
"type":"commonjs",
66
"main":"arrayStringMap.js",
77
"types":"arrayStringMap.d.ts",
88
"scripts": {
@@ -29,6 +29,7 @@
2929
"devDependencies": {
3030
"@types/chai":"^4.3.0",
3131
"@types/mocha":"^9.0.0",
32+
"@types/node":"^17.0.0",
3233
"chai":"^4.3.4",
3334
"mocha":"^9.1.3",
3435
"typescript":"^4.5.4"

‎tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module":"esnext",
3+
"module":"commonjs",
44
"target":"es2019",
55
"strict":true,
66
"allowJs":true,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp