1.0.3 β€’ Published 3 years ago

korean-random-words v1.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

TLDR: I needed a quick not-so-boring random generator with several million combinations.

  • 🌏 View README in... korean-badge | korean-badge

πŸ“ƒ Overview

korean-random-words generates a 3-word phrase in the general form of [adjective][suffix]-[adjective]ν•œ-[noun] , such as λΎ°μ‘±ν•˜κ³ -μš©κ°ν•œ-선인μž₯. Using default properties, the randomly generated phrase with the form above will be one of 256^3 * 5 = 83,886,080 possible phrases, with (currently) 256 nouns, 256 adjectives, and 5 variations of the suffix for the first adjective.

As a disclaimer, the package is not designed with cryptographycally secure randomness in mind.


✨ Demo

Coming Soon


πŸ’Ύ Install

npm install korean-random-words # npm
yarn add korean-random-words # yarn

🧠 Usage

// ES6
import PhraseGen from 'korean-random-words';
const phraseGen = new PhraseGen();

// Node
var PhraseGen = require('korean-random-words');
var phraseGen = new PhraseGen();

phraseGen.generatePhrase(); // 'μœ μ‹ν•˜κ³ -λ§λž‘ν•œ-ν•΄μ‚Ό'

constructor

The constructor takes an object with 4 optional properties:

  • adjSuffix: string - customizable suffix for the first adjective.
    • default: 'ν•˜κ³ ' | 'ν•˜μ§€λ§Œ' | 'ν•œλ°' | '해도' | 'ν•΄μ„œ' and is randomized upon each call.
    • example: { adjSuffix: '헸어도' } //would create 'λ¬΄μ‹¬ν–ˆμ–΄λ„-μ°©ν•œ-μ˜€μ†Œλ¦¬'
  • delimiter: string - overrides default delimiter to the provided string(conventionally a character)
    • default: '-'
    • example: { delimiter: '__' } // would create 'μ§„μ§€ν•˜κ³ __ꡉμž₯ν•œ__감자'
  • customNouns: string - custom set of nouns to randomize the phrase from
    • default: a word bank of common nouns
    • example: { customNouns: ['ν‚€λ³΄λ“œ','마우슀','μ›ΉμΊ ','λͺ¨λ‹ˆν„°'] }
  • customAdjectives: string - custom set of adjectives to randomize the phrase from
    • default: a word bank of common adjectives
    • *The form of adjectives should be words that are compatible with the form of -ν•˜λ‹€ without the suffix, in order to keep the phrase gramatically accurate, as shown in the example below:
    • example: { customNouns: ['λ‹Ήλ‹Ή','μ†Œμ‹¬','건듀건듀','μœ„λŒ€'] }

Below are some examples of constructing the phrase generator:

import PhraseGen from 'korean-random-words';

// default constructor
const phraseGen = new PhraseGen();
phraseGen.generatePhrase(); // 'μœ μ‹ν•˜κ³ -λ§λž‘ν•œ-ν•΄μ‚Ό'

// partial object
const phraseGen = new PhraseGen({
  delimiter: '__',
  adjSuffix: 'ν–ˆμ–΄λ„'
});
phraseGen.generatePhrase(); // 'μœ μ‹ν–ˆμ–΄λ„__λ§λž‘ν•œ__ν•΄μ‚Ό'

// pass in configuration
const phraseGenConfig = {
  customNouns: ['ν‚€λ³΄λ“œ','마우슀','μ›ΉμΊ ','λͺ¨λ‹ˆν„°'],
  customAdjectives: ['λ‹Ήλ‹Ή','μ†Œμ‹¬','건듀건듀','μœ„λŒ€'],
  delimiter: '__',
  adjSuffix: 'ν–ˆμ–΄λ„'
};
const phraseGen = new PhraseGen(phraseGenConfig);
phraseGen.generatePhrase(); // 'μ†Œμ‹¬ν–ˆμ–΄λ„__μœ„λŒ€ν•œ__λͺ¨λ‹ˆν„°'

generatePhrase: string

  • returns a generated phrase with the supplied configurations
const phraseGenConfig = { /* optional configs */ }
const phraseGen = new PhraseGen(phraseGenConfig);
phraseGen.generatePhrase(); // 'μ†Œμ‹¬ν–ˆμ–΄λ„__μœ„λŒ€ν•œ__λͺ¨λ‹ˆν„°'

getNoun: string

  • returns a random noun, either from the default noun bank or the supplied list of custom nouns
