Skip to content

Commit

Permalink
fix(humanize): fixes options bug when initializing without seed
Browse files Browse the repository at this point in the history
  • Loading branch information
dzucconi committed Aug 29, 2019
1 parent 1f80e9e commit 9dc7316
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/lib/humanize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,13 @@ import { StrokedStream, toString as strokedStreamToString } from "./simulate";
import * as Mistakes from "./mistakes";

export const DEFAULT_MISTAKES: Mistake[] = [
{
apply: Mistakes.miss,
probability: 0.033
},
{
apply: Mistakes.omit,
probability: 0.033
},
{
apply: Mistakes.duplicate,
probability: 0.001
},
{
apply: Mistakes.toggleCase,
probability: 0.033
},
{
apply: Mistakes.capitalize,
probability: 0.033
},
{
apply: Mistakes.repeat,
probability: 0.5
},
{
apply: Mistakes.substitute,
probability: 0.5
}
{ apply: Mistakes.miss, probability: 0.033 },
{ apply: Mistakes.omit, probability: 0.033 },
{ apply: Mistakes.duplicate, probability: 0.001 },
{ apply: Mistakes.toggleCase, probability: 0.033 },
{ apply: Mistakes.capitalize, probability: 0.033 },
{ apply: Mistakes.repeat, probability: 0.5 },
{ apply: Mistakes.substitute, probability: 0.5 }
];

export interface Mistake {
Expand All @@ -53,12 +32,12 @@ export function humanize(
options: {
seed?: string;
mistakes?: Mistake[];
}
} = {}
): Stream {
const { seed, mistakes = DEFAULT_MISTAKES } = options;
const stream = process(string);

initRand(seed);
if (seed) initRand(seed);

return mistakes.reduce((stream, mistake) => {
return stream.map(word => {
Expand Down

0 comments on commit 9dc7316

Please sign in to comment.