Skip to content

Commit

Permalink
cleanup pr
Browse files Browse the repository at this point in the history
- revert unneeded changes in package.json
- revert files moved to src
- linting
  • Loading branch information
erikyo committed Apr 10, 2024
1 parent c367ef7 commit 143f973
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/node_modules
lib
/@types
npm-debug.log
.DS_Store
7 changes: 4 additions & 3 deletions src/index.d.ts → index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Transform } from "readable-stream";

import {Buffer} from "safe-buffer";

export declare module 'encoding' {
export function convert(buf: Buffer, charset: string): Buffer;
export function convert(buf: Buffer, toCharset: string, fromCharset: string): Buffer;
}

export interface Compiler {
Expand Down Expand Up @@ -37,13 +38,13 @@ export interface parserOptions {
validation?: boolean;
}

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

export interface MoParser {
export interface mo {
parse: (buffer: Buffer | string, defaultCharset?: string) => GetTextTranslations;
compile: (table: GetTextTranslations, options?: parserOptions) => Buffer;
}
14 changes: 7 additions & 7 deletions src/index.js → index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as poParser from './poparser.js';
import poCompiler from './pocompiler.js';
import moParser from './moparser.js';
import moCompiler from './mocompiler.js';
import * as poParser from './lib/poparser.js';
import poCompiler from './lib/pocompiler.js';
import moParser from './lib/moparser.js';
import moCompiler from './lib/mocompiler.js';

/**
* Translation parser and compiler for PO files
* @see https://www.gnu.org/software/gettext/manual/html_node/PO.html
*
* @type {import("./index.js").PoParser} po
* @type {import("./index.d.ts").po} po
*/
export const po = {
parse: poParser.parse,
Expand All @@ -19,9 +19,9 @@ export const po = {
* Translation parser and compiler for PO files
* @see https://www.gnu.org/software/gettext/manual/html_node/MO.html
*
* @type {import("./index.js").MoParser} mo
* @type {import("./index.d.ts").mo} mo
*/
export const mo= {
export const mo = {
parse: moParser,
compile: moCompiler
};
18 changes: 8 additions & 10 deletions src/mocompiler.js → lib/mocompiler.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Buffer } from 'safe-buffer';
import encoding from 'encoding';
import { compareMsgid, formatCharset, generateHeader, HEADERS } from './shared.js';
import { HEADERS, formatCharset, generateHeader, compareMsgid } from './shared.js';
import contentType from 'content-type';

/**
* Exposes general compiler function. Takes a translation
* object as a parameter and returns binary MO object
*
* @param {import('./index.js').gettextTranslations} table Translation object
* @param {import('./index.d.ts').GetTextTranslations} table Translation object
* @return {Buffer} Compiled binary MO object
*/
export default function (table) {
Expand All @@ -20,10 +20,10 @@ export default function (table) {
* Creates a MO compiler object.
*
* @constructor
* @param {import('./index.js').gettextTranslations} table Translation table as defined in the README
* @return {import('./index.js').Compiler} Compiler
* @param {import('./index.d.ts').GetTextTranslations} table Translation table as defined in the README
* @return {import('./index.d.ts').Compiler} Compiler
*/
function Compiler (table ) {
function Compiler (table = {}) {
this._table = table;

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

this._handleCharset();

return this;
}

/**
Expand Down Expand Up @@ -151,7 +149,7 @@ Compiler.prototype._generateList = function () {
/**
* Calculate buffer size for the final binary object
*
* @param {import('./index.js').GettextTranslations} list An array of translation strings from _generateList
* @param {import('./index.d.ts').GetTextTranslations} list An array of translation strings from _generateList
* @return {Object} Size data of {msgid, msgstr, total}
*/
Compiler.prototype._calculateSize = function (list) {
Expand Down Expand Up @@ -186,7 +184,7 @@ Compiler.prototype._calculateSize = function (list) {
/**
* Generates the binary MO object from the translation list
*
* @param {import('./index.js').GettextTranslations} list translation list
* @param {import('./index.d.ts').GetTextTranslations} list translation list
* @param {Object} size Byte size information
* @return {Buffer} Compiled MO object
*/
Expand Down Expand Up @@ -240,7 +238,7 @@ Compiler.prototype._build = function (list, size) {
};

/**
* Compiles the translation object into a binary MO object
* Compiles translation object into a binary MO object
*
* @return {Buffer} Compiled MO object
*/
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/pocompiler.js → lib/pocompiler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { compareMsgid, foldLine, formatCharset, generateHeader, HEADERS } from './shared.js';
import contentType from 'content-type';
import { Buffer } from 'safe-buffer';
import encoding from 'encoding';
import { HEADERS, foldLine, compareMsgid, formatCharset, generateHeader } from './shared.js';
import contentType from 'content-type';


/**
* Exposes general compiler function. Takes a translation
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 7 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@
"engines": {
"node": ">=18"
},
"files": [
"lib",
"test",
"*.json",
"*.md",
"license.txt"
],
"scripts": {
"start": "tsc --watch",
"build": "tsc",
"lint": "eslint src/*.js test/*.js",
"lint": "eslint lib/*.js test/*.js index.js",
"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",
"test": "mocha",
"preversion": "npm run lint && npm test",
"postversion": "git push && git push --tags"
"postversion": "git push && git push --tags",
"prepublish": "tsc && npm run lint && npm run test"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"main": "./index.js",
"license": "MIT",
"dependencies": {
"content-type": "^1.0.5",
Expand All @@ -46,15 +37,16 @@
"@types/chai": "latest",
"@types/content-type": "^1.1.8",
"@types/mocha": "latest",
"@types/readable-stream": "^4.0.11",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.14.0",
"chai": "^5.1.0",
"chai": "^5.0.3",
"eslint": "^8.56.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^10.4.0",
"mocha": "^10.3.0",
"typescript": "^5.4.4"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion test/mo-compiler-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chai from 'chai';
import { promisify } from 'util';
import path from 'path';
import { mo } from '../src/index.js';
import { mo } from '../index.js';
import { readFile as fsReadFile } from 'fs';
import { fileURLToPath } from 'url';

Expand Down
2 changes: 1 addition & 1 deletion test/mo-parser-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chai from 'chai';
import { promisify } from 'util';
import path from 'path';
import { mo } from '../src/index.js';
import { mo } from '../index.js';
import { readFile as fsReadFile } from 'fs';
import { fileURLToPath } from 'url';

Expand Down
2 changes: 1 addition & 1 deletion test/module.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { po, mo } from '../src/index.js';
import { po, mo } from '../index.js';

describe('esm module', () => {
it('should allow named imports', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/po-compiler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promisify } from 'util';
import path from 'path';
import { readFile as fsReadFile } from 'fs';
import * as chai from 'chai';
import { po } from '../src/index.js';
import { po } from '../index.js';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion test/po-obsolete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chai from 'chai';
import { promisify } from 'util';
import path from 'path';
import fs from 'fs';
import * as gettextParser from '../src/index.js';
import * as gettextParser from '../index.js';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion test/po-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as chai from 'chai';
import { promisify } from 'util';
import path from 'path';
import fs from 'fs';
import * as gettextParser from '../src/index.js';
import * as gettextParser from '../index.js';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as chai from 'chai';
import { promisify } from 'util';
import path from 'path';
import { formatCharset, parseHeader, generateHeader, foldLine, parseNPluralFromHeadersSafely } from '../src/shared.js';
import { formatCharset, parseHeader, generateHeader, foldLine, parseNPluralFromHeadersSafely } from '../lib/shared.js';
import { readFile as fsReadFile } from 'fs';
import { fileURLToPath } from 'url';

Expand Down
51 changes: 25 additions & 26 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
"compilerOptions": {
"noImplicitAny": true,
"removeComments": false,
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2021",
"declaration": true,
"emitDeclarationOnly": false,
"preserveConstEnums": true,
"sourceMap": true,
"strict": false,
"module": "Node16",
"moduleResolution": "Node16",
"target": "ES2015",

// Strict mode
"strict": true,

// Allow javascript files
"allowJs": true,
"downlevelIteration": true,
"esModuleInterop": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"rootDir": "src",
"outDir": "lib",

// Check js files for errors
"checkJs": false,

// Output d.ts files to @types
"outDir": "@types",

// Generate d.ts files
"declaration": true,

// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Minify
"pretty": false,
// types
"typeRoots": [
"src/types.d.ts",
"node_modules/@types",
"@types"
],
"lib": [
"dom",
"ESNext"
]
// Skip lib check when compiling
"skipLibCheck": true
},
"include": [
"./src/**/*"
"lib/**/*.js",
"index.d.ts"
]
}

0 comments on commit 143f973

Please sign in to comment.