Skip to content

Commit

Permalink
Merge pull request #70 from p-chan/v4
Browse files Browse the repository at this point in the history
v4
  • Loading branch information
p-chan authored Apr 7, 2023
2 parents 082fbe4 + dfad0f3 commit 2ca4a1a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 21 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn
Expand All @@ -21,12 +24,15 @@ jobs:

test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ createTrip('##57414b5554454b41') // -> ' ◆sWERuZlbhs'
createTrip('#$4d45534849554d41') // -> ' ◆???'
```

:warning: Don't support string that cannot be converted to Shift_JIS (ex: Emoji)

## Author

[@p-chan](https://github.com/p-chan)
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"version:patch": "standard-version -r patch"
},
"dependencies": {
"encoding-japanese": "1.0.30",
"encoding-japanese": "2.0.0",
"unix-crypt-td-js": "1.1.4"
},
"devDependencies": {
"@stardust-configs/prettier-config": "0.1.1",
"@stardust-configs/tsconfig": "0.4.0",
"@types/encoding-japanese": "1.0.18",
"@types/encoding-japanese": "2.0.1",
"@types/node": "18.15.11",
"prettier": "2.8.7",
"rimraf": "4.4.1",
"standard-version": "9.5.0",
"typescript": "5.0.4",
"vitest": "0.29.8"
},
"engines": {
"node": ">=14"
}
}
2 changes: 1 addition & 1 deletion src/creators/10digits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import crypt from 'unix-crypt-td-js'
*/
export const create10DigitsTrip = (key: string) => {
const saltSuffixString = 'H.'
const encodedKeyString = convert(key, 'SJIS', 'UNICODE')
const encodedKeyString = convert(key, { from: 'UNICODE', to: 'SJIS', fallback: 'html-entity' })

const salt = `${encodedKeyString}${saltSuffixString}`
// 1 文字目から 2 文字を取得する
Expand Down
2 changes: 1 addition & 1 deletion src/creators/12digits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createHash } from 'crypto'
* 12 桁トリップを生成する
*/
export const create12DigitsTrip = (key: string) => {
const arrayBuffer = convert(key, { from: 'UNICODE', to: 'SJIS', type: 'arraybuffer' })
const arrayBuffer = convert(key, { from: 'UNICODE', to: 'SJIS', type: 'arraybuffer', fallback: 'html-entity' })
const byteArray = new Uint8Array(arrayBuffer)

return createHash('sha1').update(byteArray).digest().toString('base64').replace(/\+/g, '.').substr(0, 12)
Expand Down
12 changes: 10 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@ describe('10 Digits', () => {
expect(createTrip('#Jim')).toBe(' ◆ziib4d/boU')
})

test('The trip key include only multibyte characters', () => {
test('The trip key include only multibyte characters (hiragana)', () => {
expect(createTrip('#ひろゆき')).toBe(' ◆F7aSjnRHGU')
})

test('The trip key include only multibyte characters (emoji)', () => {
expect(createTrip('#🇯🇵')).toBe(' ◆K9zUBOq4IzsD')
})
})

describe('12 Digits', () => {
test('The trip key include only singlebyte characters', () => {
expect(createTrip('#N.T.Technology')).toBe(' ◆FG0WWassNUrw')
})

test('The trip key include only multibyte characters', () => {
test('The trip key include only multibyte characters (hiragana)', () => {
expect(createTrip('#パケットモンスター')).toBe(' ◆EZSPRAHOnqfS')
})

test('The trip key include only multibyte characters (emoji)', () => {
expect(createTrip('#🇯🇵🇯🇵')).toBe(' ◆pD8dlc9B7Wif')
})

test('The trip include dot', () => {
expect(createTrip('#ドットが入るトリ')).toBe(' ◆n2HxTwBby.Ar')
})
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const rawKeyPettern = /^#[0-9A-Fa-f]{16}[.\/0-9A-Za-z]{0,2}$/
const maskSpecialSymbols = (text: string) => text.replace(//g, '☆').replace(//g, '◇')

export const createTripByKey = (key: string) => {
const encodedKeyString = convert(key, 'SJIS', 'UNICODE')
const encodedKeyString = convert(key, { from: 'UNICODE', to: 'SJIS', fallback: 'html-entity' })

// 10 桁トリップ
if (encodedKeyString.length < 12) return create10DigitsTrip(key)
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==

"@types/encoding-japanese@1.0.18":
version "1.0.18"
resolved "https://registry.yarnpkg.com/@types/encoding-japanese/-/encoding-japanese-1.0.18.tgz#2e86cb46bbc88d7a42878e7a86af44aaf97754ca"
integrity sha512-tjfjChRDhI2gpbOhccj4O9txN7nLnZEWyFA3fPGO0VchGeH6FeogwNfXvEyuHM+SlKEc7Q+/kt1/4nRNgP8SeQ==
"@types/encoding-japanese@2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/encoding-japanese/-/encoding-japanese-2.0.1.tgz#e8d4aa894e99aa195ce7dc792c54a6c61d019f8a"
integrity sha512-JaCXs2HLniKY8xXeWlg8MAtd4iKhNh8LwutW3yDMWY4usEdTZ2va1x9kd8V3179OAIUTgGQVA63XJrHettpVFQ==

"@types/minimist@^1.2.0":
version "1.2.2"
Expand Down Expand Up @@ -691,10 +691,10 @@ emoji-regex@^9.2.2:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72"
integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==

encoding-japanese@1.0.30:
version "1.0.30"
resolved "https://registry.yarnpkg.com/encoding-japanese/-/encoding-japanese-1.0.30.tgz#537c4d62881767925d601acb4c79fb14db81703a"
integrity sha512-bd/DFLAoJetvv7ar/KIpE3CNO8wEuyrt9Xuw6nSMiZ+Vrz/Q21BPsMHvARL2Wz6IKHKXgb+DWZqtRg1vql9cBg==
encoding-japanese@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/encoding-japanese/-/encoding-japanese-2.0.0.tgz#fa0226e5469e7b5b69a04fea7d5481bd1fa56936"
integrity sha512-++P0RhebUC8MJAwJOsT93dT+5oc5oPImp1HubZpAuCZ5kTLnhuuBhKHj2jJeO/Gj93idPBWmIuQ9QWMe5rX3pQ==

error-ex@^1.3.1:
version "1.3.2"
Expand Down

0 comments on commit 2ca4a1a

Please sign in to comment.