UNPKG

n2words

Version:

Convert numbers to words in 70+ languages with zero dependencies. Supports BigInt, decimals, and browser/Node.js environments.

3 lines (2 loc) 6.68 kB
/*! n2words/tr-TR v5.1.2 | MIT License | github.com/forzagreen/n2words */ var e,n;e=this,n=function(e){"use strict";function n(e){let[n,t]=e.toLowerCase().split("e");const r=parseInt(t,10);let i="";"-"===n[0]&&(i="-",n=n.slice(1));const o=n.indexOf("."),s=-1===o?n:n.slice(0,o)+n.slice(o+1),u=(-1===o?n.length:o)+r;return u>=s.length?i+s+"0".repeat(u-s.length):u<=0?i+"0."+"0".repeat(-u)+s:i+s.slice(0,u)+"."+s.slice(u)}function t(e){const t=e.toString();return r(t)?n(t):t}function r(e){return e.includes("e")||e.includes("E")}function i(e){const n="-"===e[0];n&&(e=e.slice(1));const t=e.indexOf(".");if(-1===t)return{isNegative:n,integerPart:BigInt(e)};const r=e.slice(0,t)||"0",i=e.slice(t+1);return{isNegative:n,integerPart:BigInt(r),decimalPart:i}}function o(e){let t=e.trim();if(0===t.length||Number.isNaN(Number(t)))throw new RangeError(`Invalid currency format: "${e}"`);r(t)&&(t=n(t));const i="-"===t[0];i&&(t=t.slice(1));const o=t.indexOf(".");if(-1===o)return{isNegative:i,dollars:BigInt(t),cents:0n};const s=t.slice(0,o)||"0",u=(t.slice(o+1)+"00").slice(0,2);return{isNegative:i,dollars:BigInt(s),cents:BigInt(u)}}function s(e,n,t){if(null===n)return;if(e<n&&!(t&&BigInt(t)>=n))return;const r=n.toString().length-1,i=n===10n**BigInt(r)?`10^${r} - 1`:""+(n-1n);throw new RangeError(`Number too large to convert: the largest supported value is ${i}`)}function u(e){return 10n**BigInt(3*(e+1))}const c=["","bir","iki","üç","dört","beş","altı","yedi","sekiz","dokuz"],l=["on","on bir","on iki","on üç","on dört","on beş","on altı","on yedi","on sekiz","on dokuz"],f=["","","yirmi","otuz","kırk","elli","altmış","yetmiş","seksen","doksan"],a="bin",g="sıfır",d="eksi",p=["milyon","milyar","trilyon","katrilyon","kentilyon"],b=u(p.length+1),m=u(p.length+1),h=u(p.length+1),w={1:"birinci",2:"ikinci",3:"üçüncü",4:"dördüncü",5:"beşinci",6:"altıncı",7:"yedinci",8:"sekizinci",9:"dokuzuncu",10:"onuncu"};function y(e,n=" "){if(0===e)return"";const t=e%10,r=Math.trunc(e/10)%10,i=Math.trunc(e/100),o=[];i>0&&o.push(1===i?"yüz":c[i]+n+"yüz");const s=e%100;return 0===s||o.push(s<10?c[t]:s<20?l[t].replace(" ",n):0===t?f[r]:f[r]+n+c[t]),o.join(n)}function v(e,n){if(0n===e)return g;const t=n?"":" ";if(e<1000n)return y(Number(e),t);if(e<1000000n){const n=Number(e/1000n),r=Number(e%1000n);let i;return i=1===n?a:y(n,t)+t+a,r>0&&(i+=t+y(r,t)),i}return function(e,n){const t=n?"":" ",r=e.toString(),i=r.length,o=[],s=i%3;let u=0;for(s>0&&(o.push(Number(r.slice(0,s))),u=s);u<i;)o.push(Number(r.slice(u,u+3))),u+=3;const c=[];let l=o.length-1;for(let e=0;e<o.length;e++){const n=o[e];if(0!==n){const e=y(n,t);c.push(0===l?e:1===l?1===n?a:e+t+a:e+t+p[l-2])}l--}return c.join(t)}(e,n)}const N={dropSpaces:!1},I={trTR:function(e){const t=function(e){const t=typeof e;if("bigint"==typeof e){if(e<=0n)throw new RangeError("Ordinals must be positive integers");return e}if("number"==typeof e){if(!Number.isFinite(e))throw new RangeError("Ordinals must be finite numbers");if(!Number.isInteger(e))throw new RangeError("Ordinals must be whole numbers");if(e<=0)throw new RangeError("Ordinals must be positive integers");return BigInt(e)}if("string"==typeof e)return function(e){const t=e.trim();if(0===t.length)throw new RangeError("Ordinals cannot be empty strings");if("-"===t[0])throw new RangeError("Ordinals cannot be negative");if(t.includes("."))throw new RangeError("Ordinals must be whole numbers");if(r(t)){const e=n(t);if(e.includes("."))throw new RangeError("Ordinals must be whole numbers");const r=BigInt(e);if(r<=0n)throw new RangeError("Ordinals must be positive integers");return r}try{const e=BigInt(t);if(e<=0n)throw new RangeError("Ordinals must be positive integers");return e}catch(n){if(n instanceof RangeError)throw n;throw new RangeError(`Invalid ordinal format: "${e}"`,{cause:n})}}(e);throw new TypeError(`Invalid value type: expected number, string, or bigint, received ${t}`)}(e);return s(t,m),function(e){if(e>=1n&&e<=10n)return w[Number(e)];const n=v(e,!0);return n+function(e){for(let n=e.length-1;n>=0;n--){const t=e[n];if("aıou".includes(t))return"ou".includes(t)?"uncu":"ıncı";if("eiöü".includes(t))return"öü".includes(t)?"üncü":"inci"}return"inci"}(n)}(t)}};e.currency={trTR:function(e){const{isNegative:n,dollars:r,cents:i}=function(e){const n=typeof e;if("bigint"==typeof e)return e<0n?{isNegative:!0,dollars:-e,cents:0n}:{isNegative:!1,dollars:e,cents:0n};if("number"==typeof e){if(!Number.isFinite(e))throw new RangeError("Currency must be a finite number");return Number.isSafeInteger(e)?e<0?{isNegative:!0,dollars:BigInt(-e),cents:0n}:{isNegative:!1,dollars:BigInt(e),cents:0n}:o(t(e))}if("string"==typeof e)return o(e);throw new TypeError(`Invalid value type: expected number, string, or bigint, received ${n}`)}(e);s(r,h);let u="";return n&&(u=d+" "),(r>0n||0n===i)&&(u+=v(r,!1)+" lira"),i>0n&&(r>0n&&(u+=" "),u+=v(i,!1)+" kuruş"),u}},e.ordinal=I,e.trTR=function(e,o){const{isNegative:u,integerPart:c,decimalPart:l}=function(e){const o=typeof e;if("bigint"==typeof e)return e<0n?{isNegative:!0,integerPart:-e}:{isNegative:!1,integerPart:e};if("number"==typeof e){if(!Number.isFinite(e))throw new RangeError("Number must be finite (NaN and Infinity are not supported)");return Number.isSafeInteger(e)?e<0?{isNegative:!0,integerPart:BigInt(-e)}:{isNegative:!1,integerPart:BigInt(e)}:i(t(e))}if("string"==typeof e)return i(function(e){const t=e.trim();if(0===t.length||Number.isNaN(Number(t)))throw new RangeError(`Invalid number format: "${e}"`);return r(t)?n(t):t}(e));throw new TypeError(`Invalid value type: expected number, string, or bigint, received ${o}`)}(e);s(c,b,l);const{dropSpaces:f}=function(e,n){const t={...n};if(void 0===e)return t;if(!function(e){if(null===e||"object"!=typeof e)return!1;const n=Object.getPrototypeOf(e);return null===n||n===Object.prototype}(e))throw new TypeError("Invalid options: expected plain object or undefined, got "+typeof e);const r=Object.keys(n);for(const[i,o]of Object.entries(e)){if(!Object.hasOwn(n,i))throw new TypeError(`Unknown option "${i}" — expected one of: ${r.join(", ")}`);if(void 0!==o){if(typeof o!=typeof t[i])throw new TypeError(`Option "${i}" must be a ${typeof t[i]}, got ${typeof o}`);t[i]=o}}return t}(o,N),a=f?"":" ";let p="";return u&&(p=d+a),p+=v(c,f),l&&(p+=a+"virgül"+a+function(e,n){const t=n?"":" ";let r="",i=0;for(;i<e.length&&"0"===e[i];)r&&(r+=t),r+=g,i++;const o=e.slice(i);return o&&(r&&(r+=t),r+=v(BigInt(o),n)),r}(l,f)),p}},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).n2words=e.n2words||{});