node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
import{ITSELF as r,createInterpreter as t}from"@ucast/core";function n(r,t,n){for(let e=0,o=r.length;e<o;e++)if(0===n(r[e],t))return!0;return!1}function e(r,t){return Array.isArray(r)&&Number.isNaN(Number(t))}function o(r,t,n){if(!e(r,t))return n(r,t);let o=[];for(let e=0;e<r.length;e++){const u=n(r[e],t);void 0!==u&&(o=o.concat(u))}return o}function u(r){return(t,n,e)=>{const o=e.get(n,t.field);return Array.isArray(o)?o.some(n=>r(t,n,e)):r(t,o,e)}}const c=(r,t)=>r[t];function i(r,t,n){const e=t.lastIndexOf(".");return-1===e?[r,t]:[n(r,t.slice(0,e)),t.slice(e+1)]}function f(t,n,e=c){if(n===r)return t;if(!t)throw new Error(`Unable to get field "${n}" out of ${String(t)}.`);return function(r,t,n){if(-1===t.indexOf("."))return o(r,t,n);const e=t.split(".");let u=r;for(let r=0,t=e.length;r<t;r++)if(u=o(u,e[r],n),!u||"object"!=typeof u)return u;return u}(t,n,e)}function s(r){return(t,n)=>f(t,n,r)}function a(r,t){return r===t?0:r>t?1:-1}function l(r,n={}){return t(r,Object.assign({get:f,compare:a},n))}const p=(r,t,{interpret:n})=>r.value.some(r=>n(r,t)),g=(r,t,n)=>!p(r,t,n),m=(r,t,{interpret:n})=>r.value.every(r=>n(r,t)),y=(r,t,{interpret:n})=>!n(r.value[0],t),b=(r,t,{compare:e,get:o})=>{const u=o(t,r.field);return Array.isArray(u)&&!Array.isArray(r.value)?n(u,r.value,e):0===e(u,r.value)},A=(r,t,n)=>!b(r,t,n),d=u((r,t,n)=>{const e=n.compare(t,r.value);return 0===e||-1===e}),h=u((r,t,n)=>-1===n.compare(t,r.value)),j=u((r,t,n)=>1===n.compare(t,r.value)),w=u((r,t,n)=>{const e=n.compare(t,r.value);return 0===e||1===e}),_=(t,n,{get:o})=>{if(t.field===r)return void 0!==n;const[u,c]=i(n,t.field,o),f=r=>null==r?Boolean(r)===t.value:r.hasOwnProperty(c)===t.value;return e(u,c)?u.some(f):f(u)},v=u((r,t)=>"number"==typeof t&&t%r.value[0]===r.value[1]),x=(t,n,{get:o})=>{const[u,c]=i(n,t.field,o),f=r=>{const n=o(r,c);return Array.isArray(n)&&n.length===t.value};return t.field!==r&&e(u,c)?u.some(f):f(u)},O=u((r,t)=>"string"==typeof t&&r.value.test(t)),N=u((r,t,{compare:e})=>n(r.value,t,e)),$=(r,t,n)=>!N(r,t,n),q=(r,t,{compare:e,get:o})=>{const u=o(t,r.field);return Array.isArray(u)&&r.value.every(r=>n(u,r,e))},z=(r,t,{interpret:n,get:e})=>{const o=e(t,r.field);return Array.isArray(o)&&o.some(t=>n(r.value,t))},B=(r,t)=>r.value.call(t);var E=Object.freeze({__proto__:null,or:p,nor:g,and:m,not:y,eq:b,ne:A,lte:d,lt:h,gt:j,gte:w,exists:_,mod:v,size:x,regex:O,within:N,nin:$,all:q,elemMatch:z,where:B});const M=Object.assign({},E,{in:N}),S=l(M);export{q as all,M as allInterpreters,m as and,a as compare,s as createGetter,l as createJsInterpreter,z as elemMatch,b as eq,_ as exists,f as getObjectField,i as getObjectFieldCursor,j as gt,w as gte,S as interpret,h as lt,d as lte,v as mod,A as ne,$ as nin,g as nor,y as not,p as or,O as regex,x as size,B as where,N as within};
//# sourceMappingURL=index.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../src/utils.ts","../../src/interpreter.ts","../../src/interpreters.ts","../../src/defaults.ts"],"sourcesContent":["import { FieldCondition } from '@ucast/core';\nimport { JsInterpretationOptions, JsInterpreter } from './types';\n\nexport type AnyObject = Record<PropertyKey, unknown>;\nexport type GetField = (object: any, field: string) => any;\n\nexport function includes<T>(\n items: T[],\n value: T,\n compare: JsInterpretationOptions['compare']\n): boolean {\n for (let i = 0, length = items.length; i < length; i++) {\n if (compare(items[i], value) === 0) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function isArrayAndNotNumericField<T>(object: T | T[], field: string): object is T[] {\n return Array.isArray(object) && Number.isNaN(Number(field));\n}\n\nfunction getField<T extends AnyObject>(object: T | T[], field: string, get: GetField) {\n if (!isArrayAndNotNumericField(object, field)) {\n return get(object, field);\n }\n\n let result: unknown[] = [];\n\n for (let i = 0; i < object.length; i++) {\n const value = get(object[i], field);\n if (typeof value !== 'undefined') {\n result = result.concat(value);\n }\n }\n\n return result;\n}\n\nexport function getValueByPath(object: AnyObject, field: string, get: GetField) {\n if (field.indexOf('.') === -1) {\n return getField(object, field, get);\n }\n\n const paths = field.split('.');\n let value = object;\n\n for (let i = 0, length = paths.length; i < length; i++) {\n value = getField(value, paths[i], get);\n\n if (!value || typeof value !== 'object') {\n return value;\n }\n }\n\n return value;\n}\n\nexport function testValueOrArray<T, U = T>(test: JsInterpreter<FieldCondition<T>, U>) {\n return ((node, object, context) => {\n const value = context.get(object, node.field);\n\n if (!Array.isArray(value)) {\n return test(node, value, context);\n }\n\n return value.some(v => test(node, v, context));\n }) as JsInterpreter<FieldCondition<T>, AnyObject | U>;\n}\n","import { createInterpreter, ITSELF } from '@ucast/core';\nimport { getValueByPath, AnyObject, GetField } from './utils';\nimport { JsInterpretationOptions, JsInterpreter } from './types';\n\nconst defaultGet = (object: AnyObject, field: string) => object[field];\ntype Field = string | typeof ITSELF;\n\nexport function getObjectFieldCursor<T extends {}>(object: T, path: string, get: GetField) {\n const dotIndex = path.lastIndexOf('.');\n\n if (dotIndex === -1) {\n return [object, path] as const;\n }\n\n return [\n get(object, path.slice(0, dotIndex)) as T,\n path.slice(dotIndex + 1)\n ] as const;\n}\n\nexport function getObjectField(object: unknown, field: Field, get: GetField = defaultGet) {\n if (field === ITSELF) {\n return object;\n }\n\n if (!object) {\n throw new Error(`Unable to get field \"${field}\" out of ${String(object)}.`);\n }\n\n return getValueByPath(object as Record<string, unknown>, field, get);\n}\n\nexport function createGetter<T extends GetField>(get: T) {\n return (object: Parameters<T>[0], field: Parameters<T>[1]) => getObjectField(object, field, get);\n}\n\nexport function compare<T>(a: T, b: T): 0 | 1 | -1 {\n if (a === b) {\n return 0;\n }\n\n return a > b ? 1 : -1;\n}\n\nexport function createJsInterpreter<\n T extends JsInterpreter<any>,\n O extends Partial<JsInterpretationOptions>\n>(\n operators: Record<string, T>,\n options: O = {} as O\n) {\n return createInterpreter(operators, {\n get: getObjectField,\n compare,\n ...options,\n });\n}\n","import {\n CompoundCondition as Compound,\n FieldCondition as Field,\n DocumentCondition as Document,\n Condition,\n Comparable,\n ITSELF,\n} from '@ucast/core';\nimport { JsInterpreter as Interpret } from './types';\nimport {\n includes,\n testValueOrArray,\n isArrayAndNotNumericField,\n AnyObject,\n} from './utils';\nimport { getObjectFieldCursor } from './interpreter';\n\nexport const or: Interpret<Compound> = (node, object, { interpret }) => {\n return node.value.some(condition => interpret(condition, object));\n};\n\nexport const nor: typeof or = (node, object, context) => {\n return !or(node, object, context);\n};\n\nexport const and: Interpret<Compound> = (node, object, { interpret }) => {\n return node.value.every(condition => interpret(condition, object));\n};\n\nexport const not: Interpret<Compound> = (node, object, { interpret }) => {\n return !interpret(node.value[0], object);\n};\n\nexport const eq: Interpret<Field> = (node, object, { compare, get }) => {\n const value = get(object, node.field);\n\n if (Array.isArray(value) && !Array.isArray(node.value)) {\n return includes(value, node.value, compare);\n }\n\n return compare(value, node.value) === 0;\n};\n\nexport const ne: typeof eq = (node, object, context) => {\n return !eq(node, object, context);\n};\n\nexport const lte = testValueOrArray<Comparable>((node, value, Line truncated