@dxfom/text
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -11,2 +11,7 @@ export interface DxfTextContentElement { | ||
} | ||
export declare const parseDxfTextContent: (text: string) => DxfTextContentElement[]; | ||
export declare const decodeDxfTextCharacterCodes: (text: string, mbcsEncoding?: string | TextDecoder | undefined) => string; | ||
export declare const decodeDxfTextUnicodeCodePoints: (text: string) => string; | ||
export declare const decodeDxfTextMbcsCharacterCodes: (text: string, encoding: string | TextDecoder) => string; | ||
export declare const parseDxfTextContent: (text: string, options?: { | ||
readonly encoding?: string | TextDecoder | undefined; | ||
} | undefined) => DxfTextContentElement[]; |
20
index.ts
@@ -21,4 +21,20 @@ // https://knowledge.autodesk.com/ja/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2019/JPN/AutoCAD-Core/files/GUID-968CBC1D-BA99-4519-ABDD-88419EB2BF92-htm.html | ||
export const parseDxfTextContent = (text: string): DxfTextContentElement[] => { | ||
text = text.replace(/\\[uU]\+([0-9a-fA-F]{4})/g, (_, codePoint) => String.fromCodePoint(parseInt(codePoint, 16))) | ||
export const decodeDxfTextCharacterCodes = (text: string, mbcsEncoding?: string | TextDecoder) => { | ||
text = decodeDxfTextUnicodeCodePoints(text) | ||
return mbcsEncoding ? decodeDxfTextMbcsCharacterCodes(text, mbcsEncoding) : text | ||
} | ||
export const decodeDxfTextUnicodeCodePoints = (text: string) => | ||
text.replace(/\\[uU]\+([0-9a-fA-F]{4})/g, (_, codePoint) => String.fromCodePoint(parseInt(codePoint, 16))) | ||
export const decodeDxfTextMbcsCharacterCodes = (text: string, encoding: string | TextDecoder) => { | ||
let decoder: TextDecoder | undefined = encoding instanceof TextDecoder ? encoding : undefined | ||
return text.replace( | ||
/\\[mM]\+1([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g, | ||
(_, a, b) => (decoder = decoder || new TextDecoder(encoding as string)).decode(new Uint8Array([parseInt(a, 16), parseInt(b, 16)])) | ||
) | ||
} | ||
export const parseDxfTextContent = (text: string, options?: { readonly encoding?: string | TextDecoder }): DxfTextContentElement[] => { | ||
text = decodeDxfTextCharacterCodes(text, options?.encoding) | ||
let previousIndex = 0 | ||
@@ -25,0 +41,0 @@ let currentContent: DxfTextContentElement = { text: '' } |
{ | ||
"name": "@dxfom/text", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A low level DXF TEXT content parser.", | ||
@@ -16,5 +16,5 @@ "license": "GPL-3.0", | ||
"devDependencies": { | ||
"terser": "^4.6.10", | ||
"typescript": "^3.8.3" | ||
"terser": "^5.5.1", | ||
"typescript": "^4.1.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
40811
103
1