-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "unicode", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "npm run clean && npm run build:src", | ||
"build:src": "tsx ./src/build.ts", | ||
"clean": "rimraf ./dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import path from "node:path" | ||
import fs from "fs-extra" | ||
|
||
import { fonts } from "yakuhanjp/project.json" assert { type: "json" } | ||
import { glyphs2unicodes } from "." | ||
|
||
async function main() { | ||
const cwd = process.cwd() | ||
const outPath = path.join(cwd, "dist", "data.json") | ||
const data = fonts.map((item) => { | ||
return { | ||
name: item.name, | ||
glyphs: { | ||
str: item.glyphs, | ||
unicode: glyphs2unicodes(item.glyphs), | ||
}, | ||
} | ||
}) | ||
await fs | ||
.outputJSON(outPath, data, { spaces: 2 }) | ||
.then(() => { | ||
console.log(outPath) | ||
}) | ||
.catch((err) => { | ||
console.error(err) | ||
}) | ||
} | ||
|
||
await main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import { glyph2unicode, glyphs2unicodes } from "." | ||
|
||
describe("glyph2unicode", () => { | ||
it("A", () => { | ||
const result = glyph2unicode("A") | ||
expect(result).toEqual("U+0041") | ||
}) | ||
it("、", () => { | ||
const result = glyph2unicode("、") | ||
expect(result).toEqual("U+3001") | ||
}) | ||
}) | ||
|
||
describe("glyphs2unicodes", () => { | ||
it("ABC", () => { | ||
const result = glyphs2unicodes("ABC") | ||
expect(result).toEqual("U+0041,U+0042,U+0043") | ||
}) | ||
it("、。!?", () => { | ||
const result = glyphs2unicodes("、。!?") | ||
expect(result).toEqual("U+3001,U+3002,U+ff01,U+ff1f") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function glyph2unicode(str: string) { | ||
const hexStr = "000" + str.charCodeAt(0).toString(16) | ||
return "U+" + hexStr.substring(hexStr.length - 4) | ||
} | ||
|
||
export function glyphs2unicodes(glyphs: string) { | ||
const splitedGlyphs = glyphs.split("") | ||
return splitedGlyphs | ||
.map((item) => glyph2unicode(item)) | ||
.sort() | ||
.join() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from "vitest/config" | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ["./packages/unicode/**/*.test.{ts,tsx}"], | ||
exclude: ["**/node_modules/**", "**/dist/**", "./playground/**/*.*"], | ||
testTimeout: 20000, | ||
}, | ||
}) |