TLDR: I needed a quick not-so-boring random generator with several million combinations.
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.
Coming Soon
npm install korean-random-words # npm
yarn add korean-random-words # yarn
// ES6
import PhraseGen from 'korean-random-words';
const phraseGen = new PhraseGen();
// Node
var PhraseGen = require('korean-random-words');
var phraseGen = new PhraseGen();
phraseGen.generatePhrase(); // 'μ μνκ³ -λ§λν-ν΄μΌ'
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 '무μ¬νμ΄λ-μ°©ν-μ€μ리'
- default:
- 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(); // 'μμ¬νμ΄λ__μλν__λͺ¨λν°'
- returns a generated phrase with the supplied configurations
const phraseGenConfig = { /* optional configs */ }
const phraseGen = new PhraseGen(phraseGenConfig);
phraseGen.generatePhrase(); // 'μμ¬νμ΄λ__μλν__λͺ¨λν°'
- 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()
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(); // λ°κ·Έλ νλ€ | λ리λΌλ¦¬νλ€ | 거무μ€λ¦νλ€
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 '무μ¬νμ΄λ-μ°©ν-μ€μ리'
- example:
-
delimiter: string - overrides default delimiter to the provided string(conventionally a character)
- example:
{ delimiter: '__' } // would create 'μ§μ§νκ³ __κ΅μ₯ν__κ°μ'
- example:
-
nouns: [string] - custom set of nouns to randomize the phrase from
- example:
{ customNouns: ['ν€λ³΄λ','λ§μ°μ€','μΉμΊ ','λͺ¨λν°'] }
- example:
-
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: ['λΉλΉ','μμ¬','건λ€κ±΄λ€','μλ'] }
- *The form of adjectives should be words that are compatible with the form of
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
π€ Ju An Kang
- Github: @JuAn-Kang
- LinkedIn: @ju-an-kang
If you find this useful or fun, βοΈ this project!
Copyright Β© 2021 Ju An Kang.
This project is Apache--2.0 licensed.