Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opensea/seadn

Package Overview
Dependencies
Maintainers
10
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opensea/seadn - npm Package Compare versions

Comparing version 1.0.7 to 2.0.0

dist/index.d.mts

15

dist/index.d.ts

@@ -1,11 +0,10 @@

/// <reference types="node" />
export type ResizeParams = {
freezeAnimation?: boolean;
dpr?: number;
type MediaFormat = "webp" | "avif" | "jpeg" | "png";
type MediaParams = {
width?: number | `${number}`;
height?: number | `${number}`;
format?: MediaFormat;
};
export declare const resizeImage: (image: string | URL, { width, height, dpr, freezeAnimation }: ResizeParams) => string;
export declare const isSupportedFormat: (src: string | URL) => boolean;
export declare const isSupportedURL: (src: string | URL) => boolean;
//# sourceMappingURL=index.d.ts.map
declare function optimize(image: string | URL, { width, height, format }: MediaParams): string;
declare function canBeOptimized(url: URL): boolean;
export { type MediaFormat, type MediaParams, canBeOptimized, optimize };
{
"name": "@opensea/seadn",
"version": "1.0.7",
"version": "2.0.0",
"description": "Javascript SDK to work with SeaDN",
"license": "MIT",
"author": "OpenSea Developers",
"type": "module",
"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.modern.js"
},
"main": "./dist/index.cjs",
"module": "./dist/index.module.js",
"sideEffects": false,
"main": "./src/index.ts",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [

@@ -19,34 +16,13 @@ "./dist",

"scripts": {
"build": "microbundle",
"check-types": "tsc --noEmit",
"lint": "concurrently \"npm run check-types\" \"npm run prettier:check\" \"npm run prettier:package.json:check\"",
"prepare": "husky install",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"prettier:package.json:check": "prettier-package-json --list-different",
"test": "vitest"
"build": "tsup",
"build:typecheck": "attw --pack",
"test": "vitest",
"typecheck": "tsc"
},
"sideEffects": false,
"types": "./dist/index.d.ts",
"devDependencies": {
"@vitest/coverage-v8": "0.33.0",
"concurrently": "8.2.0",
"esbuild": "0.19.0",
"husky": "8.0.3",
"lint-staged": "13.2.3",
"microbundle": "0.15.1",
"prettier": "3.0.1",
"prettier-package-json": "2.8.0",
"vitest": "0.33.0"
},
"lint-staged": {
"package.json": [
"prettier-package-json --write"
],
"**/*.{ts,tsx,js,jsx,html,md,mdx,yml,json}": [
"prettier --write"
]
},
"source": "src/index.ts",
"unpkg": "./dist/index.umd.js"
"@arethetypeswrong/cli": "0.13.4",
"tsup": "8.0.1",
"typescript": "5.3.3",
"vitest": "1.1.0"
}
}
# SeaDN Javascript SDK
## Installation
## Getting Started
### Installation
**npm**
```sh
npm i @opensea/seadn
npm install @opensea/seadn
```
## Usage
**yarn**
**Resizing**
```sh
yarn install @opensea/seadn
```
```js
import { resizeImage } from '@opensea/seadn';
**pnpm**
const resized = resizeImage(image, { height: 100, width: 100 });
```sh
pnpm add @opensea/seadn
```
**Usage with next/image**
### Usage
```jsx
import { isSupportedURL, resizeImage } from '@opensea/seadn';
import type { ImageLoader, ImageProps } from 'next/image';
```js
import { resizeImage } from "@opensea/seadn";
// custom loader
export const seadnLoader: ImageLoader = ({ src, width }) => {
if (!isSupportedURL(src)) {
return src;
}
return resizeImage(src, { width });
};
// prop overrides
export const nextImageProps = <T extends ImageProps>({
src,
...rest
}: T): ImageProps => {
if (isSupportedURL(src)) {
return {
...rest,
src: resizeImage(src as string, {
width: rest.width,
height: rest.height
}),
unoptimized: true
};
}
return { src, ...rest };
};
// MyComponent.tsx
return (
<>
<Image {...nextImageProps({ alt: 'House', height: 200, src: imageUrl, width: 200 })} />
</>
)
const resized = resizeImage(image, { height: 100, width: 100 });
```

@@ -1,80 +0,1 @@

export type ResizeParams = {
freezeAnimation?: boolean;
dpr?: number;
width?: number | `${number}`;
height?: number | `${number}`;
};
export const resizeImage = (
image: string | URL,
{ width, height, dpr = 1, freezeAnimation = false }: ResizeParams
): string => {
try {
if (typeof image === 'string') {
image = new URL(image);
}
} catch {
return image.toString();
}
if (!(image instanceof URL)) {
return image;
}
const params = new URLSearchParams({
auto: 'format',
dpr: String(dpr)
});
if (width !== undefined) {
params.set('w', String(width));
}
if (height !== undefined) {
params.set('h', String(height));
}
if (freezeAnimation) {
params.set('fr', '1');
}
image.search = params.toString();
return image.toString();
};
export const isSupportedFormat = (src: string | URL): boolean => {
try {
if (typeof src === 'string') {
src = new URL(src);
}
} catch {
return false;
}
if (!(src instanceof URL)) {
return false;
}
const { pathname } = src;
return (
pathname.endsWith('.jpg') ||
pathname.endsWith('.jpeg') ||
pathname.endsWith('.png') ||
pathname.endsWith('.webp') ||
pathname.endsWith('.gif') ||
pathname.startsWith('/gae/') // GoogleAppEngine URLs do not contain extensions
);
};
export const isSupportedURL = (src: string | URL): boolean => {
try {
if (typeof src === 'string') {
src = new URL(src);
}
} catch {
return false;
}
if (!(src instanceof URL)) {
return false;
}
return src.hostname === 'i.seadn.io' && isSupportedFormat(src);
};
export { optimize, MediaParams, MediaFormat, canBeOptimized } from "./sdk";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc