Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 12, 2020
1 parent 898b749 commit cece967
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ declare const srcset: {
// ]
```
*/
parse(srcset: string): srcset.SrcSetDefinition[];
parse: (srcset: string) => srcset.SrcSetDefinition[];

/**
Stringify `SrcSetDefinition`s.
Expand Down Expand Up @@ -60,7 +60,7 @@ declare const srcset: {
// banner-HD.jpg 2x, banner-phone.jpg 100w, banner-phone-HD.jpg 100w 2x
```
*/
stringify(srcSetDefinitions: srcset.SrcSetDefinition[]): string;
stringify: (srcSetDefinitions: srcset.SrcSetDefinition[]) => string;
};

export = srcset;
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ exports.parse = string => {
return;
}

const value = element.slice(0, element.length - 1);
const value = element.slice(0, -1);
const postfix = element[element.length - 1];
const integerValue = parseInt(value, 10);
const floatValue = parseFloat(value);
const integerValue = Number.parseInt(value, 10);
const floatValue = Number.parseFloat(value);

if (postfix === 'w' && integerRegex.test(value)) {
if (integerValue <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "srcset",
"version": "2.0.1",
"description": "Parse and stringify the HTML <img> srcset attribute",
"description": "Parse and stringify the HTML `<img>` srcset attribute",
"license": "MIT",
"repository": "sindresorhus/srcset",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -33,8 +34,8 @@
"element"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.32.1"
}
}
8 changes: 2 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# srcset [![Build Status](https://travis-ci.org/sindresorhus/srcset.svg?branch=master)](https://travis-ci.org/sindresorhus/srcset)
# srcset [![Build Status](https://travis-ci.com/sindresorhus/srcset.svg?branch=master)](https://travis-ci.com/github/sindresorhus/srcset)

> Parse and stringify the HTML `<img>` [srcset](https://www.smashingmagazine.com/2013/08/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
Useful if you're creating a polyfill, build-tool, etc.

Can be useful if you're creating a build-tool.

## Install

```
$ npm install srcset
```


## Usage

How an image with `srcset` might look like:
Expand Down Expand Up @@ -55,7 +53,6 @@ banner-HD.jpg 2x, banner-phone.jpg 100w, banner-phone-HD.jpg 100w 2x
*/
```


## API

### .parse()
Expand All @@ -66,7 +63,6 @@ Accepts a srcset string and returns an array of objects with the possible proper

Accepts an array of objects with the possible properties: `url` (required), `width`, `density` and returns a srcset string.


---

<div align="center">
Expand Down
18 changes: 13 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ test('.parse() should parse srcset', t => {
]);
});

test('.parse() should not parse srcset', t => {
t.throws(() => srcset.parse('banner-phone-HD.jpeg 100w 2x'));
t.throws(() => srcset.parse('banner-phone-HD.jpeg -100w'));
t.throws(() => srcset.parse('banner-phone-HD.jpeg -2x'));
test('.parse() should not parse invalid srcset', t => {
t.throws(() => {
srcset.parse('banner-phone-HD.jpeg 100w 2x');
});

t.throws(() => {
srcset.parse('banner-phone-HD.jpeg -100w');
});

t.throws(() => {
srcset.parse('banner-phone-HD.jpeg -2x');
});
});

test('.stringify() should stringify srcset', t => {
Expand All @@ -24,7 +32,7 @@ test('.stringify() should stringify srcset', t => {
{url: 'banner-phone.jpeg', width: 100}
];

t.deepEqual(
t.is(
srcset.stringify(fixture),
'banner-HD.jpeg 2x, banner-phone.jpeg 100w'
);
Expand Down

0 comments on commit cece967

Please sign in to comment.