languageUtils.js 17 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{ArcadeFunction as e}from"../arcade/FunctionWrapper.js";import t from"../arcade/ImmutableArray.js";import n from"../arcade/ImmutablePathArray.js";import r from"../arcade/ImmutablePointArray.js";import a from"../geometry/Extent.js";import i from"../geometry/Geometry.js";import o from"../geometry/Multipoint.js";import l from"../geometry/Point.js";import s from"../geometry/Polygon.js";import u from"../geometry/Polyline.js";import{DateTime as f}from"luxon";import{isNone as c}from"../core/maybe.js";import{format as m,parse as d}from"../core/number.js";import{isClockwise as y}from"../geometry/support/coordsUtils.js";import{getLocale as p}from"../intl/locale.js";import{esriFieldToJson as g,layerGeometryEsriRestConstants as h}from"../arcade/featureset/support/shared.js";import{ArcadeModule as S}from"../arcade/ArcadeModule.js";import{ArcadeExecutionError as b,ExecutionErrorCodes as x}from"../arcade/executionError.js";class T{constructor(e){this.value=e}}class M{constructor(e){this.value=e}}const N=M,D=T,k={type:"VOID"},j={type:"BREAK"},A={type:"CONTINUE"};function R(e,t,n){return""===t||null==t||t===n||t===n?e:e=e.split(t).join(n)}function F(t){return t instanceof e}function C(e){return e instanceof S}function I(e){return!!w(e)||(!!Z(e)||(!!z(e)||(!!_(e)||(null===e||(e===k||"number"==typeof e)))))}function v(e,t){return void 0===e?t:e}function O(e){return null==e?"":Y(e)||E(e)?"Array":z(e)?"Date":w(e)?"String":_(e)?"Boolean":Z(e)?"Number":"esri.arcade.Attachment"===e?.declaredClass?"Attachment":"esri.arcade.Portal"===e?.declaredClass?"Portal":"esri.arcade.Dictionary"===e?.declaredClass?"Dictionary":e instanceof S?"Module":J(e)?"Feature":e instanceof l?"Point":e instanceof s?"Polygon":e instanceof u?"Polyline":e instanceof o?"Multipoint":e instanceof a?"Extent":F(e)?"Function":P(e)?"FeatureSet":G(e)?"FeatureSetCollection":e===k?"":"number"==typeof e&&isNaN(e)?"Number":"Unrecognised Type"}function w(e){return"string"==typeof e||e instanceof String}function _(e){return"boolean"==typeof e}function Z(e){return"number"==typeof e}function L(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}function Y(e){return e instanceof Array}function J(e){return"esri.arcade.Feature"===e?.arcadeDeclaredClass}function P(e){return!0===(e&&e.declaredRootClass&&"esri.arcade.featureset.support.FeatureSet"===e.declaredRootClass)}function G(e){return!0===(e&&e.declaredRootClass&&"esri.arcade.featureSetCollection"===e.declaredRootClass)}function E(e){return e instanceof t}function z(e){return e instanceof Date}function V(e,t,n,r,a){if(e.length<t||e.length>n)throw new b(r,x.WrongNumberOfParameters,a)}function H(e){return e<0?-Math.round(-e):Math.round(e)}function U(){let e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)}))}function q(e,t){return isNaN(e)||null==t||""===t?e.toString():(t=R(t,"‰",""),t=R(t,"¤",""),m(e,{pattern:t}))}function B(e,t){const n=f.fromJSDate(e);return null==t||""===t?n.toISO({suppressMilliseconds:!0}):n.toFormat(W(t),{locale:p(),numberingSystem:"latn"})}function W(e){e=e.replace(/LTS|LT|LL?L?L?|l{1,4}/g,"[$&]");let t="";const n=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;for(const r of e.match(n))switch(r){case"D":t+="d";break;case"DD":t+="dd";break;case"DDD":t+="o";break;case"d":t+="c";break;case"ddd":t+="ccc";break;case"dddd":t+="cccc";break;case"M":t+="L";break;case"MM":t+="LL";break;case"MMM":t+="LLL";break;case"MMMM":t+="LLLL";break;case"YY":t+="yy";break;case"Y":case"YYYY":t+="yyyy";break;case"Q":t+="q";break;case"Z":t+="ZZ";break;case"ZZ":t+="ZZZ";break;case"S":t+="'S'";break;case"SS":t+="'SS'";break;case"SSS":t+="u";break;case"A":case"a":t+="a";break;case"m":case"mm":case"h":case"hh":case"H":case"HH":case"s":case"ss":case"X":case"x":t+=r;break;default:r.length>=2&&"["===r.slice(0,1)&&"]"===r.slice(-1)?t+=`'${r.slice(1,-1)}'`:t+=`'${r}'`}return t}function $(e,t,n){switch(n){case">":return e>t;case"<":return e<t;case">=":return e>=t;case"<=":return e<=t}return!1}function Q(e,t,n){if(null===e){if(null===t||t===k)return $(null,null,n);if(Z(t))return $(0,t,n);if(w(t))return $(0,re(t),n);if(_(t))return $(0,re(t),n);if(z(t))return $(0,t.getTime(),n)}if(e===k){if(null===t||t===k)return $(null,null,n);if(Z(t))return $(0,t,n);if(w(t))return $(0,re(t),n);if(_(t))return $(0,re(t),n);if(z(t))return $(0,t.getTime(),n)}else if(Z(e)){if(Z(t))return $(e,t,n);if(_(t))return $(e,re(t),n);if(null===t||t===k)return $(e,0,n);if(w(t))return $(e,re(t),n);if(z(t))return $(e,t.getTime(),n)}else if(w(e)){if(w(t))return $(K(e),K(t),n);if(z(t))return $(re(e),t.getTime(),n);if(Z(t))return $(re(e),t,n);if(null===t||t===k)return $(re(e),0,n);if(_(t))return $(re(e),re(t),n)}else if(z(e)){if(z(t))return $(e,t,n);if(null===t||t===k)return $(e.getTime(),0,n);if(Z(t))return $(e.getTime(),t,n);if(_(t))return $(e.getTime(),re(t),n);if(w(t))return $(e.getTime(),re(t),n)}else if(_(e)){if(_(t))return $(e,t,n);if(Z(t))return $(re(e),re(t),n);if(z(t))return $(re(e),t.getTime(),n);if(null===t||t===k)return $(re(e),0,n);if(w(t))return $(re(e),re(t),n)}return!!X(e,t)&&("<="===n||">="===n)}function X(e,t){if(e===t)return!0;if(null===e&&t===k||null===t&&e===k)return!0;if(z(e)&&z(t))return e.getTime()===t.getTime();if(e instanceof n)return e.equalityTest(t);if(e instanceof r)return e.equalityTest(t);if(e instanceof l&&t instanceof l){const n=e.cache._arcadeCacheId,r=t.cache._arcadeCacheId;if(null!=n)return n===r}if(void 0!==e&&void 0!==t&&null!==e&&null!==t&&"object"==typeof e&&"object"==typeof t){if(e._arcadeCacheId===t._arcadeCacheId&&void 0!==e._arcadeCacheId&&null!==e._arcadeCacheId)return!0;if(e._underlyingGraphic===t._underlyingGraphic&&void 0!==e._underlyingGraphic&&null!==e._underlyingGraphic)return!0}return!1}function K(e,n){if(w(e))return e;if(null===e)return"";if(Z(e))return q(e,n);if(_(e))return e.toString();if(z(e))return B(e,n);if(e instanceof i)return JSON.stringify(e.toJSON());if(Y(e)){const t=[];for(let n=0;n<e.length;n++)t[n]=ne(e[n]);return"["+t.join(",")+"]"}if(e instanceof t){const t=[];for(let n=0;n<e.length();n++)t[n]=ne(e.get(n));return"["+t.join(",")+"]"}return null!==e&&"object"==typeof e&&void 0!==e.castToText?e.castToText():F(e)?"object, Function":e===k?"":C(e)?"object, Module":""}function ee(e){const n=[];if(!Y(e))return null;if(e instanceof t){for(let t=0;t<e.length();t++)n[t]=re(e.get(t));return n}for(let t=0;t<e.length;t++)n[t]=re(e[t]);return n}function te(e,n,r=!1){if(w(e))return e;if(null===e)return"";if(Z(e))return q(e,n);if(_(e))return e.toString();if(z(e))return B(e,n);if(e instanceof i)return e instanceof a?'{"xmin":'+e.xmin.toString()+',"ymin":'+e.ymin.toString()+","+(e.hasZ?'"zmin":'+e.zmin.toString()+",":"")+(e.hasM?'"mmin":'+e.mmin.toString()+",":"")+'"xmax":'+e.xmax.toString()+',"ymax":'+e.ymax.toString()+","+(e.hasZ?'"zmax":'+e.zmax.toString()+",":"")+(e.hasM?'"mmax":'+e.mmax.toString()+",":"")+'"spatialReference":'+ye(e.spatialReference)+"}":ye(e.toJSON(),((e,t)=>e.key===t.key?0:"spatialReference"===e.key?1:"spatialReference"===t.key||e.key<t.key?-1:e.key>t.key?1:0));if(Y(e)){const t=[];for(let n=0;n<e.length;n++)t[n]=ne(e[n],r);return"["+t.join(",")+"]"}if(e instanceof t){const t=[];for(let n=0;n<e.length();n++)t[n]=ne(e.get(n),r);return"["+t.join(",")+"]"}return null!==e&&"object"==typeof e&&void 0!==e.castToText?e.castToText(r):F(e)?"object, Function":e===k?"":C(e)?"object, Module":""}function ne(e,n=!1){if(null===e)return"null";if(_(e)||Z(e)||w(e))return JSON.stringify(e);if(e instanceof i)return te(e,null,n);if(e instanceof t)return te(e,null,n);if(e instanceof Array)return te(e,null,n);if(e instanceof Date)return n?JSON.stringify(e.getTime()):JSON.stringify(B(e,""));if(null!==e&&"object"==typeof e){if(void 0!==e.castToText)return e.castToText(n)}else if(e===k)return"null";return"null"}function re(e,t){return Z(e)?e:null===e||""===e?0:z(e)?NaN:_(e)?e?1:0:Y(e)||""===e||void 0===e?NaN:void 0!==t&&w(e)?(t=R(t,"‰",""),t=R(t,"¤",""),d(e,{pattern:t})):e===k?0:Number(e)}function ae(e){if(z(e))return e;if(w(e)){const t=oe(e);if(t)return t.toJSDate()}return null}function ie(e){return z(e)?f.fromJSDate(e):w(e)?oe(e):null}function oe(e){const t=/ (\d\d)/;let n=f.fromISO(e);return n.isValid||t.test(e)&&(e=e.replace(t,"T$1"),n=f.fromISO(e),n.isValid)?n:null}function le(e){return _(e)?e:w(e)?"true"===(e=e.toLowerCase()):!!Z(e)&&(0!==e&&!isNaN(e))}function se(e,t){return c(e)?null:(null!==e.spatialReference&&void 0!==e.spatialReference||(e.spatialReference=t),e)}function ue(e){if(null===e)return null;if(e instanceof l)return"NaN"===e.x||null===e.x||isNaN(e.x)?null:e;if(e instanceof s){if(0===e.rings.length)return null;for(const t of e.rings)if(t.length>0)return e;return null}if(e instanceof u){if(0===e.paths.length)return null;for(const t of e.paths)if(t.length>0)return e;return null}return e instanceof o?0===e.points.length?null:e:e instanceof a?"NaN"===e.xmin||null===e.xmin||isNaN(e.xmin)?null:e:null}function fe(e,t){if(!e)return t;if(!e.domain)return t;let n=null;if("string"===e.field.type||"esriFieldTypeString"===e.field.type)t=K(t);else{if(null==t)return null;if(""===t)return t;t=re(t)}for(let r=0;r<e.domain.codedValues.length;r++){const a=e.domain.codedValues[r];a.code===t&&(n=a)}return null===n?t:n.name}function ce(e,t){if(!e)return t;if(!e.domain)return t;let n=null;t=K(t);for(let r=0;r<e.domain.codedValues.length;r++){const a=e.domain.codedValues[r];a.name===t&&(n=a)}return null===n?t:n.code}function me(e,t,n=null,r=null){if(!t)return null;if(!t.fields)return null;let a,i,o=null;for(let l=0;l<t.fields.length;l++){const n=t.fields[l];n.name.toLowerCase()===e.toString().toLowerCase()&&(o=n)}if(null===o)throw new b(null,x.FieldNotFound,null,{key:e});return null===r&&n&&t.typeIdField&&(r=n.hasField(t.typeIdField)?n.field(t.typeIdField):null),null!=r&&t.types.some((e=>e.id===r&&(a=e.domains&&e.domains[o.name],a&&"inherited"===a.type&&(a=de(o.name,t),i=!0),!0))),i||a||(a=de(e,t)),{field:o,domain:a}}function de(e,t){let n;return t.fields.some((t=>(t.name.toLowerCase()===e.toLowerCase()&&(n=t.domain),!!n))),n}function ye(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});const n="boolean"==typeof t.cycles&&t.cycles,r=t.cmp&&(a=t.cmp,function(e){return function(t,n){const r={key:t,value:e[t]},i={key:n,value:e[n]};return a(r,i)}});var a;const i=[];return function e(t){if(t&&t.toJSON&&"function"==typeof t.toJSON&&(t=t.toJSON()),void 0===t)return;if("number"==typeof t)return isFinite(t)?""+t:"null";if("object"!=typeof t)return JSON.stringify(t);let a,o;if(Array.isArray(t)){for(o="[",a=0;a<t.length;a++)a&&(o+=","),o+=e(t[a])||"null";return o+"]"}if(null===t)return"null";if(i.includes(t)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const l=i.push(t)-1,s=Object.keys(t).sort(r&&r(t));for(o="",a=0;a<s.length;a++){const n=s[a],r=e(t[n]);r&&(o&&(o+=","),o+=JSON.stringify(n)+":"+r)}return i.splice(l,1),"{"+o+"}"}(e)}function pe(e){if(null===e)return null;const t=[];for(const n of e)n&&n.arcadeDeclaredClass&&"esri.arcade.Feature"===n.arcadeDeclaredClass?t.push(n.geometry()):t.push(n);return t}function ge(e,t){if(!(t instanceof l))throw new b(null,x.InvalidParameter,null);e.push(t.hasZ?t.hasM?[t.x,t.y,t.z,t.m]:[t.x,t.y,t.z]:[t.x,t.y])}function he(e,t){if(Y(e)||E(e)){let n=!1,a=!1,i=[],o=t;if(Y(e)){for(const t of e)ge(i,t);i.length>0&&(o=e[0].spatialReference,n=e[0].hasZ,a=e[0].hasM)}else if(e instanceof r)i=e._elements,i.length>0&&(n=e._hasZ,a=e._hasM,o=e.get(0).spatialReference);else{if(!E(e))throw new b(null,x.InvalidParameter,null);for(const t of e.toArray())ge(i,t);i.length>0&&(o=e.get(0).spatialReference,n=!0===e.get(0).hasZ,a=!0===e.get(0).hasM)}if(0===i.length)return null;return y(i,a,n)||(i=i.slice(0).reverse()),new s({rings:[i],spatialReference:o,hasZ:n,hasM:a})}return e}function Se(e,t){if(Y(e)||E(e)){let n=!1,a=!1,i=[],o=t;if(Y(e)){for(const t of e)ge(i,t);i.length>0&&(o=e[0].spatialReference,n=!0===e[0].hasZ,a=!0===e[0].hasM)}else if(e instanceof r)i=e._elements,i.length>0&&(n=e._hasZ,a=e._hasM,o=e.get(0).spatialReference);else if(E(e)){for(const t of e.toArray())ge(i,t);i.length>0&&(o=e.get(0).spatialReference,n=!0===e.get(0).hasZ,a=!0===e.get(0).hasM)}return 0===i.length?null:new u({paths:[i],spatialReference:o,hasZ:n,hasM:a})}return e}function be(e,t){if(Y(e)||E(e)){let n=!1,a=!1,i=[],l=t;if(Y(e)){for(const t of e)ge(i,t);i.length>0&&(l=e[0].spatialReference,n=!0===e[0].hasZ,a=!0===e[0].hasM)}else if(e instanceof r)i=e._elements,i.length>0&&(n=e._hasZ,a=e._hasM,l=e.get(0).spatialReference);else if(E(e)){for(const t of e.toArray())ge(i,t);i.length>0&&(l=e.get(0).spatialReference,n=!0===e.get(0).hasZ,a=!0===e.get(0).hasM)}return 0===i.length?null:new o({points:i,spatialReference:l,hasZ:n,hasM:a})}return e}function xe(e,n=!1){const r=[];if(null===e)return r;if(!0===Y(e)){for(let t=0;t<e.length;t++){const a=K(e[t]);""===a&&!0!==n||r.push(a)}return r}if(e instanceof t){for(let t=0;t<e.length();t++){const a=K(e.get(t));""===a&&!0!==n||r.push(a)}return r}if(I(e)){const t=K(e);return""===t&&!0!==n||r.push(t),r}return[]}let Te=0;function Me(e){return Te++,Te%100==0?(Te=0,new Promise((t=>{setTimeout((()=>{t(e)}),0)}))):e}function Ne(e,t,n){switch(n){case"&":return e&t;case"|":return e|t;case"^":return e^t;case"<<":return e<<t;case">>":return e>>t;case">>>":return e>>>t}}function De(e,n=null){return null==e?null:_(e)||Z(e)||w(e)?e:e instanceof i?!0===n?.keepGeometryType?e:e.toJSON():e instanceof t?e.toArray().map((e=>De(e,n))):e instanceof Array?e.map((e=>De(e,n))):e instanceof Date?e:null!==e&&"object"==typeof e&&void 0!==e.castAsJson?e.castAsJson(n):null}async function ke(e,t,n,r,a){const i=await je(e,t,n);a[r]=i}async function je(e,n=null,r=null){if(e instanceof t&&(e=e.toArray()),null==e)return null;if(I(e)||e instanceof i||e instanceof Date)return De(e,r);if(e instanceof Array){const t=[],a=[];for(const o of e)null===o||I(o)||o instanceof i||o instanceof Date?a.push(De(o,r)):(a.push(null),t.push(ke(o,n,r,a.length-1,a)));return t.length>0&&await Promise.all(t),a}return null!==e&&"object"==typeof e&&void 0!==e.castAsJsonAsync?e.castAsJsonAsync(n,r):null}function Ae(e,t,n){const r=e.fullSchema();if(null===r)return null;if(!r.fields)return null;return me(t,r,e,n)}function Re(e){const t=e.fullSchema();return null===t?null:t.fields&&t.typeIdField?{subtypeField:t.typeIdField,subtypes:t.types?t.types.map((e=>({name:e.name,code:e.id}))):[]}:null}function Fe(e,t,n,r){const a=e.fullSchema();if(null===a)return null;if(!a.fields)return null;const i=me(t,a,e,r);if(void 0===n)try{n=e.field(t)}catch(o){return null}return fe(i,n)}function Ce(e,t,n,r){const a=e.fullSchema();if(null===a)return null;if(!a.fields)return null;if(void 0===n){try{n=e.field(t)}catch(i){return null}return n}return ce(me(t,a,e,r),n)}function Ie(e){const t=e.fullSchema();if(null===t)return null;if(!t.fields)return null;const n=[];for(const r of t.fields)n.push(g(r));return{objectIdField:t.objectIdField,globalIdField:t.globalIdField,geometryType:void 0===h[t.geometryType]?"":h[t.geometryType],fields:n}}const ve=Object.freeze(Object.defineProperty({__proto__:null,ReturnResultE:T,ImplicitResultE:M,ImplicitResult:N,ReturnResult:D,voidOperation:k,breakResult:j,continueResult:A,multiReplace:R,isFunctionParameter:F,isModule:C,isSimpleType:I,defaultUndefined:v,getType:O,isString:w,isBoolean:_,isNumber:Z,isInteger:L,isArray:Y,isFeature:J,isFeatureSet:P,isFeatureSetCollection:G,isImmutableArray:E,isDate:z,pcCheck:V,absRound:H,generateUUID:U,formatNumber:q,formatDate:B,standardiseDateFormat:W,greaterThanLessThan:Q,equalityTest:X,toString:K,toNumberArray:ee,toStringExplicit:te,toNumber:re,toDate:ae,toDateTime:ie,toBoolean:le,fixSpatialReference:se,fixNullGeometry:ue,getDomainValue:fe,getDomainCode:ce,getDomain:me,stableStringify:ye,autoCastFeatureToGeometry:pe,autoCastArrayOfPointsToPolygon:he,autoCastArrayOfPointsToPolyline:Se,autoCastArrayOfPointsToMultiPoint:be,toStringArray:xe,tick:Me,binaryOperator:Ne,castAsJson:De,castAsJsonAsync:je,featureFullDomain:Ae,featureSubtypes:Re,featureDomainValueLookup:Fe,featureDomainCodeLookup:Ce,featureSchema:Ie},Symbol.toStringTag,{value:"Module"}));export{T as $,v as A,O as B,W as C,ie as D,H as E,ue as F,pe as G,Se as H,N as I,he as J,be as K,R as L,U as M,Ie as N,Re as O,Ae as P,Fe as Q,D as R,Ce as S,P as T,G as U,ee as V,Me as W,xe as X,me as Y,fe as Z,ce as _,_ as a,M as a0,C as a1,q as a2,B as a3,ye as a4,Z as b,w as c,De as d,je as e,I as f,re as g,le as h,F as i,K as j,z as k,ae as l,Y as m,ve as n,j as o,A as p,se as q,Q as r,X as s,te as t,Ne as u,k as v,J as w,E as x,V as y,L as z};