Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .buildconfig/fixup
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

cat << EOF > ./lib/cjs/package.json
{
"type": "commonjs"
}
EOF

cat << EOF > ./lib/mjs/package.json
{
"type": "module"
}
EOF
12 changes: 12 additions & 0 deletions .buildconfig/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../lib/cjs",
"target": "es2015"
},
"include": [
"../src",
"../index.ts"
]
}
8 changes: 6 additions & 2 deletions tsconfig.cli.json → .buildconfig/tsconfig.cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "dist"
}
"outDir": "../lib/cli"
},
"include": [
"../src",
"../index.ts"
]
}
7 changes: 5 additions & 2 deletions tsconfig.json → .buildconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"outDir": "lib"
"moduleResolution": "node"
},
"types": [
"node",
"jest"
],
"include": [
"../src",
"../index.ts"
]
}
12 changes: 12 additions & 0 deletions .buildconfig/tsconfig.mjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "../lib/mjs",
"target": "ESNext"
},
"include": [
"../src",
"../index.ts"
]
}
14 changes: 11 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Release

on:
push:
branches:
- master
tags:
- 'v*'

Expand All @@ -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

Expand All @@ -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 }}

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/test-on-pr.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
```
Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
37 changes: 29 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -39,7 +59,7 @@
"^.+\\.ts$": [
"ts-jest",
{
"tsconfig": "tsconfig.json"
"tsconfig": ".buildconfig/tsconfig.json"
}
]
},
Expand All @@ -55,5 +75,6 @@
"singleQuote": true,
"trailingComma": "all",
"semi": false
}
},
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
}
2 changes: 1 addition & 1 deletion src/suffix/__tests__/_smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/suffix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const suffix = {
high: 'be',
}),
),
insessive: createSuffixer(
inessive: createSuffixer(
createSuffixSelector({
low: 'ban',
high: 'ben',
Expand Down
79 changes: 79 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
declare module 'crumbjs' {
export type WordLike = string | RegExp | Array<string | RegExp>
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[]
}