pi-better-openai 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/pets.ts +21 -9
package/package.json
CHANGED
package/src/pets.ts
CHANGED
|
@@ -220,6 +220,18 @@ function petLookupKey(value: string): string {
|
|
|
220
220
|
return value.toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
type PetLookupRequest = {
|
|
224
|
+
hasText: boolean;
|
|
225
|
+
key?: string;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
function petLookupRequest(value?: string): PetLookupRequest {
|
|
229
|
+
const requestedText = value?.trim();
|
|
230
|
+
if (!requestedText) return { hasText: false };
|
|
231
|
+
|
|
232
|
+
return { hasText: true, key: petLookupKey(requestedText) || undefined };
|
|
233
|
+
}
|
|
234
|
+
|
|
223
235
|
function petMatchesLookup(pet: CodexPetPackage, requested: string): boolean {
|
|
224
236
|
return (
|
|
225
237
|
petLookupKey(pet.slug) === requested ||
|
|
@@ -229,22 +241,22 @@ function petMatchesLookup(pet: CodexPetPackage, requested: string): boolean {
|
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
export function findCodexPet(pets: CodexPetPackage[], value?: string): CodexPetPackage | undefined {
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return pets.find((pet) => petMatchesLookup(pet, requested));
|
|
244
|
+
const request = petLookupRequest(value);
|
|
245
|
+
const { key } = request;
|
|
246
|
+
if (!key) return undefined;
|
|
247
|
+
return pets.find((pet) => petMatchesLookup(pet, key));
|
|
237
248
|
}
|
|
238
249
|
|
|
239
250
|
export function findReadyCodexPet(
|
|
240
251
|
pets: CodexPetPackage[],
|
|
241
252
|
value?: string,
|
|
242
253
|
): CodexPetPackage | undefined {
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
254
|
+
const request = petLookupRequest(value);
|
|
255
|
+
if (!request.hasText) return pets.find((pet) => pet.hasSpritesheet);
|
|
245
256
|
|
|
246
|
-
const
|
|
247
|
-
|
|
257
|
+
const { key } = request;
|
|
258
|
+
if (!key) return undefined;
|
|
259
|
+
return pets.find((pet) => pet.hasSpritesheet && petMatchesLookup(pet, key));
|
|
248
260
|
}
|
|
249
261
|
|
|
250
262
|
function selectPet(pets: CodexPetPackage[], slug?: string): CodexPetPackage | undefined {
|