diff --git a/.buildconfig/fixup b/.buildconfig/fixup new file mode 100755 index 0000000..a9233e3 --- /dev/null +++ b/.buildconfig/fixup @@ -0,0 +1,13 @@ +#!/bin/bash + +cat << EOF > ./lib/cjs/package.json +{ + "type": "commonjs" +} +EOF + +cat << EOF > ./lib/mjs/package.json +{ + "type": "module" +} +EOF diff --git a/.buildconfig/tsconfig.cjs.json b/.buildconfig/tsconfig.cjs.json new file mode 100644 index 0000000..de7a807 --- /dev/null +++ b/.buildconfig/tsconfig.cjs.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../lib/cjs", + "target": "es2015" + }, + "include": [ + "../src", + "../index.ts" + ] +} diff --git a/tsconfig.cli.json b/.buildconfig/tsconfig.cli.json similarity index 70% rename from tsconfig.cli.json rename to .buildconfig/tsconfig.cli.json index 8e7c89c..b48e8e0 100644 --- a/tsconfig.cli.json +++ b/.buildconfig/tsconfig.cli.json @@ -6,6 +6,10 @@ "module": "CommonJS", "moduleResolution": "node", "esModuleInterop": true, - "outDir": "dist" - } + "outDir": "../lib/cli" + }, + "include": [ + "../src", + "../index.ts" + ] } \ No newline at end of file diff --git a/tsconfig.json b/.buildconfig/tsconfig.json similarity index 69% rename from tsconfig.json rename to .buildconfig/tsconfig.json index 51d6e1e..ad69226 100644 --- a/tsconfig.json +++ b/.buildconfig/tsconfig.json @@ -4,11 +4,14 @@ "strict": true, "forceConsistentCasingInFileNames": true, "module": "commonjs", - "moduleResolution": "node", - "outDir": "lib" + "moduleResolution": "node" }, "types": [ "node", "jest" + ], + "include": [ + "../src", + "../index.ts" ] } diff --git a/.buildconfig/tsconfig.mjs.json b/.buildconfig/tsconfig.mjs.json new file mode 100644 index 0000000..b35f09a --- /dev/null +++ b/.buildconfig/tsconfig.mjs.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "outDir": "../lib/mjs", + "target": "ESNext" + }, + "include": [ + "../src", + "../index.ts" + ] +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8937e2c..aef8f74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,6 +2,8 @@ name: Release on: push: + branches: + - master tags: - 'v*' @@ -21,6 +23,12 @@ jobs: - name: Install dependencies run: npm ci + - name: Type check + run: npm run type-check + + - name: Test + run: npm test + - name: Build library run: npm run build @@ -42,9 +50,9 @@ jobs: draft: false prerelease: false files: | - bin/crumb-linux - bin/crumb-macos - bin/crumb-win.exe + bin/crumbjs-linux + bin/crumbjs-macos + bin/crumbjs-win.exe env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-on-pr.yml b/.github/workflows/test-on-pr.yml new file mode 100644 index 0000000..7dc00a7 --- /dev/null +++ b/.github/workflows/test-on-pr.yml @@ -0,0 +1,22 @@ +name: Run Tests on PR + +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test \ No newline at end of file diff --git a/README.md b/README.md index c7a21f2..0a2c54f 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ számos egyéb alapeszközt biztosít természetes mondatok generálásához. ## Telepítés -A teljes projekt telepítése: - ```bash -npm install crumb +npm install crumbjs ``` ## Használat @@ -18,7 +16,7 @@ npm install crumb A toldalékoláshoz használd a `suffix` metódust: ```javascript -import {suffix} from 'crumb'; +import {suffix} from 'crumbjs'; suffix.dative('kutya'); // "kutyának" ``` @@ -37,7 +35,7 @@ A csomag a következő toldalékokat támogatja: - `delative`: leható eset (-ról, -ről) - pl. `suffix.delative('tető')` → "tetőről" - `elative`: kiható eset (-ból, -ből) - pl. `suffix.elative('doboz')` → "dobozból" - `illative`: beható eset (-ba, -be) - pl. `suffix.illative('ház')` → "házba" -- `insessive`: bentlakó eset (-ban, -ben) - pl. `suffix.insessive('kert')` → "kertben" +- `inessive`: bentlakó eset (-ban, -ben) - pl. `suffix.inessive('kert')` → "kertben" - `sublative`: felható eset (-ra, -re) - pl. `suffix.sublative('asztal')` → "asztalra" - `superessive`: felülmaradó eset (-on, -en, -ön) - pl. `suffix.superessive('föld')` → "földön" - `terminative`: határvető eset (-ig) - pl. `suffix.terminative('sarok')` → "sarokig" @@ -67,13 +65,36 @@ A csomag a következő toldalékokat támogatja: A csomag támogatja a melléknevek fokozását is a `grade` objektumon keresztül: ```javascript -import {grade} from 'crumb'; +import {grade} from 'crumbjs'; grade.comparative('szép'); // "szebb" grade.superlative('szép'); // "legszebb" grade.excessive('szép'); // "legeslegszebb" ``` +## Számok szöveggé alakítása + +```javascript +import {getNumberWithWords} from 'crumbjs' + +getNumberWithWords('1625'); // "ezerhatszázhuszonöt" +getNumberWithWords('-13.4'); // "mínusz tizenhárom egész négy tized" +getNumberWithWords('48239845'); // "negyvennyolcmillió-kétszázharminckilencezer-nyolcszáznegyvenöt" +``` + +## Szótagolás + +```javascript +import {getSyllables} from 'crumbjs' + +getSyllables('kivirágozhat'); // ["ki", "vi", "rá", "goz", "hat"] +getSyllables('kellemetlenség'); // ["kel", "le", "met", "len", "ség"] + +// Nincs szótár, nem ismeri fel a szóhatárokat +getSyllables('kerítésszaggató', {stopWords: ["kerítés"], formatted: true}); // ke-rí-tés-szag-ga-tó +getSyllables('pánikroham', {formatted: true, hypenCharacter: '/'}); // pá/nik/ro/ham +``` + ##### Speciális esetek és kivételek A csomag kezeli a magyar nyelv speciális eseteit és kivételeit, például: @@ -86,13 +107,13 @@ A csomag kezeli a magyar nyelv speciális eseteit és kivételeit, például: ##### Példák ```javascript -import {suffix, grade} from 'crumb'; +import {suffix, grade} from 'crumbjs'; // Esetragok suffix.accusative('alma'); // "almát" suffix.dative('ház'); // "háznak" suffix.ablative('iskola'); // "iskolától" -suffix.insessive('doboz'); // "dobozban" +suffix.inessive('doboz'); // "dobozban" suffix.superessive('szék'); // "széken" // Többes szám diff --git a/package.json b/package.json index 3fbe184..bf75c82 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,24 @@ { "name": "crumbjs", "version": "1.0.0", - "main": "index.js", + "main": "lib/cjs/index.js", + "author": { + "name": "Péter Viola", + "email": "info@violapeter.hu", + "url": "https://violapeter.hu" + }, "license": "MIT", "scripts": { "test": "jest", - "build": "tsc", - "build:cli": "tsc --project tsconfig.cli.json", - "start": "node dist/src/cli/index.js", + "build": "tsc -p .buildconfig/tsconfig.mjs.json && tsc -p .buildconfig/tsconfig.cjs.json && .buildconfig/fixup", + "build:cli": "tsc --project .buildconfig/tsconfig.cli.json", + "start": "node ./lib/cli/src/cli/index.js", "dev": "ts-node ./src/cli/index.ts", - "package": "pkg . --out-path=bin" + "package": "pkg . --out-path=bin", + "type-check": "tsc -p .buildconfig/tsconfig.json --noEmit" }, "bin": { - "crumb": "dist/src/cli/index.js" + "crumb": "lib/cli/src/cli/index.js" }, "devDependencies": { "@types/jest": "^29.5.14", @@ -26,6 +32,20 @@ "commander": "^13.1.0", "typescript": "^5.8.3" }, + "module": "lib/mjs/index.js", + "exports": { + ".": { + "import": "./lib/mjs/index.js", + "require": "./lib/cjs/index.js" + } + }, + "types": "./types.d.ts", + "files": [ + "lib", + "src", + "index.ts", + "types.d.ts" + ], "pkg": { "targets": [ "node18-linux-x64", @@ -39,7 +59,7 @@ "^.+\\.ts$": [ "ts-jest", { - "tsconfig": "tsconfig.json" + "tsconfig": ".buildconfig/tsconfig.json" } ] }, @@ -55,5 +75,6 @@ "singleQuote": true, "trailingComma": "all", "semi": false - } + }, + "packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" } diff --git a/src/suffix/__tests__/_smoke.spec.ts b/src/suffix/__tests__/_smoke.spec.ts index a6ff81d..0681c81 100644 --- a/src/suffix/__tests__/_smoke.spec.ts +++ b/src/suffix/__tests__/_smoke.spec.ts @@ -15,7 +15,7 @@ const testData: Array<[string, string, string, SuffixerMethod]> = [ ['essiveFormal', 'kalapács', 'kalapácsként', suffix.essiveFormal], ['essiveModal', 'kalapács', 'kalapácsul', suffix.essiveModal], ['illative', 'kalapács', 'kalapácsba', suffix.illative], - ['insessive', 'kalapács', 'kalapácsban', suffix.insessive], + ['inessive', 'kalapács', 'kalapácsban', suffix.inessive], [ 'instrumentalComitative', 'kalapács', diff --git a/src/suffix/index.ts b/src/suffix/index.ts index e337a83..d6331fe 100644 --- a/src/suffix/index.ts +++ b/src/suffix/index.ts @@ -67,7 +67,7 @@ export const suffix = { high: 'be', }), ), - insessive: createSuffixer( + inessive: createSuffixer( createSuffixSelector({ low: 'ban', high: 'ben', diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 0000000..a6ea910 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,79 @@ +declare module 'crumbjs' { + export type WordLike = string | RegExp | Array + export type ExceptionHandler = string | ((string: string) => string) + export type Exception = [WordLike, ExceptionHandler] + export type SuffixerMethod = ( + word: string, + exceptions?: Exception[], + ) => string + + export type StopWord = string | RegExp + + export const suffix: { + accusative: SuffixerMethod + ablative: SuffixerMethod + adessive: SuffixerMethod + adjective: SuffixerMethod + allative: SuffixerMethod + finalCasual: SuffixerMethod + dative: SuffixerMethod + delative: SuffixerMethod + elative: SuffixerMethod + essiveFormal: SuffixerMethod + essiveModal: SuffixerMethod + illative: SuffixerMethod + inessive: SuffixerMethod + instrumentalComitative: SuffixerMethod + locative: SuffixerMethod + sublative: SuffixerMethod + superessive: SuffixerMethod + terminative: SuffixerMethod + translative: SuffixerMethod + privative: SuffixerMethod + plural: SuffixerMethod + genitive: SuffixerMethod + temporal: SuffixerMethod + sociative: SuffixerMethod + distributiveTemporal: SuffixerMethod + distributive: SuffixerMethod + formal: SuffixerMethod + modalEssive: SuffixerMethod + multiplicative: SuffixerMethod + frequentative: SuffixerMethod + } + + export const grade: { + comparative: SuffixerMethod + superlative: SuffixerMethod + excessive: SuffixerMethod + } + + export function getNumberWithWords(number: number): string + + export function getSyllables( + word: string, + options?: { + stopWords?: StopWord | StopWord[] + formatted?: true + hyphenCharacter?: string + }, + ): string + + export function getSyllables( + word: string, + options?: { + stopWords?: StopWord | StopWord[] + formatted?: false + hyphenCharacter?: string + }, + ): string[] + + export function getSyllables( + word: string, + options?: { + stopWords?: StopWord | StopWord[] + formatted?: boolean + hyphenCharacter?: string + }, + ): string | string[] +}