namefully 1.2.1 → 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.
@@ -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(a){if(t[a])return t[a].exports;var s=t[a]={i:a,l:!1,exports:{}};return e[a].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},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 a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(a,s,function(t){return e[t]}.bind(null,s));return a},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=9)}([function(e,t,r){"use strict";var a,s,i,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"}(a||(t.Title=a={})),function(e){e.FATHER="father",e.MOTHER="mother",e.HYPHENATED="hyphenated",e.ALL="all"}(s||(t.Surname=s={})),function(e){e.FIRST_NAME="firstName",e.LAST_NAME="lastName"}(i||(t.NameOrder=i={})),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 h{constructor(e,t){this.index=e,this.key=t}static has(e){return h.all.has(e)}static cast(e){return h.has(e)?h.all.get(e):void 0}toString(){return"Namon."+this.key}equal(e){return e instanceof h&&e.index===this.index&&e.key===this.key}}t.Namon=h,h.PREFIX=new h(0,"prefix"),h.FIRST_NAME=new h(1,"firstName"),h.MIDDLE_NAME=new h(2,"middleName"),h.LAST_NAME=new h(3,"lastName"),h.SUFFIX=new h(4,"suffix"),h.values=[h.PREFIX,h.FIRST_NAME,h.MIDDLE_NAME,h.LAST_NAME,h.SUFFIX],h.all=new Map([[h.PREFIX.key,h.PREFIX],[h.FIRST_NAME.key,h.FIRST_NAME],[h.MIDDLE_NAME.key,h.MIDDLE_NAME],[h.LAST_NAME.key,h.LAST_NAME],[h.SUFFIX.key,h.SUFFIX]]);class u{constructor(e,t){this.name=e,this.token=t}toString(){return"Separator."+this.name}}t.Separator=u,u.COMMA=new u("comma",","),u.COLON=new u("colon",":"),u.DOUBLE_QUOTE=new u("doubleQuote",'"'),u.EMPTY=new u("empty",""),u.HYPHEN=new u("hyphen","-"),u.PERIOD=new u("period","."),u.SEMI_COLON=new u("semiColon",";"),u.SINGLE_QUOTE=new u("singleQuote","'"),u.SPACE=new u("space"," "),u.UNDERSCORE=new u("underscore","_"),u.all=new Map([[u.COMMA.name,u.COMMA],[u.COLON.name,u.COLON],[u.DOUBLE_QUOTE.name,u.DOUBLE_QUOTE],[u.EMPTY.name,u.EMPTY],[u.HYPHEN.name,u.HYPHEN],[u.PERIOD.name,u.PERIOD],[u.SEMI_COLON.name,u.SEMI_COLON],[u.SINGLE_QUOTE.name,u.SINGLE_QUOTE],[u.SPACE.name,u.SPACE],[u.UNDERSCORE.name,u.UNDERSCORE]]),u.tokens=[...u.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 a=r(2);var s;!function(e){e[e.INPUT=0]="INPUT",e[e.VALIDATION=1]="VALIDATION",e[e.NOT_ALLOWED=2]="NOT_ALLOWED",e[e.UNKNOWN=3]="UNKNOWN"}(s||(t.NameErrorType=s={}));class i extends Error{constructor(e,t,r=s.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,a.isNameArray)(this.source)&&(e=this.source.map(e=>e.toString()).join(" ")),(0,a.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=i;t.InputError=class extends i{constructor(e){super(e.source,e.message,s.INPUT),this.name="InputError"}};t.ValidationError=class extends i{constructor(e){super(e.source,e.message,s.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 i{constructor(e){super(e.source,e.message,s.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 i{constructor(e){super(e.source,e.message,s.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 a=r(4),s=r(3),i=r(0);class n{static get min(){return a.MIN_NUMBER_OF_NAME_PARTS}static get max(){return a.MAX_NUMBER_OF_NAME_PARTS}constructor(e,t,r,a,s){this.prefix=e,this.firstName=t,this.middleName=r,this.lastName=a,this.suffix=s}static base(){return new this(-1,0,-1,1,-1)}static when(e,t=2){if(e===i.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()}}}t.NameIndex=n,t.capitalize=function(e,t=i.CapsRange.INITIAL){if(!e||t===i.CapsRange.NONE)return e;const r=e[0].toUpperCase(),a=e.slice(1).toLowerCase();return t===i.CapsRange.INITIAL?r.concat(a):e.toUpperCase()},t.decapitalize=function(e,t=i.CapsRange.INITIAL){if(!e||t===i.CapsRange.NONE)return e;const r=e[0].toLowerCase(),a=e.slice(1);return t===i.CapsRange.INITIAL?r.concat(a):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 s.Name)}},function(e,t,r){"use strict";var a,s,i,n=this&&this.__classPrivateFieldSet||function(e,t,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?s.call(e,r):s?s.value=r:t.set(e,r),r},o=this&&this.__classPrivateFieldGet||function(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.LastName=t.FirstName=t.Name=void 0;const l=r(1),h=r(0),u=r(2);class c{constructor(e,t,r){this.type=t,a.set(this,void 0),this.capsRange=null!=r?r:h.CapsRange.INITIAL,this.value=e,r&&this.caps(r)}set value(e){this.validate(e),n(this,a,e,"f"),this.initial=e[0]}get value(){return o(this,a,"f")}get length(){return o(this,a,"f").length}get isPrefix(){return this.type===h.Namon.PREFIX}get isFirstName(){return this.type===h.Namon.FIRST_NAME}get isMiddleName(){return this.type===h.Namon.MIDDLE_NAME}get isLastName(){return this.type===h.Namon.LAST_NAME}get isSuffix(){return this.type===h.Namon.SUFFIX}static prefix(e){return new this(e,h.Namon.PREFIX)}static first(e){return new this(e,h.Namon.FIRST_NAME)}static middle(e){return new this(e,h.Namon.MIDDLE_NAME)}static last(e){return new this(e,h.Namon.LAST_NAME)}static suffix(e){return new this(e,h.Namon.SUFFIX)}initials(){return[this.initial]}toString(){return o(this,a,"f")}equal(e){return e instanceof c&&e.value===this.value&&e.type===this.type}caps(e){return this.value=(0,u.capitalize)(o(this,a,"f"),null!=e?e:this.capsRange),this}decaps(e){return this.value=(0,u.decapitalize)(o(this,a,"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,a=new WeakMap;class f extends c{constructor(e,...t){super(e,h.Namon.FIRST_NAME),s.set(this,void 0),t.forEach(e=>this.validate(e)),n(this,s,t,"f")}get hasMore(){return o(this,s,"f").length>0}get length(){return super.length+(this.hasMore?o(this,s,"f").reduce((e,t)=>e+t).length:0)}get asNames(){const e=[c.first(this.value)];return this.hasMore&&e.push(...o(this,s,"f").map(e=>c.first(e))),e}get more(){return o(this,s,"f")}toString(e=!1){return e&&this.hasMore?`${this.value} ${o(this,s,"f").join(" ")}`.trim():this.value}initials(e=!1){const t=[this.initial];return e&&this.hasMore&&t.push(...o(this,s,"f").map(e=>e[0])),t}caps(e){return e=e||this.capsRange,this.value=(0,u.capitalize)(this.value,e),this.hasMore&&n(this,s,o(this,s,"f").map(t=>(0,u.capitalize)(t,e)),"f"),this}decaps(e){return e=e||this.capsRange,this.value=(0,u.decapitalize)(this.value,e),this.hasMore&&n(this,s,o(this,s,"f").map(t=>(0,u.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,s,"f"))}}t.FirstName=f,s=new WeakMap;class m extends c{constructor(e,t,r=h.Surname.FATHER){super(e,h.Namon.LAST_NAME),this.format=r,i.set(this,void 0),this.validate(t),n(this,i,t,"f")}get father(){return this.value}get mother(){return o(this,i,"f")}get hasMother(){return!!o(this,i,"f")}get length(){var e,t;return super.length+(null!==(t=null===(e=o(this,i,"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,i,"f"))),e}toString(e){var t;switch(e=null!=e?e:this.format){case h.Surname.FATHER:return this.value;case h.Surname.MOTHER:return null!==(t=this.mother)&&void 0!==t?t:"";case h.Surname.HYPHENATED:return this.hasMother?`${this.value}-${o(this,i,"f")}`:this.value;case h.Surname.ALL:return this.hasMother?`${this.value} ${o(this,i,"f")}`:this.value}}initials(e){const t=[];switch(e=e||this.format){case h.Surname.MOTHER:this.hasMother&&t.push(o(this,i,"f")[0]);break;case h.Surname.HYPHENATED:case h.Surname.ALL:t.push(this.initial),this.hasMother&&t.push(o(this,i,"f")[0]);break;case h.Surname.FATHER:default:t.push(this.initial)}return t}caps(e){return e=e||this.capsRange,this.value=(0,u.capitalize)(this.value,e),this.hasMother&&n(this,i,(0,u.capitalize)(o(this,i,"f"),e),"f"),this}decaps(e){return e=e||this.capsRange,this.value=(0,u.decapitalize)(this.value,e),this.hasMother&&n(this,i,(0,u.decapitalize)(o(this,i,"f"),e),"f"),this}copyWith(e){var t,r,a;return new m(null!==(t=e.father)&&void 0!==t?t:this.value,null!==(r=e.mother)&&void 0!==r?r:this.mother,null!==(a=e.format)&&void 0!==a?a:this.format)}}t.LastName=m,i=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.2.1",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 a,s,i,n,o,l,h,u,c,f,m=this&&this.__classPrivateFieldGet||function(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.value:t.get(e)},d=this&&this.__classPrivateFieldSet||function(e,t,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?s.call(e,r):s?s.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Config=void 0;const N=r(0);class p{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,h,"f")}get bypass(){return m(this,u,"f")}get surname(){return m(this,c,"f")}get name(){return m(this,i,"f")}constructor(e,t=N.NameOrder.FIRST_NAME,r=N.Separator.SPACE,s=N.Title.UK,f=!1,m=!0,p=N.Surname.FATHER){a.add(this),i.set(this,void 0),n.set(this,void 0),o.set(this,void 0),l.set(this,void 0),h.set(this,void 0),u.set(this,void 0),c.set(this,void 0),d(this,i,e,"f"),d(this,n,t,"f"),d(this,o,r,"f"),d(this,l,s,"f"),d(this,h,f,"f"),d(this,u,m,"f"),d(this,c,p,"f")}static create(e="default"){return s.cache.has(e)||s.cache.set(e,new this(e)),s.cache.get(e)}static merge(e){var t,r,a,i,f,m;if(e){const N=s.create(e.name);return d(N,n,null!==(t=e.orderedBy)&&void 0!==t?t:N.orderedBy,"f"),d(N,o,null!==(r=e.separator)&&void 0!==r?r:N.separator,"f"),d(N,l,null!==(a=e.title)&&void 0!==a?a:N.title,"f"),d(N,h,null!==(i=e.ending)&&void 0!==i?i:N.ending,"f"),d(N,u,null!==(f=e.bypass)&&void 0!==f?f:N.bypass,"f"),d(N,c,null!==(m=e.surname)&&void 0!==m?m:N.surname,"f"),N}return s.create()}copyWith(e={}){const{name:t,orderedBy:r,separator:i,title:N,ending:p,bypass:w,surname:g}=e,v=s.create(m(this,a,"m",f).call(this,null!=t?t:this.name+"_copy"));return d(v,n,null!=r?r:this.orderedBy,"f"),d(v,o,null!=i?i:this.separator,"f"),d(v,l,null!=N?N:this.title,"f"),d(v,h,null!=p?p:this.ending,"f"),d(v,u,null!=w?w:this.bypass,"f"),d(v,c,null!=g?g:this.surname,"f"),v}clone(){return this.copyWith()}reset(){d(this,n,N.NameOrder.FIRST_NAME,"f"),d(this,o,N.Separator.SPACE,"f"),d(this,l,N.Title.UK,"f"),d(this,h,!1,"f"),d(this,u,!0,"f"),d(this,c,N.Surname.FATHER,"f"),s.cache.set(this.name,this)}updateOrder(e){e&&e!==m(this,n,"f")&&d(s.cache.get(this.name),n,e,"f")}}t.Config=p,s=p,i=new WeakMap,n=new WeakMap,o=new WeakMap,l=new WeakMap,h=new WeakMap,u=new WeakMap,c=new WeakMap,a=new WeakSet,f=function e(t){return t===this.name||s.cache.has(t)?m(this,a,"m",e).call(this,t+"_copy"):t},p.cache=new Map},function(e,t,r){"use strict";var a,s,i,n,o,l,h=this&&this.__classPrivateFieldSet||function(e,t,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?s.call(e,r):s?s.value=r:t.set(e,r),r},u=this&&this.__classPrivateFieldGet||function(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.FullName=void 0;const c=r(5),f=r(1),m=r(3),d=r(0),N=r(7);class p{constructor(e){a.set(this,void 0),s.set(this,void 0),i.set(this,[]),n.set(this,void 0),o.set(this,void 0),l.set(this,void 0),h(this,l,c.Config.merge(e),"f")}get config(){return u(this,l,"f")}get prefix(){return u(this,a,"f")}get firstName(){return u(this,s,"f")}get lastName(){return u(this,n,"f")}get middleName(){return u(this,i,"f")}get suffix(){return u(this,o,"f")}static parse(e,t){try{const r=new p(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;u(this,l,"f").bypass||N.Validators.prefix.validate(e);const t=e instanceof m.Name?e.value:e;return h(this,a,m.Name.prefix(u(this,l,"f").title===d.Title.US?t+".":t),"f"),this}setFirstName(e){return u(this,l,"f").bypass||N.Validators.firstName.validate(e),h(this,s,e instanceof m.FirstName?e:new m.FirstName(e),"f"),this}setLastName(e){return u(this,l,"f").bypass||N.Validators.lastName.validate(e),h(this,n,e instanceof m.LastName?e:new m.LastName(e),"f"),this}setMiddleName(e){return Array.isArray(e)?(u(this,l,"f").bypass||N.Validators.middleName.validate(e),h(this,i,e.map(e=>e instanceof m.Name?e:m.Name.middle(e)),"f"),this):this}setSuffix(e){return e?(u(this,l,"f").bypass||N.Validators.suffix.validate(e),h(this,o,m.Name.suffix(e instanceof m.Name?e.value:e),"f"),this):this}has(e){return e.equal(d.Namon.PREFIX)?!!u(this,a,"f"):e.equal(d.Namon.SUFFIX)?!!u(this,o,"f"):!e.equal(d.Namon.MIDDLE_NAME)||u(this,i,"f").length>0}}t.FullName=p,a=new WeakMap,s=new WeakMap,i=new WeakMap,n=new WeakMap,o=new WeakMap,l=new WeakMap},function(e,t,r){"use strict";var a,s,i,n,o,l,h,u,c,f,m,d,N,p,w,g,v=this&&this.__classPrivateFieldGet||function(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.value:t.get(e)},E=this&&this.__classPrivateFieldSet||function(e,t,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?s.call(e,r):s?s.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,a,"f",s)||E(this,a,new this,"f",s)}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"})}}}a=I,s={value:void 0};class F{static create(){return v(this,i,"f",n)||E(this,i,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"})}}}i=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,h,"f",u)||E(this,h,new this,"f",u)}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"})}}}h=P,u={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){switch(this.validateIndex(e),e.length){case 2:R.firstName.validate(e[this.index.firstName]),R.lastName.validate(e[this.index.lastName]);break;case 3:R.firstName.validate(e[this.index.firstName]),R.middleName.validate(e[this.index.middleName]),R.lastName.validate(e[this.index.lastName]);break;case 4:R.namon.validate(e[this.index.prefix]),R.firstName.validate(e[this.index.firstName]),R.middleName.validate(e[this.index.middleName]),R.lastName.validate(e[this.index.lastName]);break;case 5:R.namon.validate(e[this.index.prefix]),R.firstName.validate(e[this.index.firstName]),R.middleName.validate(e[this.index.middleName]),R.lastName.validate(e[this.index.lastName]),R.namon.validate(e[this.index.suffix])}}validateIndex(e){super.validate(e)}};class x{constructor(){N.add(this)}static create(){return v(this,p,"f",w)||E(this,p,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,N,"m",g).call(this,e))throw new y.InputError({source:e,message:"both first and last names are required"})}}t.ArrayNameValidator=x,p=x,N=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 a,s,i=this&&this.__classPrivateFieldGet||function(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.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(6),o=r(5),l=r(2),h=r(7),u=r(3),c=r(0),f=r(1);class m{constructor(e){this.raw=e}static build(e){const t=e.trim().split(c.Separator.SPACE.token),r=t.length;if(r<2)throw new f.InputError({source:e,message:"cannot build from invalid input"});if(2===r||3===r)return new d(e);{const e=t.pop(),[r,...a]=t;return new N([r,a.join(" "),e])}}static buildAsync(e){try{return Promise.resolve(m.build(e))}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 N(r).parse(e)}}t.StringParser=d;class N extends m{parse(e){const t=o.Config.merge(e),r=new n.FullName(t),a=this.raw.map(e=>e.trim()),s=l.NameIndex.when(t.orderedBy,a.length),i=new h.ArrayStringValidator(s);t.bypass?i.validateIndex(a):i.validate(a);const{firstName:c,lastName:f,middleName:m,prefix:d,suffix:N}=s;return r.setFirstName(new u.FirstName(a[c])),r.setLastName(new u.LastName(a[f])),a.length>=3&&r.setMiddleName(a[m].split(t.separator.token)),a.length>=4&&r.setPrefix(u.Name.prefix(a[d])),5===a.length&&r.setSuffix(u.Name.suffix(a[N])),r}}t.ArrayStringParser=N;t.NamaParser=class extends m{constructor(){super(...arguments),a.add(this)}parse(e){const t=o.Config.merge(e);return t.bypass?h.NamaValidator.create().validateKeys(i(this,a,"m",s).call(this)):h.NamaValidator.create().validate(i(this,a,"m",s).call(this)),n.FullName.parse(this.raw,t)}},a=new WeakSet,s=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]}))};t.ArrayNameParser=class extends m{parse(e){const t=o.Config.merge(e),r=new n.FullName(t);h.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 u.FirstName?e:new u.FirstName(e.value));else if(e.isMiddleName)r.middleName.push(e);else if(e.isLastName){const a=new u.LastName(e.value,e instanceof u.LastName?e.mother:void 0,t.surname);r.setLastName(a)}return r}}},function(e,t,r){"use strict";var a=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,s)}:function(e,t,r,a){void 0===a&&(a=r),e[a]=t[r]}),s=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||a(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.NameIndex=t.Parser=t.version=void 0,s(r(5),t);var i=r(4);Object.defineProperty(t,"version",{enumerable:!0,get:function(){return i.VERSION}}),s(r(1),t),s(r(6),t),s(r(3),t),s(r(10),t);var n=r(8);Object.defineProperty(t,"Parser",{enumerable:!0,get:function(){return n.Parser}}),s(r(0),t);var o=r(2);Object.defineProperty(t,"NameIndex",{enumerable:!0,get:function(){return o.NameIndex}})},function(e,t,r){"use strict";var a,s,i,n,o=this&&this.__awaiter||function(e,t,r,a){return new(r||(r=Promise))((function(s,i){function n(e){try{l(a.next(e))}catch(e){i(e)}}function o(e){try{l(a.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,o)}l((a=a.apply(e,t||[])).next())}))},l=this&&this.__classPrivateFieldGet||function(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.value:t.get(e)},h=this&&this.__classPrivateFieldSet||function(e,t,r,a,s){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?s.call(e,r):s?s.value=r:t.set(e,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.Namefully=void 0;const u=r(4),c=r(1),f=r(8),m=r(0),d=r(2);class N{constructor(e,t){a.add(this),s.set(this,void 0),h(this,s,l(this,a,"m",i).call(this,e).parse(t),"f")}static tryParse(e){try{return new this(f.Parser.build(e))}catch(e){return}}static parse(e){return o(this,void 0,void 0,(function*(){return f.Parser.buildAsync(e).then(e=>new N(e))}))}get config(){return l(this,s,"f").config}get length(){return this.birth.length}get prefix(){var e;return null===(e=l(this,s,"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,s,"f").has(m.Namon.MIDDLE_NAME)}get last(){return this.lastName()}get suffix(){var e;return null===(e=l(this,s,"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")}toString(){return this.full}get(e){return e.equal(m.Namon.PREFIX)?l(this,s,"f").prefix:e.equal(m.Namon.FIRST_NAME)?l(this,s,"f").firstName:e.equal(m.Namon.MIDDLE_NAME)?l(this,s,"f").middleName:e.equal(m.Namon.LAST_NAME)?l(this,s,"f").lastName:e.equal(m.Namon.SUFFIX)?l(this,s,"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,s,"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,s,"f").firstName.toString(e)}middleName(){return l(this,s,"f").middleName.map(e=>e.value)}lastName(e){return l(this,s,"f").lastName.toString(e)}initials(e){const t=[],r=l(this,s,"f").firstName.initials(),a=l(this,s,"f").middleName.map(e=>e.initials()[0]),i=l(this,s,"f").lastName.initials(),n=Object.assign({orderedBy:this.config.orderedBy,only:m.NameType.BIRTH_NAME},e),{orderedBy:o,only:h}=n;return h!==m.NameType.BIRTH_NAME?h===m.NameType.FIRST_NAME?t.push(...r):h===m.NameType.MIDDLE_NAME?t.push(...a):t.push(...i):o===m.NameOrder.FIRST_NAME?t.push(...r,...a,...i):t.push(...i,...r,...a),t}shorten(e){return(e=e||this.config.orderedBy)===m.NameOrder.FIRST_NAME?[l(this,s,"f").firstName.value,l(this,s,"f").lastName.toString()].join(" "):[l(this,s,"f").lastName.toString(),l(this,s,"f").firstName.value].join(" ")}flatten(e){if(this.length<=e.limit)return this.full;const t=Object.assign({limit:20,by:m.Flat.MIDDLE_NAME,withPeriod:!0,recursive:!1,withMore:!1},e),{by:r,limit:a,recursive:i,withMore:n,withPeriod:o,surname:h}=t,u=o?".":"",c=l(this,s,"f").firstName.toString(),f=this.middleName().join(" "),d=l(this,s,"f").lastName.toString(),N=this.hasMiddle,p=l(this,s,"f").firstName.initials(n).join(u+" ")+u,w=l(this,s,"f").lastName.initials(h).join(u+" ")+u,g=N?l(this,s,"f").middleName.map(e=>e.initials()[0]).join(u+" ")+u:"";let v=[];if(this.config.orderedBy===m.NameOrder.FIRST_NAME)switch(r){case m.Flat.FIRST_NAME:v=N?[p,f,d]:[p,d];break;case m.Flat.LAST_NAME:v=N?[c,f,w]:[c,w];break;case m.Flat.MIDDLE_NAME:v=N?[c,g,d]:[c,d];break;case m.Flat.FIRST_MID:v=N?[p,g,d]:[p,d];break;case m.Flat.MID_LAST:v=N?[c,g,w]:[c,w];break;case m.Flat.ALL:v=N?[p,g,w]:[p,w]}else switch(r){case m.Flat.FIRST_NAME:v=N?[d,p,f]:[d,p];break;case m.Flat.LAST_NAME:v=N?[w,c,f]:[w,c];break;case m.Flat.MIDDLE_NAME:v=N?[d,c,g]:[d,c];break;case m.Flat.FIRST_MID:v=N?[d,p,g]:[d,p];break;case m.Flat.MID_LAST:v=N?[w,c,g]:[w,c];break;case m.Flat.ALL:v=N?[w,p,g]:[w,p]}const E=v.join(" ");if(i&&E.length>a){const t=r===m.Flat.FIRST_NAME?m.Flat.MIDDLE_NAME:r===m.Flat.MIDDLE_NAME?m.Flat.LAST_NAME:r===m.Flat.LAST_NAME?m.Flat.FIRST_MID:r===m.Flat.FIRST_MID?m.Flat.MID_LAST:r===m.Flat.MID_LAST||r===m.Flat.ALL?m.Flat.ALL:r;return t===r?E:this.flatten(Object.assign(Object.assign({},e),{by:t}))}return E}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 s=[];for(const i of e.split("")){if(-1===u.ALLOWED_TOKENS.indexOf(i))throw new c.NotAllowedError({source:this.full,operation:"format",message:`unsupported character <${i}> from ${e}.`});r+=i,"$"!==i&&(s.push(null!==(t=l(this,a,"m",n).call(this,r))&&void 0!==t?t:""),r="")}return s.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=N,s=new WeakMap,a=new WeakSet,i=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":const a=this.config.ending?",":"",i=[];this.prefix&&i.push(this.prefix),i.push((this.last+",").toUpperCase()),this.hasMiddle?i.push(this.first,this.middleName().join(" ")+a):i.push(this.first+a),this.suffix&&i.push(this.suffix);const n=i.join(" ").trim();return"o"===e?n:n.toUpperCase();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,s,"f").firstName.initials()[0];case"$l":case"$L":return l(this,s,"f").lastName.initials()[0];case"$m":case"$M":return this.hasMiddle?this.middle[0]:void 0;default:return}}}])}));
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.2.1",
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",
@@ -9,26 +9,19 @@
9
9
  "main": "dist/lib/index.js",
10
10
  "types": "dist/types/index.d.ts",
11
11
  "browser": "dist/umd/namefully.min.js",
12
- "files": [
13
- "dist/**/*"
14
- ],
15
- "keywords": [
16
- "family",
17
- "format",
18
- "human",
19
- "name",
20
- "parse",
21
- "personal"
22
- ],
12
+ "files": ["dist/**/*"],
13
+ "keywords": ["format", "parse", "human", "personal", "family", "name"],
23
14
  "scripts": {
24
- "example": "webpack --config webpack.dev.js --progress && node ./dist/example/index.js",
15
+ "start": "webpack --config webpack.dev.js --display=errors-only && node ./build/example/index.js",
25
16
  "format": "prettier --write '{src,test}/**/*.ts'",
26
- "prebuild": "shx rm -rf dist",
17
+ "lint": "eslint 'src/**/*.ts' --fix",
18
+ "test": "jest --coverage",
19
+ "prebuild": "shx rm -rf dist build",
27
20
  "build": "tsc && tsc -p tsconfig.dts.json && webpack --config webpack.prod.js --progress",
28
- "lint": "tslint -p tsconfig.json",
29
- "test": "jest --collectCoverage=true"
21
+ "prepublish": "npm run format && npm run build"
30
22
  },
31
23
  "devDependencies": {
24
+ "@eslint/js": "^9.28.0",
32
25
  "@types/jest": "^29.5.1",
33
26
  "@types/node": "*",
34
27
  "clean-webpack-plugin": "^3.0.0",
@@ -38,9 +31,19 @@
38
31
  "terser-webpack-plugin": "^2.3.5",
39
32
  "ts-jest": "^29.1.0",
40
33
  "ts-loader": "^6.2.1",
41
- "tslint": "^6.0.0",
42
34
  "typescript": "~5.3.0",
35
+ "typescript-eslint": "^8.33.1",
43
36
  "webpack": "^4.42.0",
44
37
  "webpack-cli": "^3.3.11"
38
+ },
39
+ "prettier": {
40
+ "singleQuote": true,
41
+ "trailingComma": "all",
42
+ "printWidth": 120
43
+ },
44
+ "jest": {
45
+ "transform": {
46
+ "^.+.ts$": "ts-jest"
47
+ }
45
48
  }
46
49
  }
package/readme.md CHANGED
@@ -44,6 +44,7 @@ You may want to use this library if:
44
44
  3. Use tokens (separators) to reshape prefixes and suffixes
45
45
  4. Accept customized parsers (do it yourself)
46
46
  5. Parse non-standard name cases
47
+ 6. Build a name on the fly (via a builder)
47
48
 
48
49
  ## Installation
49
50
 
@@ -65,10 +66,10 @@ This package is also available in [Angular](https://angular.io/) and
65
66
 
66
67
  ## Usage
67
68
 
68
- See `example/example.ts`.
69
+ See [examples] or [test cases][test-cases] for more details.
69
70
 
70
71
  ```ts
71
- import { Namefully } from 'namefully'
72
+ import { Namefully } from 'namefully';
72
73
 
73
74
  const name = new Namefully('Thomas Alva Edison');
74
75
  console.log(name.short); // Thomas Edison
@@ -78,10 +79,8 @@ console.log(name.format('L, f m')); // EDISON, Thomas Alva
78
79
  console.log(name.zip()); // Thomas A. E.
79
80
  ```
80
81
 
81
- > NOTE: if you intend to use this utility for non-standard name cases such as
82
- > many middle names or last names, some extra work is required. For example,
83
- > using `Namefully.parse()` lets you parse names containing many middle names
84
- > with the risk of throwing a `NameError` when the parsing is not possible.
82
+ > **Note** that if you intend to use this utility for non-standard name cases such as
83
+ > many middle names or last names, use `Namefully.parse()` or `NameBuilder` instead.
85
84
 
86
85
  ## `Config` and default values
87
86
 
@@ -112,7 +111,7 @@ const name2 = new Namefully(['Edison', 'Thomas'], { orderedBy: NameOrder.LAST_NA
112
111
  console.log(name2.first); // Thomas
113
112
  ```
114
113
 
115
- > NOTE: This option also affects all the other results of the API. In other
114
+ > **Note** that this option also affects all the other results of the API. In other
116
115
  > words, the results will prioritize the order of appearance set in the first
117
116
  > place for the other operations. Keep in mind that in some cases, it can be
118
117
  > altered on the go. See the example below.
@@ -165,11 +164,10 @@ console.log(name.prefix); // Mr.
165
164
  Sets an ending character after the full name (a comma before the suffix actually).
166
165
 
167
166
  ```ts
168
- const name = new Namefully({
169
- firstName: 'John',
170
- lastName: 'Smith',
171
- suffix: 'Ph.D'
172
- }, { ending: true })
167
+ const name = new Namefully(
168
+ { firstName: 'John', lastName: 'Smith', suffix: 'Ph.D'},
169
+ { ending: true },
170
+ )
173
171
  console.log(name.full) // John Smith, Ph.D
174
172
  console.log(name.suffix) // Ph.D
175
173
  ```
@@ -182,8 +180,8 @@ Defines the distinct formats to output a compound surname (e.g., Hispanic surnam
182
180
 
183
181
  ```ts
184
182
  const name = new Namefully(
185
- [new FirstName('John'), new LastName('Doe', 'Smith')],
186
- { surname: Surname.HYPHENATED },
183
+ [new FirstName('John'), new LastName('Doe', 'Smith')],
184
+ { surname: Surname.HYPHENATED },
187
185
  );
188
186
  console.log(name.full); // John Doe-Smith
189
187
  ```
@@ -209,12 +207,12 @@ To sum it all up, the default values are:
209
207
 
210
208
  ```ts
211
209
  {
212
- orderedBy: NameOrder.FIRST_NAME,
213
- separator: Separator.SPACE,
214
- title: Title.UK,
215
- ending: false,
216
- bypass: true,
217
- surname: Surname.FATHER
210
+ orderedBy: NameOrder.FIRST_NAME,
211
+ separator: Separator.SPACE,
212
+ title: Title.UK,
213
+ ending: false,
214
+ bypass: true,
215
+ surname: Surname.FATHER
218
216
  }
219
217
  ```
220
218
 
@@ -223,23 +221,47 @@ To sum it all up, the default values are:
223
221
  Customize your own parser to indicate the full name yourself.
224
222
 
225
223
  ```ts
226
- import { Config, FullName, Namefully, Parser } from 'namefully'
224
+ import { Config, FullName, Namefully, Parser } from 'namefully';
227
225
 
228
226
  // Suppose you want to cover this '#' separator
229
227
  class SimpleParser extends Parser<string> {
230
- parse(options: Partial<Config>): FullName {
231
- const [firstName, lastName] = this.raw.split('#')
232
- return FullName.parse({ firstName, lastName }, Config.merge(options))
233
- }
228
+ parse(options: Partial<Config>): FullName {
229
+ const [firstName, lastName] = this.raw.split('#');
230
+ return FullName.parse({ firstName, lastName }, Config.merge(options));
231
+ }
234
232
  }
235
233
 
236
234
  const name = new Namefully(new SimpleParser('Juan#Garcia'));
237
235
  console.log(name.full); // Juan Garcia
238
236
  ```
239
237
 
238
+ **Or** use `NameIndex` to specify where the name parts are located in a text.
239
+
240
+ ```ts
241
+ import { Namefully, NameIndex } from 'namefully';
242
+
243
+ const indexing = NameIndex.only({ firstName: 0, lastName: 3 });
244
+ const name = Namefully.tryParse('Dwayne "The Rock" Johnson', indexing);
245
+ console.log(name.full); // Dwayne Johnson
246
+ ```
247
+
248
+ **Or** simply use `NameBuilder` to build a name on the fly (with lifecycle hooks if needed).
249
+
250
+ ```ts
251
+ import { Name, NameBuilder } from 'namefully';
252
+
253
+ const builder = NameBuilder.of(Name.first('Nikola')); // can be more than one name
254
+ builder.add(Name.last('Tesla'));
255
+ builder.add(Name.prefix('Mr'));
256
+
257
+ const name = builder.build() // with options if needed
258
+ console.log(name.full); // Mr Nikola Tesla
259
+ ```
260
+
240
261
  ## Concepts and examples
241
262
 
242
- The name standards used for the current version of this library are as follows:
263
+ The name standards (inspired by this [UK name guide][name-standards]) used for
264
+ the current version of this library are as follows:
243
265
 
244
266
  `[prefix] firstName [middleName] lastName [suffix]`
245
267
 
@@ -257,7 +279,7 @@ Once imported, all that is required to do is to create an instance of
257
279
 
258
280
  ### Basic cases
259
281
 
260
- Let us take a common example:
282
+ Let us take a common example with all the parts:
261
283
 
262
284
  `Mr John Joe Smith PhD`
263
285
 
@@ -274,23 +296,24 @@ So, this utility understands the name parts as follows:
274
296
  - flattened: `John J. S.`
275
297
  - initials: `J J S`
276
298
  - public: `John S`
299
+ - salutation: `Mr Smith`
277
300
 
278
301
  ### Limitations
279
302
 
280
- `namefully` does not have support for certain use cases:
303
+ `namefully` does not support certain use cases:
281
304
 
282
- - mononame: `Plato`. A workaround is to set the mononame as both first and last name;
283
- - multiple prefixes: `Prof. Dr. Einstein`.
305
+ - mononame: `Plato` - a workaround is to set the mononame as both first and last name;
306
+ - nickname: `Dwayne "The Rock" Johnson` - use custom parser instead.
307
+ - multiple prefixes or suffixes: `Prof. Dr. Einstein`.
284
308
 
285
- See the [test cases](test) for further details.
309
+ ## Contributing
286
310
 
287
- ## Author
288
-
289
- Developed by [Ralph Florent](https://github.com/ralflorent).
311
+ Visit [CONTRIBUTING.md][contributing-url] for details on the contribution guidelines,
312
+ the code of conduct, and the process for submitting pull requests.
290
313
 
291
314
  ## License
292
315
 
293
- The underlying content of this utility is licensed under [MIT License](LICENSE).
316
+ The underlying content of this utility is licensed under [MIT License][license-url].
294
317
 
295
318
  <!-- References -->
296
319
 
@@ -304,3 +327,8 @@ The underlying content of this utility is licensed under [MIT License](LICENSE).
304
327
  [codecov-url]: https://codecov.io/gh/ralflorent/namefully
305
328
  [license-img]: https://img.shields.io/npm/l/namefully
306
329
  [license-url]: https://opensource.org/licenses/MIT
330
+
331
+ [contributing-url]: https://github.com/ralflorent/namefully/blob/main/CONTRIBUTING.md
332
+ [examples]: https://github.com/ralflorent/namefully/tree/main/example
333
+ [test-cases]: https://github.com/ralflorent/namefully/tree/main/test
334
+ [name-standards]: https://www.fbiic.gov/public/2008/nov/Naming_practice_guide_UK_2006.pdf