MCPcopy Create free account
hub / github.com/blacksmithgu/datacore / DataArrayImpl

Class DataArrayImpl

src/api/data-array.ts:132–465  ·  view source on GitHub ↗

@internal Implementation of DataArray, minus the dynamic variable access, which is implemented via proxy.

Source from the content-addressed store, hash-verified

130
131/** @internal Implementation of DataArray, minus the dynamic variable access, which is implemented via proxy. */
132class DataArrayImpl<T> implements DataArray<T> {
133 private static ARRAY_FUNCTIONS: Set<string> = new Set([
134 "chain",
135 "where",
136 "filter",
137 "map",
138 "flatMap",
139 "mutate",
140 "slice",
141 "concat",
142 "indexOf",
143 "limit",
144 "find",
145 "findIndex",
146 "includes",
147 "join",
148 "sort",
149 "sortInPlace",
150 "groupBy",
151 "groupIn",
152 "distinct",
153 "every",
154 "some",
155 "none",
156 "first",
157 "last",
158 "to",
159 "into",
160 "lwrap",
161 "expand",
162 "forEach",
163 "length",
164 "values",
165 "array",
166 "defaultComparator",
167 "toString",
168 "settings",
169 ]);
170
171 private static ARRAY_PROXY: ProxyHandler<DataArrayImpl<unknown>> = {
172 get: function (target, prop, reciever) {
173 if (typeof prop === "symbol") return (target as unknown as Record<symbol, unknown>)[prop];
174 else if (typeof prop === "number") return target.values[prop];
175 else if (prop === "constructor") return target.values.constructor;
176 else if (!isNaN(parseInt(prop))) return target.values[parseInt(prop)];
177 else if (DataArrayImpl.ARRAY_FUNCTIONS.has(prop.toString()))
178 return (target as unknown as Record<string, unknown>)[prop.toString()];
179
180 return target.to(prop);
181 },
182 };
183
184 public static wrap<T>(
185 arr: T[],
186 defaultComparator: ArrayComparator<unknown> = DataArray.defaultComparator
187 ): DataArray<T> {
188 return new Proxy<DataArrayImpl<T>>(
189 new DataArrayImpl<T>(arr, defaultComparator),

Callers

nothing calls this directly

Calls 2

toMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected