Skip to content

Commit

Permalink
Fix style issues and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
BenOvermyer committed Jan 25, 2024
1 parent 9491bc7 commit a80f269
Show file tree
Hide file tree
Showing 31 changed files with 2,020 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.DS_Store
*.log
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright © 2023 Ben Overmyer <ben@overmyer.net>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

This is a library for generating random fictional words.

It exports the following:

- `allElements`: A constant array of `WordElementSet` objects. Used internally, but exported in case you need a reference.
- `WordElementSet`: A class for describing parts of a word. Used internally.
- `WordGenerator`: The main tool of this package. Has a single parameter `patterns` that it uses to generate a word via the method `generate()`. It always generates one string result based on the patterns given.
Documentation is available [here](https://ironarachne.github.io/word-generator).
15 changes: 15 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"indentStyle": "space"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
6 changes: 6 additions & 0 deletions dist/elements.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
import WordElementSet from "./elementset.js";
/**
* All available word elements. These are used in constructing patterns for word generation.
*
* @type {WordElementSet[]}
* @since 1.0.0
*/
export declare const allElements: WordElementSet[];
7 changes: 6 additions & 1 deletion dist/elements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"use strict";
import WordElementSet from "./elementset.js";
/**
* All available word elements. These are used in constructing patterns for word generation.
*
* @type {WordElementSet[]}
* @since 1.0.0
*/
export const allElements = [
new WordElementSet("affricates", "a", ["ch", "j"]),
new WordElementSet("voiced dental plosive", "b", ["d", "dh"]),
Expand Down
17 changes: 17 additions & 0 deletions dist/elementset.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* WordElementSet class
*
* @since 1.0.0
* @class
* @classdesc Represents a set of word elements.
* @property {string} name The name of the set.
* @property {string} symbol The symbol used to represent the set in word patterns.
* @property {string[]} elements The written elements in the set.
*
* @example
* ```typescript
* import { WordElementSet } from "@ironarachne/word-generator";
*
* const set = new WordElementSet("affricates", "a", ["ch", "j"]);
* ```
*/
export default class WordElementSet {
name: string;
symbol: string;
Expand Down
18 changes: 17 additions & 1 deletion dist/elementset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
'use strict';
/**
* WordElementSet class
*
* @since 1.0.0
* @class
* @classdesc Represents a set of word elements.
* @property {string} name The name of the set.
* @property {string} symbol The symbol used to represent the set in word patterns.
* @property {string[]} elements The written elements in the set.
*
* @example
* ```typescript
* import { WordElementSet } from "@ironarachne/word-generator";
*
* const set = new WordElementSet("affricates", "a", ["ch", "j"]);
* ```
*/
export default class WordElementSet {
constructor(name, symbol, elements) {
this.name = name;
Expand Down
16 changes: 16 additions & 0 deletions dist/generator.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* A word generator.
*
* @remarks After initializing the word generator by adding patterns to the internal patterns array, you can generate words by calling the generate method.
*
* @example Generating a word
* ```typescript
* import { WordGenerator } from "@ironarachne/word-generator";
*
* const generator = new WordGenerator();
* generator.patterns.push("vccv");
* generator.patterns.push("vccvc");
*
* const word = generator.generate();
* ```
*/
export default class WordGenerator {
patterns: string[];
constructor();
Expand Down
31 changes: 23 additions & 8 deletions dist/generator.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
"use strict";
import * as RND from "@ironarachne/rng";
import { allElements } from "./elements.js";
/**
* A word generator.
*
* @remarks After initializing the word generator by adding patterns to the internal patterns array, you can generate words by calling the generate method.
*
* @example Generating a word
* ```typescript
* import { WordGenerator } from "@ironarachne/word-generator";
*
* const generator = new WordGenerator();
* generator.patterns.push("vccv");
* generator.patterns.push("vccvc");
*
* const word = generator.generate();
* ```
*/
export default class WordGenerator {
constructor() {
this.patterns = [];
}
generate() {
let pattern = RND.item(this.patterns);
const pattern = RND.item(this.patterns);
let word = "";
let phonemes = [];
const phonemes = [];
for (let i = 0; i < pattern.length; i++) {
let phoneme = pattern[i];
if (pattern[i] === "+") {
phoneme = phonemes[i - 1];
}
else if (pattern[i] == "(") {
else if (pattern[i] === "(") {
i++;
let parts = [];
const parts = [];
let foundEnd = false;
let part = "";
while (!foundEnd) {
if (pattern[i] == ")") {
if (pattern[i] === ")") {
foundEnd = true;
parts.push(part);
}
else if (pattern[i] == ",") {
else if (pattern[i] === ",") {
parts.push(part);
part = "";
i++;
Expand All @@ -34,7 +49,7 @@ export default class WordGenerator {
i++;
}
}
let element = RND.item(parts);
const element = RND.item(parts);
phoneme = "";
for (let j = 0; j < element.length; j++) {
phoneme += parsePatternElement(element[j]);
Expand Down
1 change: 0 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use strict";
export { allElements } from "./elements.js";
export { default as WordElementSet } from "./elementset.js";
export { default as WordGenerator } from "./generator.js";
1 change: 1 addition & 0 deletions docs/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
71 changes: 71 additions & 0 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
:root {
--light-hl-0: #AF00DB;
--dark-hl-0: #C586C0;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #001080;
--dark-hl-2: #9CDCFE;
--light-hl-3: #A31515;
--dark-hl-3: #CE9178;
--light-hl-4: #0000FF;
--dark-hl-4: #569CD6;
--light-hl-5: #0070C1;
--dark-hl-5: #4FC1FF;
--light-hl-6: #795E26;
--dark-hl-6: #DCDCAA;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}

@media (prefers-color-scheme: light) { :root {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--code-background: var(--light-code-background);
} }

@media (prefers-color-scheme: dark) { :root {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--code-background: var(--dark-code-background);
} }

:root[data-theme='light'] {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--code-background: var(--light-code-background);
}

:root[data-theme='dark'] {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--code-background: var(--dark-code-background);
}

.hl-0 { color: var(--hl-0); }
.hl-1 { color: var(--hl-1); }
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
pre, code { background: var(--code-background); }
59 changes: 59 additions & 0 deletions docs/assets/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a80f269

Please sign in to comment.