string.js 12 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 t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as a}from"../executionError.js";import{y as o,j as i,B as u,g as s,M as p,v as d,A as c,h as l,t as f,m as h,x as y,L as m,w as g,N as A,O as w,P as I,Q as v,S as U,c as x,k as b,a as j,b as P,i as F,T as C,U as N}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as T}from"../featureset/support/shared.js";import{convertDirection as k}from"./convertdirection.js";import{XXH as L}from"./hash.js";import O from"../../geometry/Extent.js";import z from"../../geometry/Multipoint.js";import R from"../../geometry/Point.js";import M from"../../geometry/Polygon.js";import S from"../../geometry/Polyline.js";import H from"../../geometry/SpatialReference.js";function D(t,e){if(!t||!e)return t===e;if(t.x===e.x&&t.y===e.y){if(t.hasZ){if(t.z!==e.z)return!1}else if(e.hasZ)return!1;if(t.hasM){if(t.m!==e.m)return!1}else if(e.hasM)return!1;return!0}return!1}function W(o,i,u){if(null!==o)if(h(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o)W(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else if(y(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.toArray())W(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else{if(b(o))return i.updateIntArray([o.getTime()]),void i.updateUint8Array([241]);if(x(o))return i.updateIntArray([o.length]),i.updateWithString(o),void i.updateUint8Array([41]);if(j(o))i.updateUint8Array([!0===o?1:0,113]);else{if(P(o))return i.updateFloatArray([o]),void i.updateUint8Array([173]);if(o instanceof e)throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof t)throw new n(u.context,a.UnsupportedHashType,u.node);if(!(o instanceof r)){if(g(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof R)return i.updateIntArray([3833836621]),i.updateIntArray([0]),i.updateFloatArray([o.x]),i.updateIntArray([1]),i.updateFloatArray([o.y]),o.hasZ&&(i.updateIntArray([2]),i.updateFloatArray([o.z])),o.hasM&&(i.updateIntArray([3]),i.updateFloatArray([o.m])),i.updateIntArray([3765347959]),void W(o.spatialReference.wkid,i,u);if(o instanceof M){i.updateIntArray([1266616829]);for(let t=0;t<o.rings.length;t++){const e=o.rings[t],r=[];let n=null,a=null;for(let i=0;i<e.length;i++){const u=o.getPoint(t,i);if(0===i)n=u;else if(D(a,u))continue;a=u,i===e.length-1&&D(n,u)||r.push(u)}i.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];i.updateIntArray([3962308117,t]),W(e,i,u),i.updateIntArray([2716288009])}i.updateIntArray([2278822459])}return i.updateIntArray([3878477243]),void W(o.spatialReference.wkid,i,u)}if(o instanceof S){i.updateIntArray([4106883559]);for(let t=0;t<o.paths.length;t++){const e=o.paths[t];i.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)i.updateIntArray([3962308117,r]),W(o.getPoint(t,r),i,u),i.updateIntArray([2716288009]);i.updateIntArray([2278822459])}return i.updateIntArray([2568784753]),void W(o.spatialReference.wkid,i,u)}if(o instanceof z){i.updateIntArray([588535921,o.points.length]);for(let t=0;t<o.points.length;t++){const e=o.getPoint(t);i.updateIntArray([t]),W(e,i,u)}return i.updateIntArray([1700171621]),void W(o.spatialReference.wkid,i,u)}if(o instanceof O)return i.updateIntArray([3483648373]),i.updateIntArray([0]),i.updateFloatArray([o.xmax]),i.updateIntArray([1]),i.updateFloatArray([o.xmin]),i.updateIntArray([2]),i.updateFloatArray([o.ymax]),i.updateIntArray([3]),i.updateFloatArray([o.ymin]),o.hasZ&&(i.updateIntArray([4]),i.updateFloatArray([o.zmax]),i.updateIntArray([5]),i.updateFloatArray([o.zmin])),o.hasM&&(i.updateIntArray([6]),i.updateFloatArray([o.mmax]),i.updateIntArray([7]),i.updateFloatArray([o.mmin])),i.updateIntArray([3622027469]),void W(o.spatialReference.wkid,i,u);if(o instanceof H)return i.updateIntArray([14]),void 0!==o.wkid&&null!==o.wkid&&i.updateIntArray([o.wkid]),void(o.wkt&&i.updateWithString(o.wkt));if(F(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(C(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(N(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o===d)throw new n(u.context,a.UnsupportedHashType,u.node);throw new n(u.context,a.UnsupportedHashType,u.node)}if(i.updateUint8Array([223]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.keys()){i.updateIntArray([t.length]),i.updateWithString(t),i.updateUint8Array([251]);W(o.field(t),i,u),i.updateUint8Array([239])}u.map.delete(o),u.currentLength--}i.updateUint8Array([73])}}else i.updateUint8Array([0,139])}function B(e,b){e.portal=function(e,r){return b(e,r,((n,a,u)=>(o(u,1,1,e,r),new t(i(u[0])))))},e.typeof=function(t,e){return b(t,e,((r,i,s)=>{o(s,1,1,t,e);const p=u(s[0]);if("Unrecognised Type"===p)throw new n(t,a.UnrecognisedType,e);return p}))},e.trim=function(t,e){return b(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim())))},e.tohex=function(t,e){return b(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)}))},e.upper=function(t,e){return b(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase())))},e.proper=function(t,e){return b(t,e,((r,n,a)=>{o(a,1,2,t,e);let u=1;2===a.length&&"firstword"===i(a[1]).toLowerCase()&&(u=2);const s=/\s/,p=i(a[0]);let d="",c=!0;for(let t=0;t<p.length;t++){let e=p[t];if(s.test(e))1===u&&(c=!0);else{e.toUpperCase()!==e.toLowerCase()&&(c?(e=e.toUpperCase(),c=!1):e=e.toLowerCase())}d+=e}return d}))},e.lower=function(t,e){return b(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase())))},e.guid=function(t,e){return b(t,e,((r,n,a)=>{if(o(a,0,1,t,e),a.length>0)switch(i(a[0]).toLowerCase()){case"digits":return p().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return p();case"digits-hyphen-braces":return"{"+p()+"}";case"digits-hyphen-parentheses":return"("+p()+")"}return"{"+p()+"}"}))},e.standardizeguid=function(t,e){return b(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(\-?)(?<partB>[0-9a-z]{4})(\-?)(?<partC>[0-9a-z]{4})(\-?)(?<partD>[0-9a-z]{4})(\-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const p=s.groups;switch(u=p.partA+"-"+p.partB+"-"+p.partC+"-"+p.partD+"-"+p.partE,i(a[1]).toLowerCase()){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-braces":return"{"+u+"}";case"digits-hyphen-parentheses":return"("+u+")"}return"{"+u+"}"}))},e.console=function(t,e){return b(t,e,((e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),d)))},e.mid=function(t,e){return b(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u<0&&(u=0),2===a.length)return i(a[0]).substr(u);let p=s(a[2]);return isNaN(p)?"":(p<0&&(p=0),i(a[0]).substr(u,p))}))},e.find=function(t,e){return b(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(c(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)}))},e.left=function(t,e){return b(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(0,u))}))},e.right=function(t,e){return b(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(-1*u,u))}))},e.split=function(t,e){return b(t,e,((r,n,a)=>{let u;o(a,2,4,t,e);let p=s(c(a[2],-1));const d=l(c(a[3],!1));if(-1===p||null===p||!0===d?u=i(a[0]).split(i(a[1])):(isNaN(p)&&(p=-1),p<-1&&(p=-1),u=i(a[0]).split(i(a[1]),p)),!1===d)return u;const f=[];for(let t=0;t<u.length&&!(-1!==p&&f.length>=p);t++)""!==u[t]&&void 0!==u[t]&&f.push(u[t]);return f}))},e.text=function(t,e){return b(t,e,((r,n,a)=>(o(a,1,2,t,e),f(a[0],a[1]))))},e.concatenate=function(t,e){return b(t,e,((t,e,r)=>{const n=[];if(r.length<1)return"";if(h(r[0])){const t=c(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=f(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(y(r[0])){const t=c(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=f(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=f(r[a]);return n.join("")}))},e.reverse=function(t,e){return b(t,e,((r,i,u)=>{if(o(u,1,1,t,e),h(u[0])){const t=u[0].slice(0);return t.reverse(),t}if(y(u[0])){const t=u[0].toArray().slice(0);return t.reverse(),t}throw new n(t,a.InvalidParameter,e)}))},e.replace=function(t,e){return b(t,e,((r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),p=i(a[2]);return 4!==a.length||l(a[3])?m(u,s,p):u.replace(s,p)}))},e.schema=function(t,e){return b(t,e,((o,i,u)=>{if(g(u[0])){const t=A(u[0]);return t?r.convertObjectToArcadeDictionary(t):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypes=function(t,e){return b(t,e,((i,u,s)=>{if(o(s,1,1,t,e),g(s[0])){const t=w(s[0]);return t?r.convertObjectToArcadeDictionary(t):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypecode=function(t,e){return b(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0])){const t=w(u[0]);if(!t)return null;if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.code;return null}return null}throw new n(t,a.InvalidParameter,e)}))},e.subtypename=function(t,e){return b(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0])){const t=w(u[0]);if(!t)return"";if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.name;return""}return""}throw new n(t,a.InvalidParameter,e)}))},e.gdbversion=function(t,e){return b(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0]))return u[0].gdbVersion();throw new n(t,a.InvalidParameter,e)}))},e.domain=function(t,e){return b(t,e,((u,p,d)=>{if(o(d,2,3,t,e),g(d[0])){const t=I(d[0],i(d[1]),void 0===d[2]?void 0:s(d[2]));return t&&t.domain?"coded-value"===t.domain.type||"codedValue"===t.domain.type?r.convertObjectToArcadeDictionary({type:"codedValue",name:t.domain.name,dataType:T[t.field.type],codedValues:t.domain.codedValues.map((t=>({name:t.name,code:t.code})))}):r.convertObjectToArcadeDictionary({type:"range",name:t.domain.name,dataType:T[t.field.type],min:t.domain.min,max:t.domain.max}):null}throw new n(t,a.InvalidParameter,e)}))},e.domainname=function(t,e){return b(t,e,((r,u,p)=>{if(o(p,2,4,t,e),g(p[0]))return v(p[0],i(p[1]),p[2],void 0===p[3]?void 0:s(p[3]));throw new n(t,a.InvalidParameter,e)}))},e.domaincode=function(t,e){return b(t,e,((r,u,p)=>{if(o(p,2,4,t,e),g(p[0]))return U(p[0],i(p[1]),p[2],void 0===p[3]?void 0:s(p[3]));throw new n(t,a.InvalidParameter,e)}))},e.urlencode=function(t,e){return b(t,e,((n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))}))},e.hash=function(t,e){return b(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=new L(0);return W(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()}))},e.convertdirection=function(t,e){return b(t,e,((r,n,a)=>(o(a,3,3,t,e),k(a[0],a[1],a[2]))))},e.fromjson=function(t,e){return b(t,e,((u,s,p)=>{if(o(p,1,1,t,e),!1===x(p[0]))throw new n(t,a.InvalidParameter,e);return r.convertJsonToArcade(JSON.parse(i(p[0])))}))},e.expects=function(t,e){return b(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);return d}))},e.tocharcode=function(t,e){return b(t,e,((r,u,p)=>{o(p,1,2,t,e);const d=s(c(p[1],0)),l=i(p[0]);if(0===l.length&&1===p.length)return null;if(l.length<=d||d<0)throw new n(t,a.OutOfBounds,e);return l.charCodeAt(d)}))},e.tocodepoint=function(t,e){return b(t,e,((r,u,p)=>{o(p,1,2,t,e);const d=s(c(p[1],0)),l=i(p[0]);if(0===l.length&&1===p.length)return null;if(l.length<=d||d<0)throw new n(t,a.OutOfBounds,e);return l.codePointAt(d)}))},e.fromcharcode=function(t,e){return b(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);const u=i.map((t=>Math.trunc(s(t)))).filter((t=>t>=0&&t<=65535));return 0===u.length?null:String.fromCharCode.apply(null,u)}))},e.fromcodepoint=function(t,e){return b(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);let u;try{u=i.map((t=>Math.trunc(s(t)))).filter((t=>t<=1114111&&t>>>0===t))}catch(p){return null}return 0===u.length?null:String.fromCodePoint.apply(null,u)}))}}export{B as registerFunctions};