const phraseGen = new PhraseGen();
phraseGen.getNoun(); // κ³ μŠ΄λ„μΉ˜ | 땅콩 | 였이, ...

const customPhraseGen = new PhraseGen({ customNouns: ['보라돌이', 'λšœλΉ„', 'λ‚˜λ‚˜', 'λ½€'] });
phraseGen.getNoun(); // 보라돌이 | λšœλΉ„ | λ‚˜λ‚˜ | λ½€

getAdjective: string

getAdjective() takes one optional parameter:

  • suffix: string - optional override on the suffix for the adjective
    • default: 'ν•˜λ‹€'
  • returns a random adjective in the form of [adjective][suffix] // ex) 'μ˜ˆλ¦¬ν•˜λ‹€'
const phraseGen = new PhraseGen();
phraseGen.getAdjective(); // λ‹Ήλ‹Ήν•˜λ‹€, ꡉμž₯ν•˜λ‹€, λŒ€λ‹¨ν•˜λ‹€
phraseGen.getAdjective("ν•΄μš”"); // λ‹Ήλ‹Ήν•΄μš”, ꡉμž₯ν•΄μš”, λŒ€λ‹¨ν•΄μš”

const customPhraseGen = new PhraseGen({ customAdjectives: ['발그레','λˆ„λ¦¬λΌλ¦¬','κ±°λ¬΄μŠ€λ¦„'] });
phraseGen.getAdjective(); // λ°œκ·Έλ ˆν•˜λ‹€ | λˆ„λ¦¬λΌλ¦¬ν•˜λ‹€ | κ±°λ¬΄μŠ€λ¦„ν•˜λ‹€

set

used to reconfigure one or more properties of the phrase generator object. Takes in one Object as parameter with optional properties as below:

  • adjSuffix: string - customizable suffix for the first adjective.

    • example: { adjSuffix: '헸어도' } //would create 'λ¬΄μ‹¬ν–ˆμ–΄λ„-μ°©ν•œ-μ˜€μ†Œλ¦¬'
  • delimiter: string - overrides default delimiter to the provided string(conventionally a character)

    • example: { delimiter: '__' } // would create 'μ§„μ§€ν•˜κ³ __ꡉμž₯ν•œ__감자'
  • nouns: string - custom set of nouns to randomize the phrase from

    • example: { customNouns: ['ν‚€λ³΄λ“œ','마우슀','μ›ΉμΊ ','λͺ¨λ‹ˆν„°'] }
  • adjectives: string - custom set of adjectives to randomize the phrase from

    • *The form of adjectives should be words that are compatible with the form of -ν•˜λ‹€ without the suffix, in order to keep the phrase gramatically accurate, as shown in the example below:
    • example: { customNouns: ['λ‹Ήλ‹Ή','μ†Œμ‹¬','건듀건듀','μœ„λŒ€'] }
const phraseGen = new PhraseGen();
phraseGen.generatePhrase(); // μ ν•©ν•˜κ³ -μ§„μ§€ν•œ-상좔

// Valid #1
phraseGen.set({ delimiter: '__' , adjSuffix: 'ν•˜μ§€λ§Œ'});
phraseGen.generatePhrase(); // λ‹¨λ‹¨ν•˜μ§€λ§Œ__상λƒ₯ν•œ__ν˜Έλ‘

// Valid #2
const config = {
  adjSuffix: 'ν•˜μ§€λ§Œ',
  nouns: ['개발자', 'λ§€λ‹ˆμ €', 'λ””μžμ΄λ„ˆ'],
  adjectives: ['λΆ€μ§€λŸ°','μ„±μ‹€','λ‚˜νƒœ','유λŠ₯'],
  delimiter: '..'
};
phraseGen.set(config);
phraseGen.generatePhrase(); // λ‚˜νƒœν•˜μ§€λ§Œ..유λŠ₯ν•œ..λ””μžμ΄λ„ˆ

// Invalid #1
phraseGen.set('string'); // Must be an object

// Invalid #2
phraseGen.set({ randomProp: 'random' , adjSuffix: 'ν•˜μ§€λ§Œ'}); // Error -- cannot contain foreign property

πŸ§‘πŸ»β€πŸ’» Author

πŸ‘€ Ju An Kang


β˜•οΈ Brain fluid


⭐️ Share support

If you find this useful or fun, ⭐️ this project!


πŸ“ License

Copyright Β© 2021 Ju An Kang. This project is Apache--2.0 licensed.