namefully 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/config.js +10 -4
- package/dist/lib/constants.js +3 -26
- package/dist/lib/error.js +5 -10
- package/dist/lib/full-name.js +39 -14
- package/dist/lib/name.js +28 -29
- package/dist/lib/namefully.js +76 -62
- package/dist/lib/parser.js +25 -41
- package/dist/lib/types.js +19 -1
- package/dist/lib/utils.js +19 -31
- package/dist/lib/validator.js +34 -48
- package/dist/types/builder.d.ts +4 -2
- package/dist/types/config.d.ts +2 -5
- package/dist/types/constants.d.ts +2 -2
- package/dist/types/error.d.ts +11 -16
- package/dist/types/full-name.d.ts +16 -13
- package/dist/types/name.d.ts +25 -26
- package/dist/types/namefully.d.ts +115 -91
- package/dist/types/parser.d.ts +7 -10
- package/dist/types/types.d.ts +19 -48
- package/dist/types/utils.d.ts +4 -6
- package/dist/types/validator.d.ts +1 -1
- package/dist/umd/namefully.js +258 -266
- package/dist/umd/namefully.min.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("namefully",[],t):"object"==typeof exports?exports.namefully=t():e.namefully=t()}(window,(function(){return function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(s,i,function(t){return e[t]}.bind(null,i));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t,r){"use strict";var s,i,a,n,o,l;Object.defineProperty(t,"__esModule",{value:!0}),t.Separator=t.Namon=t.CapsRange=t.Flat=t.NameType=t.NameOrder=t.Surname=t.Title=void 0,function(e){e.US="US",e.UK="UK"}(s||(t.Title=s={})),function(e){e.FATHER="father",e.MOTHER="mother",e.HYPHENATED="hyphenated",e.ALL="all"}(i||(t.Surname=i={})),function(e){e.FIRST_NAME="firstName",e.LAST_NAME="lastName"}(a||(t.NameOrder=a={})),function(e){e.FIRST_NAME="firstName",e.MIDDLE_NAME="middleName",e.LAST_NAME="lastName",e.BIRTH_NAME="birthName"}(n||(t.NameType=n={})),function(e){e.FIRST_NAME="firstName",e.MIDDLE_NAME="middleName",e.LAST_NAME="lastName",e.FIRST_MID="firstMid",e.MID_LAST="midLast",e.ALL="all"}(o||(t.Flat=o={})),function(e){e[e.NONE=0]="NONE",e[e.INITIAL=1]="INITIAL",e[e.ALL=2]="ALL"}(l||(t.CapsRange=l={}));class u{constructor(e,t){this.index=e,this.key=t}static has(e){return u.all.has(e)}static cast(e){return u.has(e)?u.all.get(e):void 0}toString(){return"Namon."+this.key}equal(e){return e instanceof u&&e.index===this.index&&e.key===this.key}}t.Namon=u,u.PREFIX=new u(0,"prefix"),u.FIRST_NAME=new u(1,"firstName"),u.MIDDLE_NAME=new u(2,"middleName"),u.LAST_NAME=new u(3,"lastName"),u.SUFFIX=new u(4,"suffix"),u.values=[u.PREFIX,u.FIRST_NAME,u.MIDDLE_NAME,u.LAST_NAME,u.SUFFIX],u.all=new Map([[u.PREFIX.key,u.PREFIX],[u.FIRST_NAME.key,u.FIRST_NAME],[u.MIDDLE_NAME.key,u.MIDDLE_NAME],[u.LAST_NAME.key,u.LAST_NAME],[u.SUFFIX.key,u.SUFFIX]]);class h{constructor(e,t){this.name=e,this.token=t}toString(){return"Separator."+this.name}}t.Separator=h,h.COMMA=new h("comma",","),h.COLON=new h("colon",":"),h.DOUBLE_QUOTE=new h("doubleQuote",'"'),h.EMPTY=new h("empty",""),h.HYPHEN=new h("hyphen","-"),h.PERIOD=new h("period","."),h.SEMI_COLON=new h("semiColon",";"),h.SINGLE_QUOTE=new h("singleQuote","'"),h.SPACE=new h("space"," "),h.UNDERSCORE=new h("underscore","_"),h.all=new Map([[h.COMMA.name,h.COMMA],[h.COLON.name,h.COLON],[h.DOUBLE_QUOTE.name,h.DOUBLE_QUOTE],[h.EMPTY.name,h.EMPTY],[h.HYPHEN.name,h.HYPHEN],[h.PERIOD.name,h.PERIOD],[h.SEMI_COLON.name,h.SEMI_COLON],[h.SINGLE_QUOTE.name,h.SINGLE_QUOTE],[h.SPACE.name,h.SPACE],[h.UNDERSCORE.name,h.UNDERSCORE]]),h.tokens=[...h.all.values()].map(e=>e.token)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UnknownError=t.NotAllowedError=t.ValidationError=t.InputError=t.NameError=t.NameErrorType=void 0;const s=r(2);var i;!function(e){e[e.INPUT=0]="INPUT",e[e.VALIDATION=1]="VALIDATION",e[e.NOT_ALLOWED=2]="NOT_ALLOWED",e[e.UNKNOWN=3]="UNKNOWN"}(i||(t.NameErrorType=i={}));class a extends Error{constructor(e,t,r=i.UNKNOWN){super(t),this.source=e,this.type=r,this.name="NameError"}get sourceAsString(){let e="";return this.source||(e="<undefined>"),"string"==typeof this.source&&(e=this.source),(0,s.isNameArray)(this.source)&&(e=this.source.map(e=>e.toString()).join(" ")),(0,s.isStringArray)(this.source)&&(e=this.source.join(" ")),e}get hasMessage(){return this.message&&this.message.trim().length>0}toString(){let e=`${this.name} (${this.sourceAsString})`;return this.hasMessage&&(e=`${e}: ${this.message}`),e}}t.NameError=a;t.InputError=class extends a{constructor(e){super(e.source,e.message,i.INPUT),this.name="InputError"}};t.ValidationError=class extends a{constructor(e){super(e.source,e.message,i.VALIDATION),this.nameType=e.nameType,this.name="ValidationError"}toString(){let e=`${this.name} (${this.nameType}='${this.sourceAsString}')`;return this.hasMessage&&(e=`${e}: ${this.message}`),e}};t.NotAllowedError=class extends a{constructor(e){super(e.source,e.message,i.NOT_ALLOWED),this.operation=e.operation,this.name="NotAllowedError"}toString(){let e=`${this.name} (${this.sourceAsString})`;return this.operation&&this.operation.trim().length>0&&(e=`${e} - ${this.operation}`),this.hasMessage&&(e=`${e}: ${this.message}`),e}};t.UnknownError=class extends a{constructor(e){super(e.source,e.message,i.UNKNOWN),this.origin=e.error,this.name="UnknownError"}toString(){let e=super.toString();return this.origin&&(e+="\n"+this.origin.toString()),e}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isNameArray=t.isStringArray=t.toggleCase=t.decapitalize=t.capitalize=t.NameIndex=void 0;const s=r(4),i=r(3),a=r(0);class n{static get min(){return s.MIN_NUMBER_OF_NAME_PARTS}static get max(){return s.MAX_NUMBER_OF_NAME_PARTS}constructor(e,t,r,s,i){this.prefix=e,this.firstName=t,this.middleName=r,this.lastName=s,this.suffix=i}static base(){return new this(-1,0,-1,1,-1)}static when(e,t=2){if(e===a.NameOrder.FIRST_NAME)switch(t){case 2:return new this(-1,0,-1,1,-1);case 3:return new this(-1,0,1,2,-1);case 4:return new this(0,1,2,3,-1);case 5:return new this(0,1,2,3,4);default:return n.base()}else switch(t){case 2:return new this(-1,1,-1,0,-1);case 3:return new this(-1,1,2,0,-1);case 4:return new this(0,2,3,1,-1);case 5:return new this(0,2,3,1,4);default:return n.base()}}static only({prefix:e=-1,firstName:t,middleName:r=-1,lastName:s,suffix:i=-1}){return new this(e,t,r,s,i)}toJson(){return{prefix:this.prefix,firstName:this.firstName,middleName:this.middleName,lastName:this.lastName,suffix:this.suffix}}}t.NameIndex=n,t.capitalize=function(e,t=a.CapsRange.INITIAL){if(!e||t===a.CapsRange.NONE)return e;const r=e[0].toUpperCase(),s=e.slice(1).toLowerCase();return t===a.CapsRange.INITIAL?r.concat(s):e.toUpperCase()},t.decapitalize=function(e,t=a.CapsRange.INITIAL){if(!e||t===a.CapsRange.NONE)return e;const r=e[0].toLowerCase(),s=e.slice(1);return t===a.CapsRange.INITIAL?r.concat(s):e.toLowerCase()},t.toggleCase=function(e){const t=[];for(const r of e)r===r.toUpperCase()?t.push(r.toLowerCase()):t.push(r.toUpperCase());return t.join("")},t.isStringArray=function(e){return Array.isArray(e)&&e.length>0&&e.every(e=>"string"==typeof e)},t.isNameArray=function(e){return Array.isArray(e)&&e.length>0&&e.every(e=>e instanceof i.Name)}},function(e,t,r){"use strict";var s,i,a,n=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r},o=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.LastName=t.FirstName=t.Name=void 0;const l=r(1),u=r(0),h=r(2);class c{constructor(e,t,r){this.type=t,s.set(this,void 0),this.capsRange=null!=r?r:u.CapsRange.INITIAL,this.value=e,r&&this.caps(r)}set value(e){this.validate(e),n(this,s,e,"f"),this.initial=e[0]}get value(){return o(this,s,"f")}get length(){return o(this,s,"f").length}get isPrefix(){return this.type===u.Namon.PREFIX}get isFirstName(){return this.type===u.Namon.FIRST_NAME}get isMiddleName(){return this.type===u.Namon.MIDDLE_NAME}get isLastName(){return this.type===u.Namon.LAST_NAME}get isSuffix(){return this.type===u.Namon.SUFFIX}static prefix(e){return new this(e,u.Namon.PREFIX)}static first(e){return new this(e,u.Namon.FIRST_NAME)}static middle(e){return new this(e,u.Namon.MIDDLE_NAME)}static last(e){return new this(e,u.Namon.LAST_NAME)}static suffix(e){return new this(e,u.Namon.SUFFIX)}initials(){return[this.initial]}toString(){return o(this,s,"f")}equal(e){return e instanceof c&&e.value===this.value&&e.type===this.type}caps(e){return this.value=(0,h.capitalize)(o(this,s,"f"),null!=e?e:this.capsRange),this}decaps(e){return this.value=(0,h.decapitalize)(o(this,s,"f"),null!=e?e:this.capsRange),this}validate(e){if((null==e?void 0:e.trim().length)<2)throw new l.InputError({source:e,message:"must be 2+ characters"})}}t.Name=c,s=new WeakMap;class f extends c{constructor(e,...t){super(e,u.Namon.FIRST_NAME),i.set(this,void 0),t.forEach(e=>this.validate(e)),n(this,i,t,"f")}get hasMore(){return o(this,i,"f").length>0}get length(){return super.length+(this.hasMore?o(this,i,"f").reduce((e,t)=>e+t).length:0)}get asNames(){const e=[c.first(this.value)];return this.hasMore&&e.push(...o(this,i,"f").map(e=>c.first(e))),e}get more(){return o(this,i,"f")}toString(e=!1){return e&&this.hasMore?`${this.value} ${o(this,i,"f").join(" ")}`.trim():this.value}initials(e=!1){const t=[this.initial];return e&&this.hasMore&&t.push(...o(this,i,"f").map(e=>e[0])),t}caps(e){return e=e||this.capsRange,this.value=(0,h.capitalize)(this.value,e),this.hasMore&&n(this,i,o(this,i,"f").map(t=>(0,h.capitalize)(t,e)),"f"),this}decaps(e){return e=e||this.capsRange,this.value=(0,h.decapitalize)(this.value,e),this.hasMore&&n(this,i,o(this,i,"f").map(t=>(0,h.decapitalize)(t,e)),"f"),this}copyWith(e){var t,r;return new f(null!==(t=e.first)&&void 0!==t?t:this.value,...null!==(r=e.more)&&void 0!==r?r:o(this,i,"f"))}}t.FirstName=f,i=new WeakMap;class m extends c{constructor(e,t,r=u.Surname.FATHER){super(e,u.Namon.LAST_NAME),this.format=r,a.set(this,void 0),this.validate(t),n(this,a,t,"f")}get father(){return this.value}get mother(){return o(this,a,"f")}get hasMother(){return!!o(this,a,"f")}get length(){var e,t;return super.length+(null!==(t=null===(e=o(this,a,"f"))||void 0===e?void 0:e.length)&&void 0!==t?t:0)}get asNames(){const e=[c.last(this.value)];return this.hasMother&&e.push(c.last(o(this,a,"f"))),e}toString(e){var t;switch(e=null!=e?e:this.format){case u.Surname.FATHER:return this.value;case u.Surname.MOTHER:return null!==(t=this.mother)&&void 0!==t?t:"";case u.Surname.HYPHENATED:return this.hasMother?`${this.value}-${o(this,a,"f")}`:this.value;case u.Surname.ALL:return this.hasMother?`${this.value} ${o(this,a,"f")}`:this.value}}initials(e){const t=[];switch(e=e||this.format){case u.Surname.MOTHER:this.hasMother&&t.push(o(this,a,"f")[0]);break;case u.Surname.HYPHENATED:case u.Surname.ALL:t.push(this.initial),this.hasMother&&t.push(o(this,a,"f")[0]);break;case u.Surname.FATHER:default:t.push(this.initial)}return t}caps(e){return e=e||this.capsRange,this.value=(0,h.capitalize)(this.value,e),this.hasMother&&n(this,a,(0,h.capitalize)(o(this,a,"f"),e),"f"),this}decaps(e){return e=e||this.capsRange,this.value=(0,h.decapitalize)(this.value,e),this.hasMother&&n(this,a,(0,h.decapitalize)(o(this,a,"f"),e),"f"),this}copyWith(e){var t,r,s;return new m(null!==(t=e.father)&&void 0!==t?t:this.value,null!==(r=e.mother)&&void 0!==r?r:this.mother,null!==(s=e.format)&&void 0!==s?s:this.format)}}t.LastName=m,a=new WeakMap},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ALLOWED_TOKENS=t.MAX_NUMBER_OF_NAME_PARTS=t.MIN_NUMBER_OF_NAME_PARTS=t.VERSION=void 0,t.VERSION="1.3.0",t.MIN_NUMBER_OF_NAME_PARTS=2,t.MAX_NUMBER_OF_NAME_PARTS=5,t.ALLOWED_TOKENS=[".",","," ","-","_","b","B","f","F","l","L","m","M","n","N","o","O","p","P","s","S","$"]},function(e,t,r){"use strict";var s,i,a,n,o=this&&this.__awaiter||function(e,t,r,s){return new(r||(r=Promise))((function(i,a){function n(e){try{l(s.next(e))}catch(e){a(e)}}function o(e){try{l(s.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((s=s.apply(e,t||[])).next())}))},l=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)},u=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Namefully=void 0;const h=r(4),c=r(1),f=r(8),m=r(0),d=r(2);class p{constructor(e,t){s.add(this),i.set(this,void 0),u(this,i,l(this,s,"m",a).call(this,e).parse(t),"f")}static tryParse(e,t){try{return new p(f.Parser.build(e,t))}catch(e){return}}static parse(e,t){return o(this,void 0,void 0,(function*(){return f.Parser.buildAsync(e,t).then(e=>new p(e))}))}get config(){return l(this,i,"f").config}get length(){return this.birth.length}get prefix(){var e;return null===(e=l(this,i,"f").prefix)||void 0===e?void 0:e.toString()}get first(){return this.firstName()}get middle(){return this.hasMiddle?this.middleName()[0]:void 0}get hasMiddle(){return l(this,i,"f").has(m.Namon.MIDDLE_NAME)}get last(){return this.lastName()}get suffix(){var e;return null===(e=l(this,i,"f").suffix)||void 0===e?void 0:e.toString()}get birth(){return this.birthName()}get short(){return this.shorten()}get long(){return this.birth}get full(){return this.fullName()}get public(){return this.format("f $l")}get salutation(){return this.format("p l")}toString(){return this.full}get(e){return e.equal(m.Namon.PREFIX)?l(this,i,"f").prefix:e.equal(m.Namon.FIRST_NAME)?l(this,i,"f").firstName:e.equal(m.Namon.MIDDLE_NAME)?l(this,i,"f").middleName:e.equal(m.Namon.LAST_NAME)?l(this,i,"f").lastName:e.equal(m.Namon.SUFFIX)?l(this,i,"f").suffix:void 0}equal(e){return this.toString()===e.toString()}toJson(){return{prefix:this.prefix,firstName:this.first,middleName:this.middleName(),lastName:this.last,suffix:this.suffix}}has(e){return l(this,i,"f").has(e)}fullName(e){const t=this.config.ending?",":"",r=[];return e=e||this.config.orderedBy,this.prefix&&r.push(this.prefix),e===m.NameOrder.FIRST_NAME?r.push(this.first,...this.middleName(),this.last+t):r.push(this.last,this.first,this.middleName().join(" ")+t),this.suffix&&r.push(this.suffix),r.join(" ").trim()}birthName(e){return(e=e||this.config.orderedBy)===m.NameOrder.FIRST_NAME?[this.first,...this.middleName(),this.last].join(" "):[this.last,this.first,...this.middleName()].join(" ")}firstName(e=!0){return l(this,i,"f").firstName.toString(e)}middleName(){return l(this,i,"f").middleName.map(e=>e.value)}lastName(e){return l(this,i,"f").lastName.toString(e)}initials(e){const t=l(this,i,"f").firstName.initials(),r=l(this,i,"f").middleName.map(e=>e.initials()[0]),s=l(this,i,"f").lastName.initials();if(null==e?void 0:e.asJson)return{firstName:t,middleName:r,lastName:s};const a=[],{orderedBy:n=this.config.orderedBy,only:o=m.NameType.BIRTH_NAME}=null!=e?e:{};return o!==m.NameType.BIRTH_NAME?o===m.NameType.FIRST_NAME?a.push(...t):o===m.NameType.MIDDLE_NAME?a.push(...r):a.push(...s):n===m.NameOrder.FIRST_NAME?a.push(...t,...r,...s):a.push(...s,...t,...r),a}shorten(e){return(e=e||this.config.orderedBy)===m.NameOrder.FIRST_NAME?[l(this,i,"f").firstName.value,l(this,i,"f").lastName.toString()].join(" "):[l(this,i,"f").lastName.toString(),l(this,i,"f").firstName.value].join(" ")}flatten(e){if(this.length<=e.limit)return this.full;const{by:t=m.Flat.MIDDLE_NAME,limit:r=20,recursive:s=!1,withMore:a=!1,withPeriod:n=!0,surname:o}=e,u=n?".":"",h=l(this,i,"f").firstName.toString(),c=this.middleName().join(" "),f=l(this,i,"f").lastName.toString(),d=this.hasMiddle,p=l(this,i,"f").firstName.initials(a).join(u+" ")+u,N=l(this,i,"f").lastName.initials(o).join(u+" ")+u,w=d?l(this,i,"f").middleName.map(e=>e.initials()[0]).join(u+" ")+u:"";let g=[];if(this.config.orderedBy===m.NameOrder.FIRST_NAME)switch(t){case m.Flat.FIRST_NAME:g=d?[p,c,f]:[p,f];break;case m.Flat.LAST_NAME:g=d?[h,c,N]:[h,N];break;case m.Flat.MIDDLE_NAME:g=d?[h,w,f]:[h,f];break;case m.Flat.FIRST_MID:g=d?[p,w,f]:[p,f];break;case m.Flat.MID_LAST:g=d?[h,w,N]:[h,N];break;case m.Flat.ALL:g=d?[p,w,N]:[p,N]}else switch(t){case m.Flat.FIRST_NAME:g=d?[f,p,c]:[f,p];break;case m.Flat.LAST_NAME:g=d?[N,h,c]:[N,h];break;case m.Flat.MIDDLE_NAME:g=d?[f,h,w]:[f,h];break;case m.Flat.FIRST_MID:g=d?[f,p,w]:[f,p];break;case m.Flat.MID_LAST:g=d?[N,h,w]:[N,h];break;case m.Flat.ALL:g=d?[N,p,w]:[N,p]}const v=g.join(" ");if(s&&v.length>r){const r=t===m.Flat.FIRST_NAME?m.Flat.MIDDLE_NAME:t===m.Flat.MIDDLE_NAME?m.Flat.LAST_NAME:t===m.Flat.LAST_NAME?m.Flat.FIRST_MID:t===m.Flat.FIRST_MID?m.Flat.MID_LAST:t===m.Flat.MID_LAST||t===m.Flat.ALL?m.Flat.ALL:t;return r===t?v:this.flatten(Object.assign(Object.assign({},e),{by:r}))}return v}zip(e=m.Flat.MID_LAST,t=!0){return this.flatten({limit:0,by:e,withPeriod:t})}format(e){var t;if("short"===e)return this.short;if("long"===e)return this.long;if("public"===e)return this.public;"official"===e&&(e="o");let r="";const i=[];for(const a of e.split("")){if(-1===h.ALLOWED_TOKENS.indexOf(a))throw new c.NotAllowedError({source:this.full,operation:"format",message:`unsupported character <${a}> from ${e}.`});r+=a,"$"!==a&&(i.push(null!==(t=l(this,s,"m",n).call(this,r))&&void 0!==t?t:""),r="")}return i.join("").trim()}flip(){this.config.updateOrder(this.config.orderedBy===m.NameOrder.FIRST_NAME?m.NameOrder.LAST_NAME:m.NameOrder.FIRST_NAME)}split(e=/[' -]/g){return this.birth.replace(e," ").split(" ")}join(e=""){return this.split().join(e)}toUpperCase(){return this.birth.toUpperCase()}toLowerCase(){return this.birth.toLowerCase()}toCamelCase(){return(0,d.decapitalize)(this.toPascalCase())}toPascalCase(){return this.split().map(e=>(0,d.capitalize)(e)).join("")}toSnakeCase(){return this.split().map(e=>e.toLowerCase()).join("_")}toHyphenCase(){return this.split().map(e=>e.toLowerCase()).join("-")}toDotCase(){return this.split().map(e=>e.toLowerCase()).join(".")}toToggleCase(){return(0,d.toggleCase)(this.birth)}}t.Namefully=p,i=new WeakMap,s=new WeakSet,a=function(e){if(e instanceof f.Parser)return e;if("string"==typeof e)return new f.StringParser(e);if((0,d.isStringArray)(e))return new f.ArrayStringParser(e);if((0,d.isNameArray)(e))return new f.ArrayNameParser(e);if("object"==typeof e)return new f.NamaParser(e);throw new c.InputError({source:e,message:"Cannot parse raw data. Review expected data types."})},n=function(e){var t,r;switch(e){case".":case",":case" ":case"-":case"_":return e;case"b":return this.birth;case"B":return this.birth.toUpperCase();case"f":return this.first;case"F":return this.first.toUpperCase();case"l":return this.last;case"L":return this.last.toUpperCase();case"m":case"M":return"m"===e?this.middleName().join(" "):this.middleName().join(" ").toUpperCase();case"o":case"O":return(e=>{const t=this.config.ending?",":"",r=[];this.prefix&&r.push(this.prefix),r.push((this.last+",").toUpperCase()),this.hasMiddle?r.push(this.first,this.middleName().join(" ")+t):r.push(this.first+t),this.suffix&&r.push(this.suffix);const s=r.join(" ").trim();return"o"===e?s:s.toUpperCase()})(e);case"p":return this.prefix;case"P":return null===(t=this.prefix)||void 0===t?void 0:t.toUpperCase();case"s":return this.suffix;case"S":return null===(r=this.suffix)||void 0===r?void 0:r.toUpperCase();case"$f":case"$F":return l(this,i,"f").firstName.initials()[0];case"$l":case"$L":return l(this,i,"f").lastName.initials()[0];case"$m":case"$M":return this.hasMiddle?this.middle[0]:void 0;default:return}},t.default=(e,t)=>new p(e,t)},function(e,t,r){"use strict";var s,i,a,n,o,l,u,h,c,f,m=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)},d=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0;const p=r(0);class N{get orderedBy(){return m(this,n,"f")}get separator(){return m(this,o,"f")}get title(){return m(this,l,"f")}get ending(){return m(this,u,"f")}get bypass(){return m(this,h,"f")}get surname(){return m(this,c,"f")}get name(){return m(this,a,"f")}constructor(e,t=p.NameOrder.FIRST_NAME,r=p.Separator.SPACE,i=p.Title.UK,f=!1,m=!0,N=p.Surname.FATHER){s.add(this),a.set(this,void 0),n.set(this,void 0),o.set(this,void 0),l.set(this,void 0),u.set(this,void 0),h.set(this,void 0),c.set(this,void 0),d(this,a,e,"f"),d(this,n,t,"f"),d(this,o,r,"f"),d(this,l,i,"f"),d(this,u,f,"f"),d(this,h,m,"f"),d(this,c,N,"f")}static create(e="default"){return i.cache.has(e)||i.cache.set(e,new this(e)),i.cache.get(e)}static merge(e){var t,r,s,a,f,m;if(e){const p=i.create(e.name);return d(p,n,null!==(t=e.orderedBy)&&void 0!==t?t:p.orderedBy,"f"),d(p,o,null!==(r=e.separator)&&void 0!==r?r:p.separator,"f"),d(p,l,null!==(s=e.title)&&void 0!==s?s:p.title,"f"),d(p,u,null!==(a=e.ending)&&void 0!==a?a:p.ending,"f"),d(p,h,null!==(f=e.bypass)&&void 0!==f?f:p.bypass,"f"),d(p,c,null!==(m=e.surname)&&void 0!==m?m:p.surname,"f"),p}return i.create()}copyWith(e={}){const{name:t,orderedBy:r,separator:a,title:p,ending:N,bypass:w,surname:g}=e,v=i.create(m(this,s,"m",f).call(this,null!=t?t:this.name+"_copy"));return d(v,n,null!=r?r:this.orderedBy,"f"),d(v,o,null!=a?a:this.separator,"f"),d(v,l,null!=p?p:this.title,"f"),d(v,u,null!=N?N:this.ending,"f"),d(v,h,null!=w?w:this.bypass,"f"),d(v,c,null!=g?g:this.surname,"f"),v}clone(){return this.copyWith()}reset(){d(this,n,p.NameOrder.FIRST_NAME,"f"),d(this,o,p.Separator.SPACE,"f"),d(this,l,p.Title.UK,"f"),d(this,u,!1,"f"),d(this,h,!0,"f"),d(this,c,p.Surname.FATHER,"f"),i.cache.set(this.name,this)}updateOrder(e){e&&e!==m(this,n,"f")&&d(i.cache.get(this.name),n,e,"f")}}t.Config=N,i=N,a=new WeakMap,n=new WeakMap,o=new WeakMap,l=new WeakMap,u=new WeakMap,h=new WeakMap,c=new WeakMap,s=new WeakSet,f=function e(t){return t===this.name||i.cache.has(t)?m(this,s,"m",e).call(this,t+"_copy"):t},N.cache=new Map},function(e,t,r){"use strict";var s,i,a,n,o,l,u,h,c,f,m,d,p,N,w,g,v=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)},E=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Validators=t.ArrayNameValidator=t.ArrayStringValidator=t.NamaValidator=void 0;const M=r(4),y=r(1),_=r(3),A=r(0),S=r(2);class T{}T.base=/[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/,T.namon=new RegExp(`^${T.base.source}+(([' -]${T.base.source})?${T.base.source}*)*$`),T.firstName=T.namon,T.middleName=new RegExp(`^${T.base.source}+(([' -]${T.base.source})?${T.base.source}*)*$`),T.lastName=T.namon;class I{static create(){return v(this,s,"f",i)||E(this,s,new this,"f",i)}validate(e,t){if(e instanceof _.Name)O.create().validate(e,t);else{if("string"!=typeof e)throw new y.InputError({source:typeof e,message:"expecting types of string | Name"});if(!T.namon.test(e))throw new y.ValidationError({source:e,nameType:"namon",message:"invalid content"})}}}s=I,i={value:void 0};class F{static create(){return v(this,a,"f",n)||E(this,a,new this,"f",n)}validate(e){if(e instanceof _.FirstName)e.asNames.forEach(e=>this.validate(e.value));else{if("string"!=typeof e)throw new y.InputError({source:typeof e,message:"expecting types string | FirstName"});if(!T.firstName.test(e))throw new y.ValidationError({source:e,nameType:"firstName",message:"invalid content"})}}}a=F,n={value:void 0};class b{static create(){return v(this,o,"f",l)||E(this,o,new this,"f",l)}validate(e){if("string"==typeof e){if(!T.middleName.test(e))throw new y.ValidationError({source:e,nameType:"middleName",message:"invalid content"})}else{if(!Array.isArray(e))throw new y.InputError({source:typeof e,message:"expecting types of string | string[] | Name[]"});try{const t=I.create();for(const r of e)t.validate(r,A.Namon.MIDDLE_NAME)}catch(t){throw new y.ValidationError({source:e,nameType:"middleName",message:null==t?void 0:t.message})}}}}o=b,l={value:void 0};class P{static create(){return v(this,u,"f",h)||E(this,u,new this,"f",h)}validate(e){if(e instanceof _.LastName)e.asNames.forEach(e=>this.validate(e.value));else{if("string"!=typeof e)throw new y.InputError({source:typeof e,message:"expecting types string | LastName"});if(!T.lastName.test(e))throw new y.ValidationError({source:e,nameType:"lastName",message:"invalid content"})}}}u=P,h={value:void 0};class O{static create(){return v(this,c,"f",f)||E(this,c,new this,"f",f)}validate(e,t){if(t&&e.type!==t)throw new y.ValidationError({source:[e],nameType:e.type.toString(),message:"wrong type"});if(!T.namon.test(e.value))throw new y.ValidationError({source:[e],nameType:e.type.toString(),message:"invalid content"})}}c=O,f={value:void 0};class L{static create(){return v(this,m,"f",d)||E(this,m,new this,"f",d)}validate(e){this.validateKeys(e),R.firstName.validate(e.get(A.Namon.FIRST_NAME)),R.lastName.validate(e.get(A.Namon.LAST_NAME)),e.has(A.Namon.PREFIX)&&R.namon.validate(e.get(A.Namon.PREFIX)),e.has(A.Namon.SUFFIX)&&R.namon.validate(e.get(A.Namon.SUFFIX))}validateKeys(e){if(!e.size)throw new y.InputError({source:void 0,message:"Map<k,v> must not be empty"});if(e.size<M.MIN_NUMBER_OF_NAME_PARTS||e.size>M.MAX_NUMBER_OF_NAME_PARTS)throw new y.InputError({source:[...e.values()],message:`expecting ${M.MIN_NUMBER_OF_NAME_PARTS}-${M.MIN_NUMBER_OF_NAME_PARTS} fields`});if(!e.has(A.Namon.FIRST_NAME))throw new y.InputError({source:[...e.values()],message:'"firstName" is a required key'});if(!e.has(A.Namon.LAST_NAME))throw new y.InputError({source:[...e.values()],message:'"lastName" is a required key'})}}t.NamaValidator=L,m=L,d={value:void 0};t.ArrayStringValidator=class extends class{validate(e){if(0===e.length||e.length<M.MIN_NUMBER_OF_NAME_PARTS||e.length>M.MAX_NUMBER_OF_NAME_PARTS)throw new y.InputError({source:e.map(e=>e.toString()),message:`expecting a list of ${M.MIN_NUMBER_OF_NAME_PARTS}-${M.MIN_NUMBER_OF_NAME_PARTS} elements`})}}{constructor(e=S.NameIndex.base()){super(),this.index=e}validate(e){this.validateIndex(e),R.firstName.validate(e[this.index.firstName]),R.lastName.validate(e[this.index.lastName]),e.length>=3&&R.middleName.validate(e[this.index.middleName]),e.length>=4&&R.namon.validate(e[this.index.prefix]),5===e.length&&R.namon.validate(e[this.index.suffix])}validateIndex(e){super.validate(e)}};class x{constructor(){p.add(this)}static create(){return v(this,N,"f",w)||E(this,N,new this,"f",w)}validate(e){if(e.length<M.MIN_NUMBER_OF_NAME_PARTS)throw new y.InputError({source:e,message:`expecting at least ${M.MIN_NUMBER_OF_NAME_PARTS} elements`});if(!v(this,p,"m",g).call(this,e))throw new y.InputError({source:e,message:"both first and last names are required"})}}t.ArrayNameValidator=x,N=x,p=new WeakSet,g=function(e){const t={};for(const r of e)(r.isFirstName||r.isLastName)&&(t[r.type.key]=r.toString());return Object.keys(t).length===M.MIN_NUMBER_OF_NAME_PARTS},w={value:void 0};class R{}t.Validators=R,R.namon=I.create(),R.nama=L.create(),R.prefix=I.create(),R.firstName=F.create(),R.middleName=b.create(),R.lastName=P.create(),R.suffix=I.create()},function(e,t,r){"use strict";var s,i,a=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayNameParser=t.NamaParser=t.ArrayStringParser=t.StringParser=t.Parser=void 0;const n=r(9),o=r(6),l=r(2),u=r(7),h=r(3),c=r(0),f=r(1);class m{constructor(e){this.raw=e}static build(e,t){const r=e.trim().split(c.Separator.SPACE.token),s=r.length;if(t instanceof l.NameIndex){const e=Object.entries(t.toJson()).filter(([,e])=>e>-1&&e<s).map(([e,t])=>new h.Name(r[t],c.Namon.all.get(e)));return new N(e)}if(s<2)throw new f.InputError({source:e,message:"cannot build from invalid input"});if(2===s||3===s)return new d(e);{const e=r.pop(),[t,...s]=r;return new p([t,s.join(" "),e])}}static buildAsync(e,t){try{return Promise.resolve(m.build(e,t))}catch(e){return Promise.reject(e)}}}t.Parser=m;class d extends m{parse(e){const t=o.Config.merge(e),r=this.raw.split(t.separator.token);return new p(r).parse(e)}}t.StringParser=d;class p extends m{parse(e){const t=o.Config.merge(e),r=new n.FullName(t),s=this.raw.map(e=>e.trim()),i=l.NameIndex.when(t.orderedBy,s.length),a=new u.ArrayStringValidator(i);t.bypass?a.validateIndex(s):a.validate(s);const{firstName:c,lastName:f,middleName:m,prefix:d,suffix:p}=i;return r.setFirstName(new h.FirstName(s[c])),r.setLastName(new h.LastName(s[f])),s.length>=3&&r.setMiddleName(s[m].split(t.separator.token)),s.length>=4&&r.setPrefix(h.Name.prefix(s[d])),5===s.length&&r.setSuffix(h.Name.suffix(s[p])),r}}t.ArrayStringParser=p;t.NamaParser=class extends m{constructor(){super(...arguments),s.add(this)}parse(e){const t=o.Config.merge(e);return t.bypass?u.NamaValidator.create().validateKeys(a(this,s,"m",i).call(this)):u.NamaValidator.create().validate(a(this,s,"m",i).call(this)),n.FullName.parse(this.raw,t)}},s=new WeakSet,i=function(){return new Map(Object.entries(this.raw).map(([e,t])=>{const r=c.Namon.cast(e);if(!r)throw new f.InputError({source:Object.values(this.raw).join(" "),message:`unsupported key "${e}"`});return[r,t]}))};class N extends m{parse(e){const t=o.Config.merge(e),r=new n.FullName(t);u.ArrayNameValidator.create().validate(this.raw);for(const e of this.raw)if(e.isPrefix)r.setPrefix(e);else if(e.isSuffix)r.setSuffix(e);else if(e.isFirstName)r.setFirstName(e instanceof h.FirstName?e:new h.FirstName(e.value));else if(e.isMiddleName)r.middleName.push(e);else if(e.isLastName){const s=new h.LastName(e.value,e instanceof h.LastName?e.mother:void 0,t.surname);r.setLastName(s)}return r}}t.ArrayNameParser=N},function(e,t,r){"use strict";var s,i,a,n,o,l,u=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r},h=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.FullName=void 0;const c=r(6),f=r(1),m=r(3),d=r(0),p=r(7);class N{constructor(e){s.set(this,void 0),i.set(this,void 0),a.set(this,[]),n.set(this,void 0),o.set(this,void 0),l.set(this,void 0),u(this,l,c.Config.merge(e),"f")}get config(){return h(this,l,"f")}get prefix(){return h(this,s,"f")}get firstName(){return h(this,i,"f")}get lastName(){return h(this,n,"f")}get middleName(){return h(this,a,"f")}get suffix(){return h(this,o,"f")}static parse(e,t){try{const r=new N(t);return r.setPrefix(e.prefix),r.setFirstName(e.firstName),r.setMiddleName(e.middleName),r.setLastName(e.lastName),r.setSuffix(e.suffix),r}catch(t){if(t instanceof f.NameError)throw t;throw new f.UnknownError({source:Object.values(e).join(" "),message:"could not parse JSON content",error:t})}}setPrefix(e){if(!e)return this;h(this,l,"f").bypass||p.Validators.prefix.validate(e);const t=e instanceof m.Name?e.value:e;return u(this,s,m.Name.prefix(h(this,l,"f").title===d.Title.US?t+".":t),"f"),this}setFirstName(e){return h(this,l,"f").bypass||p.Validators.firstName.validate(e),u(this,i,e instanceof m.FirstName?e:new m.FirstName(e),"f"),this}setLastName(e){return h(this,l,"f").bypass||p.Validators.lastName.validate(e),u(this,n,e instanceof m.LastName?e:new m.LastName(e),"f"),this}setMiddleName(e){return Array.isArray(e)?(h(this,l,"f").bypass||p.Validators.middleName.validate(e),u(this,a,e.map(e=>e instanceof m.Name?e:m.Name.middle(e)),"f"),this):this}setSuffix(e){return e?(h(this,l,"f").bypass||p.Validators.suffix.validate(e),u(this,o,m.Name.suffix(e instanceof m.Name?e.value:e),"f"),this):this}has(e){return e.equal(d.Namon.PREFIX)?!!h(this,s,"f"):e.equal(d.Namon.SUFFIX)?!!h(this,o,"f"):!e.equal(d.Namon.MIDDLE_NAME)||h(this,a,"f").length>0}}t.FullName=N,s=new WeakMap,i=new WeakMap,a=new WeakMap,n=new WeakMap,o=new WeakMap,l=new WeakMap},function(e,t,r){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,i)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||s(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.NameIndex=t.Parser=t.version=void 0;const a=r(5);i(r(11),t),i(r(6),t);var n=r(4);Object.defineProperty(t,"version",{enumerable:!0,get:function(){return n.VERSION}}),i(r(1),t),i(r(9),t),i(r(3),t),i(r(5),t);var o=r(8);Object.defineProperty(t,"Parser",{enumerable:!0,get:function(){return o.Parser}}),i(r(0),t);var l=r(2);Object.defineProperty(t,"NameIndex",{enumerable:!0,get:function(){return l.NameIndex}}),t.default=a.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NameBuilder=void 0;const s=r(5),i=r(7);class a extends class{constructor(e,t,r,s){this.prebuild=e,this.postbuild=t,this.preclear=r,this.postclear=s,this.queue=[],this.instance=null}get size(){return this.queue.length}removeFirst(){return this.queue.length>0?this.queue.shift():void 0}removeLast(){return this.queue.length>0?this.queue.pop():void 0}addFirst(e){this.queue.unshift(e)}addLast(e){this.queue.push(e)}add(...e){this.queue.push(...e)}remove(e){const t=this.queue.indexOf(e);return-1!==t&&(this.queue.splice(t,1),!0)}removeWhere(e){this.queue=this.queue.filter(t=>!e(t))}retainWhere(e){this.queue=this.queue.filter(e)}clear(){var e,t;null!==this.instance&&(null===(e=this.preclear)||void 0===e||e.call(this,this.instance)),this.queue=[],null===(t=this.postclear)||void 0===t||t.call(this),this.instance=null}}{constructor(e,t,r,s,i){super(t,r,s,i),this.add(...e)}static create(e){return new a(e?[e]:[])}static of(...e){return new a(e)}static use({names:e,prebuild:t,postbuild:r,preclear:s,postclear:i}){return new a(null!=e?e:[],t,r,s,i)}build(e){var t,r;null===(t=this.prebuild)||void 0===t||t.call(this);const a=[...this.queue];return i.ArrayNameValidator.create().validate(a),this.instance=new s.Namefully(a,e),null===(r=this.postbuild)||void 0===r||r.call(this,this.instance),this.instance}}t.NameBuilder=a}])}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("namefully",[],t):"object"==typeof exports?exports.namefully=t():e.namefully=t()}(window,(function(){return function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(s,i,function(t){return e[t]}.bind(null,i));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=10)}([function(e,t,r){"use strict";var s,i,a,n,o,l;Object.defineProperty(t,"__esModule",{value:!0}),t.Separator=t.Namon=t.CapsRange=t.Flat=t.NameType=t.NameOrder=t.Surname=t.Title=void 0,function(e){e.US="US",e.UK="UK"}(s||(t.Title=s={})),function(e){e.FATHER="father",e.MOTHER="mother",e.HYPHENATED="hyphenated",e.ALL="all"}(i||(t.Surname=i={})),function(e){e.FIRST_NAME="firstName",e.LAST_NAME="lastName"}(a||(t.NameOrder=a={})),function(e){e.FIRST_NAME="firstName",e.MIDDLE_NAME="middleName",e.LAST_NAME="lastName",e.BIRTH_NAME="birthName"}(n||(t.NameType=n={})),function(e){e.FIRST_NAME="firstName",e.MIDDLE_NAME="middleName",e.LAST_NAME="lastName",e.FIRST_MID="firstMid",e.MID_LAST="midLast",e.ALL="all"}(o||(t.Flat=o={})),function(e){e[e.NONE=0]="NONE",e[e.INITIAL=1]="INITIAL",e[e.ALL=2]="ALL"}(l||(t.CapsRange=l={}));class u{constructor(e,t){this.index=e,this.key=t}static has(e){return u.all.has(e)}static cast(e){var t;const r=String(e).toLowerCase(),s=null===(t=Object.entries(u.aliases).find(([,e])=>e.includes(r)))||void 0===t?void 0:t[0];return u.has(null!=s?s:"")?u.all.get(e):void 0}toString(){return"Namon."+this.key}equal(e){return e instanceof u&&e.index===this.index&&e.key===this.key}}t.Namon=u,u.PREFIX=new u(0,"prefix"),u.FIRST_NAME=new u(1,"firstName"),u.MIDDLE_NAME=new u(2,"middleName"),u.LAST_NAME=new u(3,"lastName"),u.SUFFIX=new u(4,"suffix"),u.values=[u.PREFIX,u.FIRST_NAME,u.MIDDLE_NAME,u.LAST_NAME,u.SUFFIX],u.all=new Map([[u.PREFIX.key,u.PREFIX],[u.FIRST_NAME.key,u.FIRST_NAME],[u.MIDDLE_NAME.key,u.MIDDLE_NAME],[u.LAST_NAME.key,u.LAST_NAME],[u.SUFFIX.key,u.SUFFIX]]),u.aliases={[u.PREFIX.key]:["prefix","px","p"],[u.FIRST_NAME.key]:["firstname","first","fn","f"],[u.MIDDLE_NAME.key]:["middlename","middle","mid","mn","m"],[u.LAST_NAME.key]:["lastname","last","ln","l"],[u.SUFFIX.key]:["suffix","sx","s"]};class h{constructor(e,t){this.name=e,this.token=t}static cast(e){for(const[t,r]of h.all)if(r.token===e||t.toLowerCase()===e.toLowerCase())return r}toString(){return"Separator."+this.name}}t.Separator=h,h.COMMA=new h("comma",","),h.COLON=new h("colon",":"),h.DOUBLE_QUOTE=new h("doubleQuote",'"'),h.EMPTY=new h("empty",""),h.HYPHEN=new h("hyphen","-"),h.PERIOD=new h("period","."),h.SEMI_COLON=new h("semiColon",";"),h.SINGLE_QUOTE=new h("singleQuote","'"),h.SPACE=new h("space"," "),h.UNDERSCORE=new h("underscore","_"),h.all=new Map([[h.COMMA.name,h.COMMA],[h.COLON.name,h.COLON],[h.DOUBLE_QUOTE.name,h.DOUBLE_QUOTE],[h.EMPTY.name,h.EMPTY],[h.HYPHEN.name,h.HYPHEN],[h.PERIOD.name,h.PERIOD],[h.SEMI_COLON.name,h.SEMI_COLON],[h.SINGLE_QUOTE.name,h.SINGLE_QUOTE],[h.SPACE.name,h.SPACE],[h.UNDERSCORE.name,h.UNDERSCORE]]),h.tokens=[...h.all.values()].map(e=>e.token)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UnknownError=t.NotAllowedError=t.ValidationError=t.InputError=t.NameError=t.NameErrorType=void 0;const s=r(2);var i;!function(e){e[e.INPUT=0]="INPUT",e[e.VALIDATION=1]="VALIDATION",e[e.NOT_ALLOWED=2]="NOT_ALLOWED",e[e.UNKNOWN=3]="UNKNOWN"}(i||(t.NameErrorType=i={}));class a extends Error{constructor(e,t,r=i.UNKNOWN){super(t),this.source=e,this.type=r,this.name="NameError"}get sourceAsString(){return"string"==typeof this.source?this.source:(0,s.isStringArray)(this.source)?this.source.join(" "):"<undefined>"}get hasMessage(){return this.message.trim().length>0}toString(){let e=`${this.name} (${this.sourceAsString})`;return this.hasMessage&&(e=`${e}: ${this.message}`),e}}t.NameError=a;t.InputError=class extends a{constructor(e){super(e.source,e.message,i.INPUT),this.name="InputError"}};t.ValidationError=class extends a{constructor(e){super(e.source,e.message,i.VALIDATION),this.nameType=e.nameType,this.name="ValidationError"}toString(){let e=`${this.name} (${this.nameType}='${this.sourceAsString}')`;return this.hasMessage&&(e=`${e}: ${this.message}`),e}};t.NotAllowedError=class extends a{constructor(e){super(e.source,e.message,i.NOT_ALLOWED),this.operation=e.operation,this.name="NotAllowedError"}toString(){let e=`${this.name} (${this.sourceAsString})`;return this.operation&&this.operation.trim().length>0&&(e=`${e} - ${this.operation}`),this.hasMessage&&(e=`${e}: ${this.message}`),e}};t.UnknownError=class extends a{constructor(e){super(e.source,e.message,i.UNKNOWN),this.origin=e.origin,this.name="UnknownError"}toString(){let e=super.toString();return this.origin&&(e+="\n"+this.origin.toString()),e}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isStringArray=t.toggleCase=t.decapitalize=t.capitalize=t.NameIndex=void 0;const s=r(0),i=r(4);class a{static get min(){return i.MIN_NUMBER_OF_NAME_PARTS}static get max(){return i.MAX_NUMBER_OF_NAME_PARTS}constructor(e,t,r,s,i){this.prefix=e,this.firstName=t,this.middleName=r,this.lastName=s,this.suffix=i,this.json=this.toJson}static base(){return new a(-1,0,-1,1,-1)}static when(e,t=2){if(e===s.NameOrder.FIRST_NAME)switch(t){case 2:return new a(-1,0,-1,1,-1);case 3:return new a(-1,0,1,2,-1);case 4:return new a(0,1,2,3,-1);case 5:return new a(0,1,2,3,4);default:return a.base()}else switch(t){case 2:return new a(-1,1,-1,0,-1);case 3:return new a(-1,1,2,0,-1);case 4:return new a(0,2,3,1,-1);case 5:return new a(0,2,3,1,4);default:return a.base()}}static only({prefix:e=-1,firstName:t,middleName:r=-1,lastName:s,suffix:i=-1}){return new a(e,t,r,s,i)}toJson(){return{prefix:this.prefix,firstName:this.firstName,middleName:this.middleName,lastName:this.lastName,suffix:this.suffix}}}t.NameIndex=a,t.capitalize=function(e,t=s.CapsRange.INITIAL){if(!e||t===s.CapsRange.NONE)return e;const[r,i]=[e[0].toUpperCase(),e.slice(1).toLowerCase()];return t===s.CapsRange.INITIAL?r.concat(i):e.toUpperCase()},t.decapitalize=function(e,t=s.CapsRange.INITIAL){if(!e||t===s.CapsRange.NONE)return e;const[r,i]=[e[0].toLowerCase(),e.slice(1)];return t===s.CapsRange.INITIAL?r.concat(i):e.toLowerCase()},t.toggleCase=function(e){return e.split("").map(e=>e===e.toUpperCase()?e.toLowerCase():e.toUpperCase()).join("")},t.isStringArray=function(e){return Array.isArray(e)&&e.length>0&&e.every(e=>"string"==typeof e)}},function(e,t,r){"use strict";var s,i,a,n=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r},o=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.isNameArray=t.LastName=t.FirstName=t.Name=void 0;const l=r(1),u=r(0),h=r(2);class f{constructor(e,t,r){this.type=t,s.set(this,void 0),this.capsRange=null!=r?r:u.CapsRange.INITIAL,this.value=e,r&&this.caps(r)}set value(e){this.validate(e),n(this,s,e,"f"),this.initial=e[0]}get value(){return o(this,s,"f")}get length(){return o(this,s,"f").length}get isPrefix(){return this.type===u.Namon.PREFIX}get isFirstName(){return this.type===u.Namon.FIRST_NAME}get isMiddleName(){return this.type===u.Namon.MIDDLE_NAME}get isLastName(){return this.type===u.Namon.LAST_NAME}get isSuffix(){return this.type===u.Namon.SUFFIX}static prefix(e){return new f(e,u.Namon.PREFIX)}static first(e){return new f(e,u.Namon.FIRST_NAME)}static middle(e){return new f(e,u.Namon.MIDDLE_NAME)}static last(e){return new f(e,u.Namon.LAST_NAME)}static suffix(e){return new f(e,u.Namon.SUFFIX)}initials(){return[this.initial]}toString(){return o(this,s,"f")}equal(e){return e instanceof f&&e.value===this.value&&e.type===this.type}caps(e){return this.value=(0,h.capitalize)(o(this,s,"f"),null!=e?e:this.capsRange),this}decaps(e){return this.value=(0,h.decapitalize)(o(this,s,"f"),null!=e?e:this.capsRange),this}validate(e){if("string"==typeof e&&e.trim().length<1)throw new l.InputError({source:e,message:"must be 1+ characters"})}}t.Name=f,s=new WeakMap;class c extends f{constructor(e,...t){super(e,u.Namon.FIRST_NAME),i.set(this,void 0),t.forEach(this.validate),n(this,i,t,"f")}get hasMore(){return o(this,i,"f").length>0}get length(){return super.length+(this.hasMore?o(this,i,"f").reduce((e,t)=>e+t).length:0)}get asNames(){const e=[f.first(this.value)];return this.hasMore&&e.push(...o(this,i,"f").map(f.first)),e}get more(){return o(this,i,"f")}toString(e=!1){return e&&this.hasMore?`${this.value} ${o(this,i,"f").join(" ")}`.trim():this.value}initials(e=!1){const t=[this.initial];return e&&this.hasMore&&t.push(...o(this,i,"f").map(e=>e[0])),t}caps(e){return e=e||this.capsRange,this.value=(0,h.capitalize)(this.value,e),this.hasMore&&n(this,i,o(this,i,"f").map(t=>(0,h.capitalize)(t,e)),"f"),this}decaps(e){return e=e||this.capsRange,this.value=(0,h.decapitalize)(this.value,e),this.hasMore&&n(this,i,o(this,i,"f").map(t=>(0,h.decapitalize)(t,e)),"f"),this}copyWith(e){var t,r;return new c(null!==(t=null==e?void 0:e.first)&&void 0!==t?t:this.value,...null!==(r=null==e?void 0:e.more)&&void 0!==r?r:o(this,i,"f"))}}t.FirstName=c,i=new WeakMap;class d extends f{constructor(e,t,r=u.Surname.FATHER){super(e,u.Namon.LAST_NAME),this.format=r,a.set(this,void 0),this.validate(t),n(this,a,t,"f")}get father(){return this.value}get mother(){return o(this,a,"f")}get hasMother(){return!!o(this,a,"f")}get length(){var e,t;return super.length+(null!==(t=null===(e=o(this,a,"f"))||void 0===e?void 0:e.length)&&void 0!==t?t:0)}get asNames(){const e=[f.last(this.value)];return o(this,a,"f")&&e.push(f.last(o(this,a,"f"))),e}toString(e){var t;switch(e=null!=e?e:this.format){case u.Surname.FATHER:return this.value;case u.Surname.MOTHER:return null!==(t=this.mother)&&void 0!==t?t:"";case u.Surname.HYPHENATED:return this.hasMother?`${this.value}-${o(this,a,"f")}`:this.value;default:return this.hasMother?`${this.value} ${o(this,a,"f")}`:this.value}}initials(e){const t=[];switch(null!=e?e:this.format){case u.Surname.HYPHENATED:case u.Surname.ALL:t.push(this.initial),o(this,a,"f")&&t.push(o(this,a,"f")[0]);break;case u.Surname.MOTHER:o(this,a,"f")&&t.push(o(this,a,"f")[0]);break;default:t.push(this.initial)}return t}caps(e){return null!=e||(e=this.capsRange),this.value=(0,h.capitalize)(this.value,e),this.hasMother&&n(this,a,(0,h.capitalize)(o(this,a,"f"),e),"f"),this}decaps(e){return null!=e||(e=this.capsRange),this.value=(0,h.decapitalize)(this.value,e),this.hasMother&&n(this,a,(0,h.decapitalize)(o(this,a,"f"),e),"f"),this}copyWith(e){var t,r,s;return new d(null!==(t=null==e?void 0:e.father)&&void 0!==t?t:this.value,null!==(r=null==e?void 0:e.mother)&&void 0!==r?r:this.mother,null!==(s=null==e?void 0:e.format)&&void 0!==s?s:this.format)}}t.LastName=d,a=new WeakMap,t.isNameArray=function(e){return Array.isArray(e)&&e.length>0&&e.every(e=>e instanceof f)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ALLOWED_FORMAT_TOKENS=t.MAX_NUMBER_OF_NAME_PARTS=t.MIN_NUMBER_OF_NAME_PARTS=t.VERSION=void 0,t.VERSION="1.3.1",t.MIN_NUMBER_OF_NAME_PARTS=2,t.MAX_NUMBER_OF_NAME_PARTS=5,t.ALLOWED_FORMAT_TOKENS=" .,_-()[]<>'\"bBfFlLmMnNoOpPsS$"},function(e,t,r){"use strict";var s,i,a,n,o=this&&this.__awaiter||function(e,t,r,s){return new(r||(r=Promise))((function(i,a){function n(e){try{l(s.next(e))}catch(e){a(e)}}function o(e){try{l(s.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((s=s.apply(e,t||[])).next())}))},l=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)},u=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Namefully=void 0;const h=r(4),f=r(3),c=r(1),d=r(2),m=r(0),p=r(8);class N{constructor(e,t){s.add(this),i.set(this,void 0),this.json=this.toJson,u(this,i,l(this,s,"m",a).call(this,e).parse(t),"f")}static tryParse(e,t){try{return new N(p.Parser.build(e,t))}catch(e){return}}static parse(e,t){return o(this,void 0,void 0,(function*(){return p.Parser.buildAsync(e,t).then(e=>new N(e))}))}get config(){return l(this,i,"f").config}get length(){return this.birth.length}get prefix(){var e;return null===(e=l(this,i,"f").prefix)||void 0===e?void 0:e.toString()}get first(){return this.firstName()}get middle(){return this.hasMiddle?this.middleName()[0]:void 0}get hasMiddle(){return l(this,i,"f").has(m.Namon.MIDDLE_NAME)}get last(){return this.lastName()}get suffix(){var e;return null===(e=l(this,i,"f").suffix)||void 0===e?void 0:e.toString()}get birth(){return this.birthName()}get short(){return this.shorten()}get long(){return this.birth}get full(){return this.fullName()}get public(){return this.format("f $l")}get salutation(){return this.format("p l")}get parts(){return l(this,i,"f").toIterable()}get size(){return Array.from(this.parts).length}*[(i=new WeakMap,s=new WeakSet,Symbol.iterator)](){yield*l(this,i,"f").toIterable(!0)}toString(){return this.full}get(e){const t="string"==typeof e?m.Namon.cast(e):e;return(null==t?void 0:t.equal(m.Namon.PREFIX))?l(this,i,"f").prefix:(null==t?void 0:t.equal(m.Namon.FIRST_NAME))?l(this,i,"f").firstName:(null==t?void 0:t.equal(m.Namon.MIDDLE_NAME))?l(this,i,"f").middleName:(null==t?void 0:t.equal(m.Namon.LAST_NAME))?l(this,i,"f").lastName:(null==t?void 0:t.equal(m.Namon.SUFFIX))?l(this,i,"f").suffix:void 0}equal(e){return this.toString()===e.toString()}deepEqual(e){const t=Array.from(e.parts);for(const e of this.parts)if(!t.some(t=>t.equal(e)))return!1;return!0}toJson(){return{prefix:this.prefix,firstName:this.first,middleName:this.middleName(),lastName:this.last,suffix:this.suffix}}has(e){return l(this,i,"f").has(e)}fullName(e){const t=this.config.ending?",":"",r=[];return this.prefix&&r.push(this.prefix),(null!=e?e:this.config.orderedBy)===m.NameOrder.FIRST_NAME?r.push(this.first,...this.middleName(),this.last+t):(r.push(this.last),this.hasMiddle?r.push(this.first,this.middleName().join(" ")+t):r.push(this.first+t)),this.suffix&&r.push(this.suffix),r.join(" ").trim()}birthName(e){return null!=e||(e=this.config.orderedBy),e===m.NameOrder.FIRST_NAME?[this.first,...this.middleName(),this.last].join(" "):[this.last,this.first,...this.middleName()].join(" ")}firstName(e=!0){return l(this,i,"f").firstName.toString(e)}middleName(){return l(this,i,"f").middleName.map(e=>e.value)}lastName(e){return l(this,i,"f").lastName.toString(e)}initials(e){const{orderedBy:t=this.config.orderedBy,only:r=m.NameType.BIRTH_NAME,asJson:s}=null!=e?e:{},a=l(this,i,"f").firstName.initials(),n=l(this,i,"f").middleName.map(e=>e.value[0]),o=l(this,i,"f").lastName.initials();return s?{firstName:a,middleName:n,lastName:o}:r!==m.NameType.BIRTH_NAME?r===m.NameType.FIRST_NAME?a:r===m.NameType.MIDDLE_NAME?n:o:t===m.NameOrder.FIRST_NAME?[...a,...n,...o]:[...o,...a,...n]}shorten(e){null!=e||(e=this.config.orderedBy);const{firstName:t,lastName:r}=l(this,i,"f");return e===m.NameOrder.FIRST_NAME?[t.value,r.toString()].join(" "):[r.toString(),t.value].join(" ")}flatten(e){const{by:t=m.Flat.MIDDLE_NAME,limit:r=20,recursive:s=!1,withMore:a=!1,withPeriod:n=!0,surname:o}=e;if(this.length<=r)return this.full;const{firstName:u,lastName:h,middleName:f}=l(this,i,"f"),c=n?".":"",d=this.hasMiddle,p=u.toString(),N=this.middleName().join(" "),g=h.toString(),v=u.initials(a).join(c+" ")+c,w=h.initials(o).join(c+" ")+c,E=d?f.map(e=>e.value[0]).join(c+" ")+c:"";let y=[];if(this.config.orderedBy===m.NameOrder.FIRST_NAME)switch(t){case m.Flat.FIRST_NAME:y=d?[v,N,g]:[v,g];break;case m.Flat.LAST_NAME:y=d?[p,N,w]:[p,w];break;case m.Flat.MIDDLE_NAME:y=d?[p,E,g]:[p,g];break;case m.Flat.FIRST_MID:y=d?[v,E,g]:[v,g];break;case m.Flat.MID_LAST:y=d?[p,E,w]:[p,w];break;default:y=d?[v,E,w]:[v,w]}else switch(t){case m.Flat.FIRST_NAME:y=d?[g,v,N]:[g,v];break;case m.Flat.LAST_NAME:y=d?[w,p,N]:[w,p];break;case m.Flat.MIDDLE_NAME:y=d?[g,p,E]:[g,p];break;case m.Flat.FIRST_MID:y=d?[g,v,E]:[g,v];break;case m.Flat.MID_LAST:y=d?[w,p,E]:[w,p];break;default:y=d?[w,v,E]:[w,v]}const M=y.join(" ");if(s&&M.length>r){const r=t===m.Flat.FIRST_NAME?m.Flat.MIDDLE_NAME:t===m.Flat.MIDDLE_NAME?m.Flat.LAST_NAME:t===m.Flat.LAST_NAME?m.Flat.FIRST_MID:t===m.Flat.FIRST_MID?m.Flat.MID_LAST:t===m.Flat.MID_LAST||t===m.Flat.ALL?m.Flat.ALL:t;return r===t?M:this.flatten(Object.assign(Object.assign({},e),{by:r}))}return M}zip(e=m.Flat.MID_LAST,t=!0){return this.flatten({limit:0,by:e,withPeriod:t})}format(e){var t;if("short"===e)return this.short;if("long"===e)return this.long;if("public"===e)return this.public;"official"===e&&(e="o");let r="";const i=[];for(const a of e){if(!h.ALLOWED_FORMAT_TOKENS.includes(a))throw new c.NotAllowedError({source:this.full,operation:"format",message:`unsupported character <${a}> from ${e}.`});r+=a,"$"!==a&&(i.push(null!==(t=l(this,s,"m",n).call(this,r))&&void 0!==t?t:""),r="")}return i.join("").trim()}flip(){const e=this.config.orderedBy===m.NameOrder.FIRST_NAME?m.NameOrder.LAST_NAME:m.NameOrder.FIRST_NAME;this.config.update({orderedBy:e})}split(e=/[' -]/g){return this.birth.replace(e," ").split(" ")}join(e=""){return this.split().join(e)}toUpperCase(){return this.birth.toUpperCase()}toLowerCase(){return this.birth.toLowerCase()}toCamelCase(){return(0,d.decapitalize)(this.toPascalCase())}toPascalCase(){return this.split().map(e=>(0,d.capitalize)(e)).join("")}toSnakeCase(){return this.split().map(e=>e.toLowerCase()).join("_")}toHyphenCase(){return this.split().map(e=>e.toLowerCase()).join("-")}toDotCase(){return this.split().map(e=>e.toLowerCase()).join(".")}toToggleCase(){return(0,d.toggleCase)(this.birth)}}t.Namefully=N,a=function(e){if(e instanceof p.Parser)return e;if("string"==typeof e)return new p.StringParser(e);if((0,d.isStringArray)(e))return new p.ArrayStringParser(e);if((0,f.isNameArray)(e))return new p.ArrayNameParser(e);if("object"==typeof e)return new p.NamaParser(e);throw new c.InputError({source:e,message:"Cannot parse raw data; review expected data types."})},n=function(e){var t,r;switch(e){case"b":return this.birth;case"B":return this.birth.toUpperCase();case"f":return this.first;case"F":return this.first.toUpperCase();case"l":return this.last;case"L":return this.last.toUpperCase();case"m":case"M":return"m"===e?this.middleName().join(" "):this.middleName().join(" ").toUpperCase();case"o":case"O":return(e=>{const t=this.config.ending?",":"",r=[];this.prefix&&r.push(this.prefix),r.push((this.last+",").toUpperCase()),this.hasMiddle?r.push(this.first,this.middleName().join(" ")+t):r.push(this.first+t),this.suffix&&r.push(this.suffix);const s=r.join(" ").trim();return"o"===e?s:s.toUpperCase()})(e);case"p":return this.prefix;case"P":return null===(t=this.prefix)||void 0===t?void 0:t.toUpperCase();case"s":return this.suffix;case"S":return null===(r=this.suffix)||void 0===r?void 0:r.toUpperCase();case"$f":return l(this,i,"f").firstName.value[0];case"$F":return l(this,i,"f").firstName.initials(!0).join("");case"$l":return l(this,i,"f").lastName.value[0];case"$L":return l(this,i,"f").lastName.initials().join("");case"$m":return this.hasMiddle?this.middle[0]:void 0;case"$M":return this.hasMiddle?l(this,i,"f").middleName.map(e=>e.value[0]).join(""):void 0;default:return h.ALLOWED_FORMAT_TOKENS.includes(e)?e:void 0}},t.default=(e,t)=>new N(e,t)},function(e,t,r){"use strict";var s,i,a,n,o,l,u,h,f,c,d=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)},m=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0;const p=r(0);class N{get orderedBy(){return d(this,n,"f")}get separator(){return d(this,o,"f")}get title(){return d(this,l,"f")}get ending(){return d(this,u,"f")}get bypass(){return d(this,h,"f")}get surname(){return d(this,f,"f")}get name(){return d(this,a,"f")}constructor(e,t=p.NameOrder.FIRST_NAME,r=p.Separator.SPACE,i=p.Title.UK,c=!1,d=!0,N=p.Surname.FATHER){s.add(this),a.set(this,void 0),n.set(this,void 0),o.set(this,void 0),l.set(this,void 0),u.set(this,void 0),h.set(this,void 0),f.set(this,void 0),m(this,a,e,"f"),m(this,n,t,"f"),m(this,o,r,"f"),m(this,l,i,"f"),m(this,u,c,"f"),m(this,h,d,"f"),m(this,f,N,"f")}static create(e="default"){return i.cache.has(e)||i.cache.set(e,new this(e)),i.cache.get(e)}static merge(e){var t,r,s,a,c,d;if(e){const p=i.create(e.name);return m(p,n,null!==(t=e.orderedBy)&&void 0!==t?t:p.orderedBy,"f"),m(p,o,null!==(r=e.separator)&&void 0!==r?r:p.separator,"f"),m(p,l,null!==(s=e.title)&&void 0!==s?s:p.title,"f"),m(p,u,null!==(a=e.ending)&&void 0!==a?a:p.ending,"f"),m(p,h,null!==(c=e.bypass)&&void 0!==c?c:p.bypass,"f"),m(p,f,null!==(d=e.surname)&&void 0!==d?d:p.surname,"f"),p}return i.create()}copyWith(e={}){const{name:t,orderedBy:r,separator:a,title:p,ending:N,bypass:g,surname:v}=e,w=i.create(d(this,s,"m",c).call(this,null!=t?t:this.name+"_copy"));return m(w,n,null!=r?r:this.orderedBy,"f"),m(w,o,null!=a?a:this.separator,"f"),m(w,l,null!=p?p:this.title,"f"),m(w,u,null!=N?N:this.ending,"f"),m(w,h,null!=g?g:this.bypass,"f"),m(w,f,null!=v?v:this.surname,"f"),w}clone(){return this.copyWith()}reset(){m(this,n,p.NameOrder.FIRST_NAME,"f"),m(this,o,p.Separator.SPACE,"f"),m(this,l,p.Title.UK,"f"),m(this,u,!1,"f"),m(this,h,!0,"f"),m(this,f,p.Surname.FATHER,"f"),i.cache.set(this.name,this)}update({orderedBy:e,title:t,ending:r}){const s=i.cache.get(this.name);s&&(e!==d(this,n,"f")&&m(s,n,e,"f"),t!==d(this,l,"f")&&m(s,l,t,"f"),r!==d(this,u,"f")&&m(s,u,r,"f"))}}t.Config=N,i=N,a=new WeakMap,n=new WeakMap,o=new WeakMap,l=new WeakMap,u=new WeakMap,h=new WeakMap,f=new WeakMap,s=new WeakSet,c=function e(t){return t===this.name||i.cache.has(t)?d(this,s,"m",e).call(this,t+"_copy"):t},N.cache=new Map},function(e,t,r){"use strict";var s,i,a,n,o,l,u,h,f,c,d,m,p,N,g,v,w=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)},E=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Validators=t.ArrayNameValidator=t.ArrayStringValidator=t.NamaValidator=void 0;const y=r(0),M=r(2),_=r(3),A=r(1),S=r(4);class I{}I.base=/[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\u0400-\u04FFΆ-ωΑ-ώ]/,I.namon=new RegExp(`^${I.base.source}+(([' -]${I.base.source})?${I.base.source}*)*$`),I.firstName=I.namon,I.middleName=new RegExp(`^${I.base.source}+(([' -]${I.base.source})?${I.base.source}*)*$`),I.lastName=I.namon;const T=e=>(0,_.isNameArray)(e)?e.map(e=>e.toString()).join(" "):"";class F{static create(){return w(this,s,"f",i)||E(this,s,new s,"f",i)}validate(e,t){if(e instanceof _.Name)x.create().validate(e,t);else{if("string"!=typeof e)throw new A.InputError({source:typeof e,message:"expecting types of string or Name"});if(!I.namon.test(e))throw new A.ValidationError({source:e,nameType:"namon",message:"invalid name content failing namon regex"})}}}s=F,i={value:void 0};class b{static create(){return w(this,a,"f",n)||E(this,a,new a,"f",n)}validate(e){if(e instanceof _.FirstName)e.asNames.forEach(e=>this.validate(e.value));else{if("string"!=typeof e)throw new A.InputError({source:typeof e,message:"expecting types string or FirstName"});if(!I.firstName.test(e))throw new A.ValidationError({source:e,nameType:"firstName",message:"invalid name content failing firstName regex"})}}}a=b,n={value:void 0};class O{static create(){return w(this,o,"f",l)||E(this,o,new o,"f",l)}validate(e){if("string"==typeof e){if(!I.middleName.test(e))throw new A.ValidationError({source:e,nameType:"middleName",message:"invalid name content failing middleName regex"})}else{if(!Array.isArray(e))throw new A.InputError({source:typeof e,message:"expecting types of string, string[] or Name[]"});try{const t=F.create();for(const r of e)t.validate(r,y.Namon.MIDDLE_NAME)}catch(t){throw new A.ValidationError({source:T(e),nameType:"middleName",message:null==t?void 0:t.message})}}}}o=O,l={value:void 0};class P{static create(){return w(this,u,"f",h)||E(this,u,new u,"f",h)}validate(e){if(e instanceof _.LastName)e.asNames.forEach(e=>this.validate(e.value));else{if("string"!=typeof e)throw new A.InputError({source:typeof e,message:"expecting types string or LastName"});if(!I.lastName.test(e))throw new A.ValidationError({source:e,nameType:"lastName",message:"invalid name content failing lastName regex"})}}}u=P,h={value:void 0};class x{static create(){return w(this,f,"f",c)||E(this,f,new f,"f",c)}validate(e,t){if(t&&e.type!==t)throw new A.ValidationError({source:e.toString(),nameType:e.type.toString(),message:"wrong name type; only Namon types are supported"});if(!I.namon.test(e.value))throw new A.ValidationError({source:e.toString(),nameType:e.type.toString(),message:"invalid name content failing namon regex"})}}f=x,c={value:void 0};class L{static create(){return w(this,d,"f",m)||E(this,d,new d,"f",m)}validate(e){this.validateKeys(e),j.firstName.validate(e.get(y.Namon.FIRST_NAME)),j.lastName.validate(e.get(y.Namon.LAST_NAME)),e.has(y.Namon.PREFIX)&&j.namon.validate(e.get(y.Namon.PREFIX)),e.has(y.Namon.SUFFIX)&&j.namon.validate(e.get(y.Namon.SUFFIX))}validateKeys(e){if(!e.size)throw new A.InputError({source:void 0,message:"Map<k,v> must not be empty"});if(e.size<S.MIN_NUMBER_OF_NAME_PARTS||e.size>S.MAX_NUMBER_OF_NAME_PARTS)throw new A.InputError({source:[...e.values()],message:`expecting ${S.MIN_NUMBER_OF_NAME_PARTS}-${S.MAX_NUMBER_OF_NAME_PARTS} fields`});if(!e.has(y.Namon.FIRST_NAME))throw new A.InputError({source:[...e.values()],message:'"firstName" is a required key'});if(!e.has(y.Namon.LAST_NAME))throw new A.InputError({source:[...e.values()],message:'"lastName" is a required key'})}}t.NamaValidator=L,d=L,m={value:void 0};t.ArrayStringValidator=class extends class{validate(e){if(0===e.length||e.length<S.MIN_NUMBER_OF_NAME_PARTS||e.length>S.MAX_NUMBER_OF_NAME_PARTS)throw new A.InputError({source:e.map(e=>e.toString()),message:`expecting a list of ${S.MIN_NUMBER_OF_NAME_PARTS}-${S.MAX_NUMBER_OF_NAME_PARTS} elements`})}}{constructor(e=M.NameIndex.base()){super(),this.index=e}validate(e){this.validateIndex(e),j.firstName.validate(e[this.index.firstName]),j.lastName.validate(e[this.index.lastName]),e.length>=3&&j.middleName.validate(e[this.index.middleName]),e.length>=4&&j.namon.validate(e[this.index.prefix]),5===e.length&&j.namon.validate(e[this.index.suffix])}validateIndex(e){super.validate(e)}};class R{constructor(){p.add(this)}static create(){return w(this,N,"f",g)||E(this,N,new N,"f",g)}validate(e){if(e.length<S.MIN_NUMBER_OF_NAME_PARTS)throw new A.InputError({source:T(e),message:`expecting at least ${S.MIN_NUMBER_OF_NAME_PARTS} elements`});if(!w(this,p,"m",v).call(this,e))throw new A.InputError({source:T(e),message:"both first and last names are required"})}}t.ArrayNameValidator=R,N=R,p=new WeakSet,v=function(e){const t={};for(const r of e)(r.isFirstName||r.isLastName)&&(t[r.type.key]=r.toString());return Object.keys(t).length===S.MIN_NUMBER_OF_NAME_PARTS},g={value:void 0};class j{}t.Validators=j,j.namon=F.create(),j.nama=L.create(),j.prefix=F.create(),j.firstName=b.create(),j.middleName=O.create(),j.lastName=P.create(),j.suffix=F.create()},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayNameParser=t.NamaParser=t.ArrayStringParser=t.StringParser=t.Parser=void 0;const s=r(6),i=r(2),a=r(1),n=r(9),o=r(0),l=r(3),u=r(7);class h{constructor(e){this.raw=e}static build(e,t){const r=e.trim().split(o.Separator.SPACE.token),s=r.length;if(t instanceof i.NameIndex){const e=Object.entries(t.json()).filter(([,e])=>e>-1&&e<s).map(([e,t])=>new l.Name(r[t],o.Namon.all.get(e)));return new d(e)}if(s<2)throw new a.InputError({source:e,message:"expecting at least 2 name parts"});if(2===s||3===s)return new f(e);{const e=r.pop(),[t,...s]=r;return new c([t,s.join(" "),e])}}static buildAsync(e,t){try{return Promise.resolve(h.build(e,t))}catch(e){return Promise.reject(e)}}}t.Parser=h;class f extends h{parse(e){const t=s.Config.merge(e),r=this.raw.split(t.separator.token);return new c(r).parse(t)}}t.StringParser=f;class c extends h{parse(e){const t=s.Config.merge(e),r=this.raw.map(e=>e.trim()),a=i.NameIndex.when(t.orderedBy,r.length),o=new u.ArrayStringValidator(a);t.bypass?o.validateIndex(r):o.validate(r);const{firstName:h,lastName:f,middleName:c,prefix:d,suffix:m}=a,p=new n.FullName(t).setFirstName(new l.FirstName(r[h])).setLastName(new l.LastName(r[f]));return r.length>=3&&p.setMiddleName(r[c].split(t.separator.token)),r.length>=4&&p.setPrefix(l.Name.prefix(r[d])),5===r.length&&p.setSuffix(l.Name.suffix(r[m])),p}}t.ArrayStringParser=c;t.NamaParser=class extends h{parse(e){const t=s.Config.merge(e),r=new Map(Object.entries(this.raw).map(([e,t])=>{const r=o.Namon.cast(e);if(!r)throw new a.InputError({source:Object.values(this.raw).join(" "),message:`unsupported key "${e}"`});return[r,t]}));return t.bypass?u.Validators.nama.validateKeys(r):u.Validators.nama.validate(r),n.FullName.parse(this.raw,t)}};class d extends h{parse(e){u.ArrayNameValidator.create().validate(this.raw);const t=new n.FullName(e);for(const e of this.raw)if(e.isPrefix)t.setPrefix(e);else if(e.isSuffix)t.setSuffix(e);else if(e.isFirstName)t.setFirstName(e instanceof l.FirstName?e:new l.FirstName(e.value));else if(e.isMiddleName)t.middleName.push(e);else if(e.isLastName){const r=e instanceof l.LastName?e.mother:void 0;t.setLastName(new l.LastName(e.value,r,t.config.surname))}return t}}t.ArrayNameParser=d},function(e,t,r){"use strict";var s,i,a,n,o,l,u=this&&this.__classPrivateFieldSet||function(e,t,r,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,r):i?i.value=r:t.set(e,r),r},h=this&&this.__classPrivateFieldGet||function(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(e):s?s.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.FullName=void 0;const f=r(6),c=r(7),d=r(0),m=r(1),p=r(3);class N{constructor(e){s.set(this,void 0),i.set(this,void 0),a.set(this,[]),n.set(this,void 0),o.set(this,void 0),l.set(this,void 0),u(this,l,f.Config.merge(e),"f")}get config(){return h(this,l,"f")}get prefix(){return h(this,s,"f")}get firstName(){return h(this,i,"f")}get lastName(){return h(this,n,"f")}get middleName(){return h(this,a,"f")}get suffix(){return h(this,o,"f")}static parse(e,t){var r;try{const{prefix:s,firstName:i,middleName:a,lastName:n,suffix:o}=e;return new N(t).setPrefix(s).setFirstName("string"==typeof i?i:new p.FirstName(i.value,...null!==(r=i.more)&&void 0!==r?r:[])).setMiddleName("string"==typeof a?[a]:null!=a?a:[]).setLastName("string"==typeof n?n:new p.LastName(n.father,n.mother)).setSuffix(o)}catch(t){if(t instanceof m.NameError)throw t;throw new m.UnknownError({source:Object.values(e).join(" "),message:"could not parse JSON content",origin:t instanceof Error?t:new Error(String(t))})}}setPrefix(e){if(!e)return this;h(this,l,"f").bypass||c.Validators.prefix.validate(e);const t=e instanceof p.Name?e.value:e;return u(this,s,p.Name.prefix(h(this,l,"f").title!==d.Title.US||t.endsWith(".")?t:t+"."),"f"),this}setFirstName(e){return h(this,l,"f").bypass||c.Validators.firstName.validate(e),u(this,i,e instanceof p.FirstName?e:new p.FirstName(e),"f"),this}setLastName(e){return h(this,l,"f").bypass||c.Validators.lastName.validate(e),u(this,n,e instanceof p.LastName?e:new p.LastName(e),"f"),this}setMiddleName(e){return Array.isArray(e)?(h(this,l,"f").bypass||c.Validators.middleName.validate(e),u(this,a,e.map(e=>e instanceof p.Name?e:p.Name.middle(e)),"f"),this):this}setSuffix(e){return e?(h(this,l,"f").bypass||c.Validators.suffix.validate(e),u(this,o,p.Name.suffix(e instanceof p.Name?e.value:e),"f"),this):this}has(e){const t="string"==typeof e?d.Namon.cast(e):e;return!!t&&(t.equal(d.Namon.PREFIX)?!!h(this,s,"f"):t.equal(d.Namon.SUFFIX)?!!h(this,o,"f"):!t.equal(d.Namon.MIDDLE_NAME)||h(this,a,"f").length>0)}toString(){return Array.from(this.toIterable(!0)).join(" ")}*toIterable(e=!1){h(this,s,"f")&&(yield h(this,s,"f")),e?(yield*h(this,i,"f").asNames,yield*h(this,a,"f"),yield*h(this,n,"f").asNames):(yield h(this,i,"f"),yield*h(this,a,"f"),yield h(this,n,"f")),h(this,o,"f")&&(yield h(this,o,"f"))}*[(s=new WeakMap,i=new WeakMap,a=new WeakMap,n=new WeakMap,o=new WeakMap,l=new WeakMap,Symbol.iterator)](){yield*this.toIterable(!0)}}t.FullName=N},function(e,t,r){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,i)}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||s(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.NameIndex=t.Parser=t.version=void 0;const a=r(5);i(r(11),t),i(r(6),t);var n=r(4);Object.defineProperty(t,"version",{enumerable:!0,get:function(){return n.VERSION}}),i(r(1),t),i(r(9),t),i(r(3),t),i(r(5),t);var o=r(8);Object.defineProperty(t,"Parser",{enumerable:!0,get:function(){return o.Parser}}),i(r(0),t);var l=r(2);Object.defineProperty(t,"NameIndex",{enumerable:!0,get:function(){return l.NameIndex}}),t.default=a.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.NameBuilder=void 0;const s=r(5),i=r(7);class a extends class{constructor(e,t,r,s){this.prebuild=e,this.postbuild=t,this.preclear=r,this.postclear=s,this.queue=[],this.instance=null}get size(){return this.queue.length}removeFirst(){return this.queue.length>0?this.queue.shift():void 0}removeLast(){return this.queue.length>0?this.queue.pop():void 0}addFirst(e){this.queue.unshift(e)}addLast(e){this.queue.push(e)}add(...e){this.queue.push(...e)}remove(e){const t=this.queue.indexOf(e);return-1!==t&&(this.queue.splice(t,1),!0)}removeWhere(e){this.queue=this.queue.filter(t=>!e(t))}retainWhere(e){this.queue=this.queue.filter(e)}clear(){var e,t;null!==this.instance&&(null===(e=this.preclear)||void 0===e||e.call(this,this.instance)),this.queue=[],null===(t=this.postclear)||void 0===t||t.call(this),this.instance=null}}{constructor(e,t,r,s,i){super(t,r,s,i),this.add(...e)}static create(e){return new a(e?[e]:[])}static of(...e){return new a(e)}static use({names:e,prebuild:t,postbuild:r,preclear:s,postclear:i}){return new a(null!=e?e:[],t,r,s,i)}build(e){var t,r;null===(t=this.prebuild)||void 0===t||t.call(this);const a=[...this.queue];return i.ArrayNameValidator.create().validate(a),this.instance=new s.Namefully(a,e),null===(r=this.postbuild)||void 0===r||r.call(this,this.instance),this.instance}}t.NameBuilder=a}])}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "namefully",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Handle personal names in a particular order, way, or shape.",
|
|
5
5
|
"author": "Ralph Florent",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"start": "webpack --config webpack.dev.js --display=errors-only && node ./build/example/index.js",
|
|
16
16
|
"format": "prettier --write '{src,test}/**/*.ts'",
|
|
17
17
|
"lint": "eslint 'src/**/*.ts' --fix",
|
|
18
|
-
"test": "jest --
|
|
18
|
+
"test": "jest --coverage",
|
|
19
19
|
"prebuild": "shx rm -rf dist build",
|
|
20
20
|
"build": "tsc && tsc -p tsconfig.dts.json && webpack --config webpack.prod.js --progress",
|
|
21
21
|
"prepublish": "npm run format && npm run build"
|