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

srcset

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

srcset - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

118

index.d.ts

@@ -1,78 +0,70 @@

/* eslint-disable no-redeclare */
export interface SrcSetDefinition {
readonly url: string;
readonly width?: number;
readonly density?: number;
}
declare namespace srcset {
interface SrcSetDefinition {
url: string;
width?: number;
density?: number;
}
export interface Options {
/**
When strict mode is enabled, errors will be thrown on invalid input.
interface Options {
/**
When strict mode is enabled, errors will be thrown on invalid input.
When disabled, a best effort will be made to handle invalid input and no errors will be thrown. The output may be invalid.
When disabled, a best effort will be made to handle invalid input and no errors will be thrown. The output may be invalid.
@default false
*/
strict?: boolean;
}
@default false
*/
readonly strict?: boolean;
}
declare const srcset: {
/**
Parse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
/**
Parse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
Accepts a “srcset” string and returns an array of objects with the possible properties: `url` (always), `width`, `density`, and `height`.
Accepts a “srcset” string and returns an array of objects with the possible properties: `url` (always), `width`, `density`, and `height`.
@param srcset - A “srcset” string.
@param srcset - A “srcset” string.
@example
```
import srcset = require('srcset');
@example
```
import {parseSrcset} from 'srcset';
console.log(srcset.parse('banner-HD.jpg 2x, banner-phone.jpg 100w'));
// [
// {
// url: 'banner-HD.jpg',
// density: 2
// },
// {
// url: 'banner-phone.jpg',
// width: 100
// }
// ]
```
*/
parse: (srcset: string, options?: srcset.Options) => srcset.SrcSetDefinition[];
console.log(parseSrcset('banner-HD.jpg 2x, banner-phone.jpg 100w'));
// [
// {
// url: 'banner-HD.jpg',
// density: 2
// },
// {
// url: 'banner-phone.jpg',
// width: 100
// }
// ]
```
*/
export function parseSrcset(srcset: string, options?: Options): SrcSetDefinition[];
/**
Stringify `SrcSetDefinition`s.
/**
Stringify `SrcSetDefinition`s.
@param SrcSetDefinitions - Each object should have a `url` field and may have either `width` or `density`. When the `strict` option is `true`, only `width` or `density` is accepted.
@param SrcSetDefinitions - Each object should have a `url` field and may have either `width` or `density`. When the `strict` option is `true`, only `width` or `density` is accepted.
@returns A “srcset” string.
@returns A “srcset” string.
@example
```
import srcset = require('srcset');
@example
```
import {stringifySrcset} from 'srcset';
const stringified = srcset.stringify([
{
url: 'banner-HD.jpg',
density: 2
},
{
url: 'banner-phone.jpg',
width: 100
}
]);
const stringified = stringifySrcset([
{
url: 'banner-HD.jpg',
density: 2
},
{
url: 'banner-phone.jpg',
width: 100
}
]);
console.log(stringified);
// banner-HD.jpg 2x, banner-phone.jpg 100w
```
*/
stringify: (srcSetDefinitions: readonly srcset.SrcSetDefinition[], options?: srcset.Options) => string;
};
export = srcset;
console.log(stringified);
// banner-HD.jpg 2x, banner-phone.jpg 100w
```
*/
export function stringifySrcset(srcSetDefinitions: readonly SrcSetDefinition[], options?: Options): string;

@@ -1,3 +0,1 @@

'use strict';
/**

@@ -83,4 +81,5 @@ This regex represents a loose rule of an “image candidate string”.

exports.parse = (string, {strict = false} = {}) => {
export function parseSrcset(string, {strict = false} = {}) {
const allDescriptors = strict ? {} : undefined;
return string.split(imageCandidateRegex)

@@ -128,8 +127,9 @@ .filter((part, index) => index % 2 === 1)

});
};
}
const knownDescriptors = new Set(['width', 'height', 'density']);
exports.stringify = (array, {strict = false} = {}) => {
const allDescriptors = strict ? {} : null;
export function stringifySrcset(array, {strict = false} = {}) {
const allDescriptors = strict ? {} : undefined;
return array.map(element => {

@@ -188,2 +188,2 @@ if (!element.url) {

}).join(', ');
};
}
{
"name": "srcset",
"version": "4.0.0",
"version": "5.0.0",
"description": "Parse and stringify the HTML `<img>` srcset attribute",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -38,6 +40,6 @@ "scripts": {

"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.39.0"
"ava": "^3.15.0",
"tsd": "^0.19.0",
"xo": "^0.46.4"
}
}

@@ -9,5 +9,5 @@ # srcset

```sh
npm install srcset
```
$ npm install srcset
```

@@ -29,5 +29,5 @@ ## Usage

```js
const srcset = require('srcset');
import {parseSrcset, stringifySrcset} from 'srcset';
const parsed = srcset.parse('banner-HD.jpg 2x, banner-phone.jpg 100w');
const parsed = parseSrcset('banner-HD.jpg 2x, banner-phone.jpg 100w');
console.log(parsed);

@@ -52,3 +52,3 @@ /*

const stringified = srcset.stringify(parsed);
const stringified = stringifySrcset(parsed);
console.log(stringified);

@@ -62,3 +62,3 @@ /*

### .parse(string, options?)
### parseSrcset(string, options?)

@@ -86,3 +86,3 @@ Parse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.

### .stringify(SrcSetDefinitions, options?)
### stringifySrcset(SrcSetDefinitions, options?)

@@ -103,7 +103,6 @@ Stringify `SrcSetDefinition`s. Accepts an array of `SrcSetDefinition` objects and returns a “srcset” string.

Type: `boolean`
Type: `boolean`\
Default: `false`
Enable or disable validation of the SrcSetDefinitions. When true, invalid input will cause an error to be thrown. When false, a best effort will be made to stringify invalid input, likely resulting in invalid srcset value.
Enable or disable validation of the `SrcSetDefinition`'s. When true, invalid input will cause an error to be thrown. When false, a best effort will be made to stringify invalid input, likely resulting in invalid srcset value.

@@ -110,0 +109,0 @@ ---

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