@chillwhales/lsp4 0.1.1 → 0.2.0
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/dist/index.d.mts +74 -2
- package/dist/index.d.ts +74 -2
- package/dist/index.mjs +36 -2
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _chillwhales_lsp2 from '@chillwhales/lsp2';
|
|
2
2
|
import { Image } from '@chillwhales/lsp2';
|
|
3
|
+
import { ImageSize } from '@chillwhales/utils';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -376,6 +377,20 @@ declare const lsp4MetadataSchema: z.ZodObject<{
|
|
|
376
377
|
|
|
377
378
|
type LSP4Attribute = z.infer<typeof attributesSchema>;
|
|
378
379
|
type LSP4Metadata = z.infer<typeof lsp4MetadataSchema>;
|
|
380
|
+
/**
|
|
381
|
+
* Extended NFT metadata with optional token identification fields.
|
|
382
|
+
*
|
|
383
|
+
* Adds `tokenName`, `tokenIdFormat`, and `formattedTokenId` on top of
|
|
384
|
+
* standard LSP4 metadata for use with `getNftDisplayName`.
|
|
385
|
+
*/
|
|
386
|
+
interface NftMetadata extends LSP4Metadata {
|
|
387
|
+
/** Token collection name (e.g., "CoolCats") */
|
|
388
|
+
tokenName?: string;
|
|
389
|
+
/** Format of the token ID (e.g., "NUMBER", "STRING") */
|
|
390
|
+
tokenIdFormat?: string;
|
|
391
|
+
/** Pre-formatted token ID for display */
|
|
392
|
+
formattedTokenId?: string;
|
|
393
|
+
}
|
|
379
394
|
|
|
380
395
|
/**
|
|
381
396
|
* LSP4 Digital Asset Metadata Utilities
|
|
@@ -415,6 +430,63 @@ declare function getImageUrl(options: {
|
|
|
415
430
|
* @returns Display name string
|
|
416
431
|
*/
|
|
417
432
|
declare function getAssetDisplayName(metadata: LSP4Metadata): string;
|
|
433
|
+
/**
|
|
434
|
+
* Extract avatar image URL from Digital Asset metadata.
|
|
435
|
+
* Prefers icon, falls back to images. Optionally finds the closest image
|
|
436
|
+
* to target dimensions.
|
|
437
|
+
*
|
|
438
|
+
* @param metadata - Digital Asset (LSP7/LSP8) metadata
|
|
439
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
440
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
441
|
+
* @returns Parsed URL or undefined if no image found
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* // Get first available image (prefers icon)
|
|
446
|
+
* getAssetImageUrl(asset, parseIpfsUrl)
|
|
447
|
+
*
|
|
448
|
+
* // Get image closest to 128×128
|
|
449
|
+
* getAssetImageUrl(asset, parseIpfsUrl, { width: 128, height: 128 })
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
declare function getAssetImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
453
|
+
/**
|
|
454
|
+
* Extract avatar image URL from NFT metadata.
|
|
455
|
+
* Prefers images (usually more detailed), falls back to icon.
|
|
456
|
+
* Optionally finds the closest image to target dimensions.
|
|
457
|
+
*
|
|
458
|
+
* @param metadata - NFT (LSP8 token) metadata
|
|
459
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
460
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
461
|
+
* @returns Parsed URL or undefined if no image found
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```typescript
|
|
465
|
+
* // Get first available image (prefers full images)
|
|
466
|
+
* getNftImageUrl(nft, parseIpfsUrl)
|
|
467
|
+
*
|
|
468
|
+
* // Get image closest to 256×256
|
|
469
|
+
* getNftImageUrl(nft, parseIpfsUrl, { width: 256, height: 256 })
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
declare function getNftImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
473
|
+
/**
|
|
474
|
+
* Get display name for NFT (LSP8 token).
|
|
475
|
+
* Includes token ID formatting (e.g., "TokenName #123").
|
|
476
|
+
*
|
|
477
|
+
* @param metadata - NFT metadata with optional token info
|
|
478
|
+
* @returns Display name string, possibly with token ID suffix
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* getNftDisplayName({ tokenName: "CoolCats", tokenIdFormat: "NUMBER", formattedTokenId: "42" })
|
|
483
|
+
* // => "CoolCats #42"
|
|
484
|
+
*
|
|
485
|
+
* getNftDisplayName({ tokenName: "Art" })
|
|
486
|
+
* // => "Art"
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
declare function getNftDisplayName(metadata: NftMetadata): string;
|
|
418
490
|
|
|
419
491
|
/**
|
|
420
492
|
* LSP4 Type Guards
|
|
@@ -431,5 +503,5 @@ declare function isAttributesSchema(obj: unknown): obj is z.infer<typeof attribu
|
|
|
431
503
|
*/
|
|
432
504
|
declare function isLsp4MetadataSchema(obj: unknown): obj is z.infer<typeof lsp4MetadataSchema>;
|
|
433
505
|
|
|
434
|
-
export { attributesSchema, getAssetDisplayName, getImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
435
|
-
export type { LSP4Attribute, LSP4Metadata };
|
|
506
|
+
export { attributesSchema, getAssetDisplayName, getAssetImageUrl, getImageUrl, getNftDisplayName, getNftImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
507
|
+
export type { LSP4Attribute, LSP4Metadata, NftMetadata };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _chillwhales_lsp2 from '@chillwhales/lsp2';
|
|
2
2
|
import { Image } from '@chillwhales/lsp2';
|
|
3
|
+
import { ImageSize } from '@chillwhales/utils';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -376,6 +377,20 @@ declare const lsp4MetadataSchema: z.ZodObject<{
|
|
|
376
377
|
|
|
377
378
|
type LSP4Attribute = z.infer<typeof attributesSchema>;
|
|
378
379
|
type LSP4Metadata = z.infer<typeof lsp4MetadataSchema>;
|
|
380
|
+
/**
|
|
381
|
+
* Extended NFT metadata with optional token identification fields.
|
|
382
|
+
*
|
|
383
|
+
* Adds `tokenName`, `tokenIdFormat`, and `formattedTokenId` on top of
|
|
384
|
+
* standard LSP4 metadata for use with `getNftDisplayName`.
|
|
385
|
+
*/
|
|
386
|
+
interface NftMetadata extends LSP4Metadata {
|
|
387
|
+
/** Token collection name (e.g., "CoolCats") */
|
|
388
|
+
tokenName?: string;
|
|
389
|
+
/** Format of the token ID (e.g., "NUMBER", "STRING") */
|
|
390
|
+
tokenIdFormat?: string;
|
|
391
|
+
/** Pre-formatted token ID for display */
|
|
392
|
+
formattedTokenId?: string;
|
|
393
|
+
}
|
|
379
394
|
|
|
380
395
|
/**
|
|
381
396
|
* LSP4 Digital Asset Metadata Utilities
|
|
@@ -415,6 +430,63 @@ declare function getImageUrl(options: {
|
|
|
415
430
|
* @returns Display name string
|
|
416
431
|
*/
|
|
417
432
|
declare function getAssetDisplayName(metadata: LSP4Metadata): string;
|
|
433
|
+
/**
|
|
434
|
+
* Extract avatar image URL from Digital Asset metadata.
|
|
435
|
+
* Prefers icon, falls back to images. Optionally finds the closest image
|
|
436
|
+
* to target dimensions.
|
|
437
|
+
*
|
|
438
|
+
* @param metadata - Digital Asset (LSP7/LSP8) metadata
|
|
439
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
440
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
441
|
+
* @returns Parsed URL or undefined if no image found
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* // Get first available image (prefers icon)
|
|
446
|
+
* getAssetImageUrl(asset, parseIpfsUrl)
|
|
447
|
+
*
|
|
448
|
+
* // Get image closest to 128×128
|
|
449
|
+
* getAssetImageUrl(asset, parseIpfsUrl, { width: 128, height: 128 })
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
declare function getAssetImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
453
|
+
/**
|
|
454
|
+
* Extract avatar image URL from NFT metadata.
|
|
455
|
+
* Prefers images (usually more detailed), falls back to icon.
|
|
456
|
+
* Optionally finds the closest image to target dimensions.
|
|
457
|
+
*
|
|
458
|
+
* @param metadata - NFT (LSP8 token) metadata
|
|
459
|
+
* @param parseUrl - Function to parse/transform the URL (e.g., IPFS gateway resolution)
|
|
460
|
+
* @param options - Optional target dimensions `{ width, height }`
|
|
461
|
+
* @returns Parsed URL or undefined if no image found
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```typescript
|
|
465
|
+
* // Get first available image (prefers full images)
|
|
466
|
+
* getNftImageUrl(nft, parseIpfsUrl)
|
|
467
|
+
*
|
|
468
|
+
* // Get image closest to 256×256
|
|
469
|
+
* getNftImageUrl(nft, parseIpfsUrl, { width: 256, height: 256 })
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
declare function getNftImageUrl(metadata: LSP4Metadata, parseUrl: (url: string) => string, options?: Partial<ImageSize>): string | undefined;
|
|
473
|
+
/**
|
|
474
|
+
* Get display name for NFT (LSP8 token).
|
|
475
|
+
* Includes token ID formatting (e.g., "TokenName #123").
|
|
476
|
+
*
|
|
477
|
+
* @param metadata - NFT metadata with optional token info
|
|
478
|
+
* @returns Display name string, possibly with token ID suffix
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* getNftDisplayName({ tokenName: "CoolCats", tokenIdFormat: "NUMBER", formattedTokenId: "42" })
|
|
483
|
+
* // => "CoolCats #42"
|
|
484
|
+
*
|
|
485
|
+
* getNftDisplayName({ tokenName: "Art" })
|
|
486
|
+
* // => "Art"
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
declare function getNftDisplayName(metadata: NftMetadata): string;
|
|
418
490
|
|
|
419
491
|
/**
|
|
420
492
|
* LSP4 Type Guards
|
|
@@ -431,5 +503,5 @@ declare function isAttributesSchema(obj: unknown): obj is z.infer<typeof attribu
|
|
|
431
503
|
*/
|
|
432
504
|
declare function isLsp4MetadataSchema(obj: unknown): obj is z.infer<typeof lsp4MetadataSchema>;
|
|
433
505
|
|
|
434
|
-
export { attributesSchema, getAssetDisplayName, getImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
435
|
-
export type { LSP4Attribute, LSP4Metadata };
|
|
506
|
+
export { attributesSchema, getAssetDisplayName, getAssetImageUrl, getImageUrl, getNftDisplayName, getNftImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
507
|
+
export type { LSP4Attribute, LSP4Metadata, NftMetadata };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { findBestImage, isNumeric } from '@chillwhales/utils';
|
|
1
2
|
import { assetSchema, imageSchema, linkSchema } from '@chillwhales/lsp2';
|
|
2
|
-
import { isNumeric } from '@chillwhales/utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
function getImageUrl(options) {
|
|
@@ -17,6 +17,40 @@ function getImageUrl(options) {
|
|
|
17
17
|
function getAssetDisplayName(metadata) {
|
|
18
18
|
return metadata.name || "Digital Asset";
|
|
19
19
|
}
|
|
20
|
+
function getAssetImageUrl(metadata, parseUrl, options) {
|
|
21
|
+
const icon = findBestImage(metadata.icon, options);
|
|
22
|
+
if (icon?.url) {
|
|
23
|
+
return parseUrl(icon.url);
|
|
24
|
+
}
|
|
25
|
+
const allImages = metadata.images?.flat();
|
|
26
|
+
const image = findBestImage(allImages, options);
|
|
27
|
+
if (image?.url) {
|
|
28
|
+
return parseUrl(image.url);
|
|
29
|
+
}
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
function getNftImageUrl(metadata, parseUrl, options) {
|
|
33
|
+
const allImages = metadata.images?.flat();
|
|
34
|
+
const image = findBestImage(allImages, options);
|
|
35
|
+
if (image?.url) {
|
|
36
|
+
return parseUrl(image.url);
|
|
37
|
+
}
|
|
38
|
+
const icon = findBestImage(metadata.icon, options);
|
|
39
|
+
if (icon?.url) {
|
|
40
|
+
return parseUrl(icon.url);
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
function getNftDisplayName(metadata) {
|
|
45
|
+
const baseName = metadata.tokenName || "NFT";
|
|
46
|
+
if (metadata.tokenIdFormat === "NUMBER" && metadata.formattedTokenId) {
|
|
47
|
+
return `${baseName} #${metadata.formattedTokenId}`;
|
|
48
|
+
}
|
|
49
|
+
if (metadata.formattedTokenId) {
|
|
50
|
+
return `${baseName} ${metadata.formattedTokenId}`;
|
|
51
|
+
}
|
|
52
|
+
return baseName;
|
|
53
|
+
}
|
|
20
54
|
|
|
21
55
|
const attributesSchema = z.discriminatedUnion("type", [
|
|
22
56
|
z.object({
|
|
@@ -61,4 +95,4 @@ function isLsp4MetadataSchema(obj) {
|
|
|
61
95
|
return success;
|
|
62
96
|
}
|
|
63
97
|
|
|
64
|
-
export { attributesSchema, getAssetDisplayName, getImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
|
98
|
+
export { attributesSchema, getAssetDisplayName, getAssetImageUrl, getImageUrl, getNftDisplayName, getNftImageUrl, isAttributesSchema, isLsp4MetadataSchema, lsp4MetadataSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chillwhales/lsp4",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "LSP4 Digital Asset Metadata — schemas, types, and utilities for LSP7/LSP8 token metadata on LUKSO",
|
|
6
6
|
"author": "b00ste",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"zod": "^3.24.1",
|
|
41
|
-
"@chillwhales/lsp2": "0.
|
|
42
|
-
"@chillwhales/utils": "0.
|
|
41
|
+
"@chillwhales/lsp2": "0.2.0",
|
|
42
|
+
"@chillwhales/utils": "0.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.9.3",
|