@@ -84,6 +84,12 @@ const writeFiles = function(options) {
8484 return ;
8585 }
8686 const dirMap = { } ;
87+
88+ const rootDir = path . resolve (
89+ __dirname , '..' ,
90+ 'output' , 'unicode-' + version
91+ ) ;
92+
8793 /**
8894 * A list of flatten (x, y) pairs,
8995 * where x is a codepoint, y := codepoint(z) - x,
@@ -101,10 +107,7 @@ const writeFiles = function(options) {
101107 const isNamesCanon = type == 'Names' && ! subType ;
102108 const isNameAliases = type == 'Names' && subType == 'name-aliases' ;
103109 const subdir = isNameAliases ? item . charAt ( 0 ) . toUpperCase ( ) + item . slice ( 1 ) : item ;
104- const dir = path . resolve (
105- __dirname , '..' ,
106- 'output' , 'unicode-' + version , type , subdir
107- ) ;
110+ const dir = path . resolve ( rootDir , type , subdir ) ;
108111 if (
109112 type == 'Bidi_Class' ||
110113 type == 'Bidi_Mirroring_Glyph' ||
@@ -147,6 +150,12 @@ const writeFiles = function(options) {
147150 path . resolve ( dir , 'index.js' ) ,
148151 output
149152 ) ;
153+ fs . writeFileSync (
154+ path . resolve ( dir , 'index.d.ts' ) ,
155+ type === 'Sequence_Property'
156+ ? `const data: string[];\nexport default data;`
157+ : `const aliasMap: Record<number, string[]>;\nexport default aliasMap;`
158+ ) ;
150159 return ;
151160 }
152161
@@ -159,10 +168,18 @@ const writeFiles = function(options) {
159168 path . resolve ( dir , 'ranges.js' ) ,
160169 `module.exports=require('../../decode-ranges.js')('${ encodedRanges } ')`
161170 ) ;
171+ fs . writeFileSync (
172+ path . resolve ( dir , 'ranges.d.ts' ) ,
173+ 'import type { UnicodeRange } from "../../decode-ranges.js";\n\nconst ranges: UnicodeRange[];\nexport default ranges;\n'
174+ ) ;
162175 fs . writeFileSync (
163176 path . resolve ( dir , 'regex.js' ) ,
164177 'module.exports=/' + regenerate ( codePoints ) . toString ( ) + '/'
165178 ) ;
179+ fs . writeFileSync (
180+ path . resolve ( dir , 'regex.d.ts' ) ,
181+ 'declare const regex: RegExp;\nexport default regex;'
182+ ) ;
166183 if ( codePointsSizeLt ( codePoints , 10 ) ) {
167184 const codePointsAsArray = codePoints instanceof regenerate ? codePoints . toArray ( ) : codePoints ;
168185 codePointsExports = jsesc ( codePointsAsArray ) ;
@@ -186,10 +203,18 @@ const writeFiles = function(options) {
186203 path . resolve ( dir , 'code-points.js' ) ,
187204 `module.exports=${ codePointsExports } `
188205 ) ;
206+ fs . writeFileSync (
207+ path . resolve ( dir , 'code-points.d.ts' ) ,
208+ `declare const codePoints: number[];\nexport default codePoints;`
209+ ) ;
189210 fs . writeFileSync (
190211 path . resolve ( dir , 'symbols.js' ) ,
191212 `module.exports=${ symbolsExports } `
192213 ) ;
214+ fs . writeFileSync (
215+ path . resolve ( dir , 'symbols.d.ts' ) ,
216+ `declare const symbols: string[];\nexport default symbols;`
217+ ) ;
193218 } ) ;
194219 if ( options . type == 'Bidi_Mirroring_Glyph' ) {
195220 const type = options . type ;
@@ -214,6 +239,10 @@ const writeFiles = function(options) {
214239 path . resolve ( dir , 'index.js' ) ,
215240 output
216241 ) ;
242+ fs . writeFileSync (
243+ path . resolve ( dir , 'index.d.ts' ) ,
244+ `const data: Map<number, string>;\nexport default data;`
245+ ) ;
217246 } else {
218247 Object . keys ( auxMap ) . forEach ( function ( type ) {
219248 const dir = path . resolve (
@@ -233,6 +262,7 @@ const writeFiles = function(options) {
233262 flatRuns
234263 ) } )`;
235264 fs . writeFileSync ( path . resolve ( dir , "index.js" ) , output ) ;
265+ fs . writeFileSync ( path . resolve ( dir , "index.d.ts" ) , `declare const map: Map<number, string>;\nexport default map;` ) ;
236266 } ) ;
237267 }
238268 return dirMap ;
0 commit comments