Skip to content

Commit c0d9561

Browse files
committed
cleanup pr
- revert unneeded changes in package.json - revert files moved to src
1 parent c367ef7 commit c0d9561

18 files changed

+83
-91
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/node_modules
2-
lib
2+
/@types
33
npm-debug.log
44
.DS_Store

src/index.d.ts renamed to index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Transform } from "readable-stream";
2+
23
import {Buffer} from "safe-buffer";
34

45
export declare module 'encoding' {
5-
export function convert(buf: Buffer, charset: string): Buffer;
6+
export function convert(buf: Buffer, toCharset: string, fromCharset: string): Buffer;
67
}
78

89
export interface Compiler {
@@ -37,13 +38,13 @@ export interface parserOptions {
3738
validation?: boolean;
3839
}
3940

40-
export interface PoParser {
41+
export interface po {
4142
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
4243
compile: (table: GetTextTranslations, options?: parserOptions) => Buffer;
4344
createParseStream: (options?: parserOptions, transformOptions?: import('readable-stream').TransformOptions) => Transform;
4445
}
4546

46-
export interface MoParser {
47+
export interface mo {
4748
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
4849
compile: (table: GetTextTranslations, options?: parserOptions) => Buffer;
4950
}

index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as poParser from './lib/poparser.js';
2+
import poCompiler from './lib/pocompiler.js';
3+
import moParser from './lib/moparser.js';
4+
import moCompiler from './lib/mocompiler.js';
5+
6+
/**
7+
* Translation parser and compiler for PO files
8+
* @see https://www.gnu.org/software/gettext/manual/html_node/PO.html
9+
*
10+
* @type {import("./index.d.ts").po} po
11+
*/
12+
export const po = {
13+
parse: poParser.parse,
14+
createParseStream: poParser.stream,
15+
compile: poCompiler
16+
};
17+
18+
/**
19+
* Translation parser and compiler for PO files
20+
* @see https://www.gnu.org/software/gettext/manual/html_node/MO.html
21+
*
22+
* @type {import("./index.d.ts").mo} mo
23+
*/
24+
export const mo = {
25+
parse: moParser,
26+
compile: moCompiler
27+
};

src/mocompiler.js renamed to lib/mocompiler.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Buffer } from 'safe-buffer';
22
import encoding from 'encoding';
3-
import { compareMsgid, formatCharset, generateHeader, HEADERS } from './shared.js';
3+
import { HEADERS, formatCharset, generateHeader, compareMsgid } from './shared.js';
44
import contentType from 'content-type';
55

66
/**
77
* Exposes general compiler function. Takes a translation
88
* object as a parameter and returns binary MO object
99
*
10-
* @param {import('./index.js').gettextTranslations} table Translation object
10+
* @param {import('./index.d.ts').GetTextTranslations} table Translation object
1111
* @return {Buffer} Compiled binary MO object
1212
*/
1313
export default function (table) {
@@ -20,10 +20,10 @@ export default function (table) {
2020
* Creates a MO compiler object.
2121
*
2222
* @constructor
23-
* @param {import('./index.js').gettextTranslations} table Translation table as defined in the README
24-
* @return {import('./index.js').Compiler} Compiler
23+
* @param {import('./index.d.ts').GetTextTranslations} table Translation table as defined in the README
24+
* @return {import('./index.d.ts').Compiler} Compiler
2525
*/
26-
function Compiler (table ) {
26+
function Compiler (table = {}) {
2727
this._table = table;
2828

2929
let { headers = {}, translations = {} } = this._table;
@@ -71,8 +71,6 @@ function Compiler (table ) {
7171
this._writeFunc = 'writeUInt32LE';
7272

7373
this._handleCharset();
74-
75-
return this;
7674
}
7775

7876
/**
@@ -151,7 +149,7 @@ Compiler.prototype._generateList = function () {
151149
/**
152150
* Calculate buffer size for the final binary object
153151
*
154-
* @param {import('./index.js').GettextTranslations} list An array of translation strings from _generateList
152+
* @param {import('./index.d.ts').GetTextTranslations} list An array of translation strings from _generateList
155153
* @return {Object} Size data of {msgid, msgstr, total}
156154
*/
157155
Compiler.prototype._calculateSize = function (list) {
@@ -186,7 +184,7 @@ Compiler.prototype._calculateSize = function (list) {
186184
/**
187185
* Generates the binary MO object from the translation list
188186
*
189-
* @param {import('./index.js').GettextTranslations} list translation list
187+
* @param {import('./index.d.ts').GetTextTranslations} list translation list
190188
* @param {Object} size Byte size information
191189
* @return {Buffer} Compiled MO object
192190
*/
@@ -240,7 +238,7 @@ Compiler.prototype._build = function (list, size) {
240238
};
241239

242240
/**
243-
* Compiles the translation object into a binary MO object
241+
* Compiles translation object into a binary MO object
244242
*
245243
* @return {Buffer} Compiled MO object
246244
*/
File renamed without changes.

src/pocompiler.js renamed to lib/pocompiler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { compareMsgid, foldLine, formatCharset, generateHeader, HEADERS } from './shared.js';
2-
import contentType from 'content-type';
1+
import { Buffer } from 'safe-buffer';
32
import encoding from 'encoding';
3+
import { HEADERS, foldLine, compareMsgid, formatCharset, generateHeader } from './shared.js';
4+
import contentType from 'content-type';
5+
46

57
/**
68
* Exposes general compiler function. Takes a translation
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,15 @@
1717
"engines": {
1818
"node": ">=18"
1919
},
20-
"files": [
21-
"lib",
22-
"test",
23-
"*.json",
24-
"*.md",
25-
"license.txt"
26-
],
2720
"scripts": {
28-
"start": "tsc --watch",
29-
"build": "tsc",
30-
"lint": "eslint src/*.js test/*.js",
21+
"lint": "eslint lib/*.js test/*.js index.js",
3122
"test-generate-mo": "msgfmt test/fixtures/latin13.po -o test/fixtures/latin13.mo & msgfmt test/fixtures/utf8.po -o test/fixtures/utf8.mo & msgfmt test/fixtures/obsolete.po -o test/fixtures/obsolete.mo",
3223
"test": "mocha",
3324
"preversion": "npm run lint && npm test",
34-
"postversion": "git push && git push --tags"
25+
"postversion": "git push && git push --tags",
26+
"prepublish": "tsc && npm run lint && npm run test"
3527
},
36-
"main": "./lib/index.js",
37-
"types": "./lib/index.d.ts",
28+
"main": "./index.js",
3829
"license": "MIT",
3930
"dependencies": {
4031
"content-type": "^1.0.5",
@@ -46,15 +37,16 @@
4637
"@types/chai": "latest",
4738
"@types/content-type": "^1.1.8",
4839
"@types/mocha": "latest",
40+
"@types/readable-stream": "^4.0.11",
4941
"@typescript-eslint/eslint-plugin": "^6.18.1",
5042
"@typescript-eslint/parser": "^6.14.0",
51-
"chai": "^5.1.0",
43+
"chai": "^5.0.3",
5244
"eslint": "^8.56.0",
5345
"eslint-config-standard": "^17.1.0",
5446
"eslint-plugin-import": "^2.29.1",
5547
"eslint-plugin-n": "^16.6.2",
5648
"eslint-plugin-promise": "^6.1.1",
57-
"mocha": "^10.4.0",
49+
"mocha": "^10.3.0",
5850
"typescript": "^5.4.4"
5951
},
6052
"keywords": [

src/index.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)