-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
4 changed files
with
44 additions
and
18 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
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
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,26 @@ | ||
import asyncTransform from "./async-transform"; | ||
|
||
export interface Option { | ||
prefix: string; | ||
} | ||
|
||
function codepointsMetadata(file: any): Record<string, number> { | ||
return file.codepoints; | ||
} | ||
|
||
export default function symheader(option?: Partial<Option>) { | ||
return asyncTransform(async file => { | ||
const codepoints: Record<string, number> = codepointsMetadata(file); | ||
let content = '#pragma once\n\n'; | ||
const encoder = new TextEncoder(); | ||
for (let key in codepoints) { | ||
const cp: number = codepoints[key]; | ||
const value = Array.from(encoder.encode(String.fromCodePoint(cp))) | ||
.map(v => `\\x${v.toString(16)}`).join(''); | ||
const name = key.toUpperCase().replace(/[^0-9a-z_]/ig, '_'); | ||
content += `#define ${option.prefix}_SYMBOL_${name} "${value}"\n`; | ||
} | ||
file.contents = Buffer.from(content); | ||
file.extname = '.h'; | ||
}) | ||
} |