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,OAAQ,UAAU,UAAW,KAAK,UACpE,IACR,EAEA,UAAU,UAAU,WAAa,SAAS,GAEzC,OADA,KAAK,OAAO,KAAK,QAAQ,EAAY,KAAK,OAAQ,UAAU,WAAY,KAAK,UACtE,IACR,EAEA,UAAU,UAAU,OAAS,SAAS,GAErC,OADA,KAAK,QAAU,EACR,IACR,EAEA,UAAU,UAAU,MAAQ,SAAS,GAEpC,OADA,KAAK,OAAS,EACP,IACR,EAEA,UAAU,UAAU,SAAW,SAAS,GACvC,IAAI,EAAO,KAAK,OAAO,KAAK,KAG5B,OAFK,IACJ,KAAK,OAAS,IACR,CACR,EAEA,UAAU,UAAU,KAAO,SAAS,GACnC,OAAO,KAAK,SAAS,EACtB,EAEA,UAAU,OAAS,CAClB,WAAY,aACZ,EAAG,aACH,SAAU,WACV,EAAG,WACH,OAAQ,SACR,EAAG,SACH,WAAY,aACZ,EAAG,aACH,aAAc,eACd,EAAG,eACH,cAAe,gBACf,EAAG,iBAGJ,UAAU,QAAU,CACnB,KAAM,OACN,EAAG,OACH,OAAQ,SACR,EAAG,SACH,YAAa,cACb,EAAG,eAGJ,UAAU,SAAW,SAAS,EAAM,EAAQ,GAC3C,OAAO,QAAQ,EAAM,EAAO,UAAU,SAAU,EACjD,EACA,UAAU,UAAY,SAAS,EAAM,EAAQ,GAC5C,OAAO,QAAQ,EAAM,EAAO,UAAU,UAAW,EAClD,EACA,UAAU,WAAa,SAAS,EAAM,EAAQ,GAC7C,OAAO,QAAQ,EAAM,EAAO,UAAU,WAAY,EACnD,EAEA,OAAO,QAAU","file":"/npm/petrovich-js@0.1.1/petrovich.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/petrovich-js@0.1.1/petrovich.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var yml = require('js-yaml');\r\nvar all_rules = null;\r\n\r\nrequire('assert').doesNotThrow(\r\n\tfunction() {\r\n\t\tall_rules = require(process.cwd() + '/rules.yml');\r\n\t},\r\n\tfunction(err) {\r\n\t\tconsole.error('There\\'s no rules.yml file!');\r\n\t\tconsole.error('Please download rules.yml from https://github.com/rocsci/petrovich/blob/master/lib/petrovich/rules.yml');\r\n\t}\r\n);\r\n\r\nfunction inflect(name, gcase, rules, gender) {\r\n\tvar _gender = gender ? ((['male', 'female', 'androgynous'].indexOf(gender.toLowerCase()) < 0) ? 'androgynous' : gender.toLowerCase()) : 'androgynous';\r\n\treturn name.split('-').map(function(value, index, array) {\r\n\t\treturn find_and_apply(value, gcase, {\r\n\t\t\tfirst_word: ((index == 0) && (array.length > 1))\r\n\t\t}, rules, _gender);\r\n\t}).join('-');\r\n}\r\n\r\nfunction find_and_apply(name, gcase, features, rules, gender) {\r\n\tvar rule = find_for(name, features, rules, gender);\r\n\treturn (rule) ? apply(name, gcase, rule) : name;\r\n}\r\n\r\nfunction find_for(name, features, rules, gender) {\r\n\r\n\tvar tags = extract_tags(features);\r\n\r\n\tif (rules.exception !== undefined) {\r\n\t\tvar match = find(name, rules.exception, true, tags, gender);\r\n\t\tif (match)\r\n\t\t\treturn match;\r\n\t}\r\n\r\n\treturn find(name, rules.suffixes, false, tags, gender);\r\n}\r\n\r\nfunction find(name, rules, match_whole_word, tags, gender) {\r\n\tfor (var i = 0; i < rules.length; i++)\r\n\t\tif (match(name, rules[i], match_whole_word, tags, gender))\r\n\t\t\treturn rules[i];\r\n}\r\n\r\nfunction match(name, rule, match_whole_word, tags, gender) {\r\n\tif (!tags_allow(tags, rule.tags))\r\n\t\treturn false;\r\n\tif (((rule.gender == 'male') && (gender == 'female')) || ((rule.gender == 'female') && (gender == 'male')))\r\n\t\treturn false;\r\n\r\n\tvar name_l = name.toLowerCase();\r\n\treturn rule.test.some(function(value) {\r\n\t\tvar test = match_whole_word ? name_l : name_l.slice(-1 * value.length);\r\n\t\treturn (test === value);\r\n\t})\r\n}\r\n\r\nfunction apply(name, gcase, rule) {\r\n\r\n\tvar sw = {\r\n\t\t'.': function(name) {\r\n\t\t\treturn name\r\n\t\t},\r\n\t\t'-': function(name) {\r\n\t\t\treturn name.substr(0, name.length - 1)\r\n\t\t}\r\n\t};\r\n\r\n\tmodificator_for(gcase, rule).split('').forEach(function(char) {\r\n\t\tname = (sw[char]) ? sw[char](name) : (name + char);\r\n\t})\r\n\r\n\treturn name;\r\n}\r\n\r\nfunction extract_tags(features) {\r\n\tvar ret = [];\r\n\tfor (var i in features)\r\n\t\tif (features[i] === true)\r\n\t\t\tret.push(i);\r\n\treturn ret;\r\n}\r\n\r\nfunction modificator_for(gcase, rule) {\r\n\tvar mod = {\r\n\t\t'nominative': '.',\r\n\t\t'genitive': rule.mods[0],\r\n\t\t'dative': rule.mods[1],\r\n\t\t'accusative': rule.mods[2],\r\n\t\t'instrumental': rule.mods[3],\r\n\t\t'prepositional': rule.mods[4]\r\n\t}[gcase];\r\n\treturn (mod) ? mod : '.';\r\n}\r\n\r\nfunction tags_allow(tags, rule_tags) {\r\n\tvar rule_tags = (!rule_tags) ? [] : rule_tags;\r\n\treturn (rule_tags.filter(function(value) {\r\n\t\treturn (tags.indexOf(value) >= 0) ? undefined : value\r\n\t}).length == 0)\r\n}\r\n\r\nvar Petrovich = function(gender, gcase) {\r\n\tthis._final = [];\r\n\tthis._gender = gender;\r\n\tthis._gcase = gcase;\r\n\r\n\tif ((typeof gender !== \"string\") && (typeof gender === \"object\")) {\r\n\t\tthis._gender = gender.gender;\r\n\t\tthis._gcase = gender.gcase;\r\n\t}\r\n\r\n}\r\n\r\nPetrovich.prototype.lastname = function(lastname) {\r\n\tthis._final.push(inflect(lastname, this._gcase, all_rules.lastname, this._gender));\r\n\treturn this;\r\n}\r\n\r\nPetrovich.prototype.firstname = function(firstname) {\r\n\tthis._final.push(inflect(firstname, this._gcase, all_rules.firstname, this._gender));\r\n\treturn this;\r\n}\r\n\r\nPetrovich.prototype.middlename = function(middlename) {\r\n\tthis._final.push(inflect(middlename, this._gcase, all_rules.middlename, this._gender));\r\n\treturn this;\r\n}\r\n\r\nPetrovich.prototype.gender = function(gender) {\r\n\tthis._gender = gender;\r\n\treturn this;\r\n}\r\n\r\nPetrovich.prototype.gcase = function(gcase) {\r\n\tthis._gcase = gcase;\r\n\treturn this;\r\n}\r\n\r\nPetrovich.prototype.toString = function(save) {\r\n\tvar name = this._final.join(' ');\r\n\tif (!save)\r\n\t\tthis._final = [];\r\n\treturn name;\r\n}\r\n\r\nPetrovich.prototype.exec = function(save) {\r\n\treturn this.toString(save);\r\n}\r\n\r\nPetrovich.gcases = {\r\n\tNOMINATIVE: 'nominative',\r\n\tN: 'nominative',\r\n\tGENITIVE: 'genitive',\r\n\tG: 'genitive',\r\n\tDATIVE: 'dative',\r\n\tD: 'dative',\r\n\tACCUSATIVE: 'accusative',\r\n\tA: 'accusative',\r\n\tINSTRUMENTAL: 'instrumental',\r\n\tI: 'instrumental',\r\n\tPREPOSITIONAL: 'prepositional',\r\n\tP: 'prepositional'\r\n}\r\n\r\nPetrovich.genders = {\r\n\tMALE: 'male',\r\n\tM: 'male',\r\n\tFEMALE: 'female',\r\n\tF: 'female',\r\n\tANDROGYNOUS: 'androgynous',\r\n\tA: 'androgynous'\r\n}\r\n\r\nPetrovich.lastname = function(name, gender, gcase) {\r\n\treturn inflect(name, gcase, all_rules.lastname, gender);\r\n}\r\nPetrovich.firstname = function(name, gender, gcase) {\r\n\treturn inflect(name, gcase, all_rules.firstname, gender);\r\n}\r\nPetrovich.middlename = function(name, gender, gcase) {\r\n\treturn inflect(name, gcase, all_rules.middlename, gender);\r\n}\r\n\r\nmodule.exports = Petrovich;"]}