{"id":25654232,"url":"https://github.com/alex-mas/mchains","last_synced_at":"2025-07-20T19:31:51.509Z","repository":{"id":57141790,"uuid":"120119504","full_name":"alex-mas/mchains","owner":"alex-mas","description":"simple string markov chain module in javascript","archived":false,"fork":false,"pushed_at":"2018-05-21T21:11:40.000Z","size":485,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-05T06:06:57.149Z","etag":null,"topics":["algorithm","chain","string-chains"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alex-mas.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-03T18:47:12.000Z","updated_at":"2018-05-21T21:11:42.000Z","dependencies_parsed_at":"2022-09-03T07:41:40.935Z","dependency_job_id":null,"html_url":"https://github.com/alex-mas/mchains","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alex-mas/mchains","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-mas%2Fmchains","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-mas%2Fmchains/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-mas%2Fmchains/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-mas%2Fmchains/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alex-mas","download_url":"https://codeload.github.com/alex-mas/mchains/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-mas%2Fmchains/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266187011,"owners_count":23889895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","chain","string-chains"],"created_at":"2025-02-23T20:18:41.764Z","updated_at":"2025-07-20T19:31:51.494Z","avatar_url":"https://github.com/alex-mas.png","language":"JavaScript","readme":"mchains.js\n===\n\nSimple library to generate string [markov chains](https://en.wikipedia.org/wiki/Markov_chain)\n\n\n# install \n```\nnpm i mchains --save\n```\n\n\n# usage\n### supports UMD\n\n\n\n### usage with commonjs:\n\n\n```javascript\n\nconst Chain = require('mchains');\n\n```\n\n### usage in the browser without any loader\n\n```html\n\u003c!-- In the html--\u003e\n\u003cscript src=\"node_modules/mchains/mchains.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"yourCode.js\"\u003e\u003c/script\u003e\n```\n\n```javascript \n\n//inside your javascript source\nconst Chain = window.mchains;\n\n```\n\n# [documentation](./docs/mchains/1.1.4/module-mchains.html)\n\n\n### constructor\n\n```javascript\n\nnew Chain(parameters);\n\n```\nParameters:\n- Configuration object(optional)\n- Training data(optional)\n\n#### Configuration object(optional):\n\n##### order: \nDefines how many items are grouped together to form a state, in the case of strings that is either words or characters\nIf you want to use this for word generation a lower order will produce more random-like patterns than higher order values\n\n\n##### type:\nDetermines how the strings are parsed and generated:\n- \"character\" will make the strings be parsed as sequences of characters\n- \"word\" will make the strings be parsed as sequences of words (strings delimited by \" \", \"\\n\" and \"\\r\" )\n\n\n#### Training data: \nOptional training data for the chain to process, more information about training data below.\n\n\n### methods\n\n\n#### train()\nTakes data to train from it generating new states for the chain.\n\nValid data:\n- A string\n- An array of strings\n- An object with string values in its properties\n\nExamples:\n```javascript\n\n//option 1:\nconst training = ' just a simple string';\n\n//option 2:\nconst training = ['first string', 'second string', ['string inside an array', 'etc...']];\n\n//option 3: \nconst training = {\n    firstSampleData: ['first string', 'second string', ['string inside an array', 'etc...']],\n    secondSampleData: {\n        whateverKey: ['first string', 'second string', ['string inside an array', 'etc...']],\n        anotherKey: 'just a simple string'\n    },\n    thirdSampleData: 'just a simple string'\n}\n\n\n```\n\n#### doesStateExist(String)\nreturns true if the string matches one of the chain states, false otherwise\n\n#### configOutput(config)\nTakes a configuration object to configure the output of the generate method\n\nConfiguration object properties:\n- minLength            -\u003e defaults to chain order\n- maxLength            -\u003e defaults to chain's order * 2\n- amount               -\u003e defaults to 1\n- capitalizeFirst      -\u003e defaults to false\n- cropToLength         -\u003e defaults to false\n\n#### getNgrams()\nreturns an array of strings, representing the unique ngrams found in the provided training data\n\n\n\n#### generate(config)\nreturns an array of strings generated randomly from the internal states of the chain\n- The config param matches the structure of the parameter of configOutput method\n\n\n\n### Properties\nNote: public properties that are ment to be readonly, they are initialized with the cosntructor:\n\n#### Chain.order\nreturns the order of the chain, that is, how many items are grouped together to form each state\n```javascript\nlet chain = new Chain();\nchain.order \n```\n\n#### Chain.type\nreturns the method used to parse strings, if Chain.type is not String this property will not be used by the algorithm\n```javascript\nlet chain = new Chain();\nchain.type \n```\n\n\n## live examples\nThe following page uses this algorithm in order to generate some of the names\n[demo page](http://www.randomfantasynames.com/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-mas%2Fmchains","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex-mas%2Fmchains","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-mas%2Fmchains/lists"}