Skip to content

Commit

Permalink
Require Node.js 12.20 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 21, 2021
1 parent 88e1879 commit 8a5561c
Show file tree
Hide file tree
Showing 24 changed files with 318 additions and 350 deletions.
18 changes: 0 additions & 18 deletions appveyor.yml

This file was deleted.

154 changes: 67 additions & 87 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,96 @@
declare namespace wallpaper {
interface GetOptions {
/**
__macOS only.__
export interface GetOptions {
/**
__macOS only.__
The screen to get the wallpaper from.
The screen to get the wallpaper from.
Values: `all`, `main`, or the index of a screen from `.screens()`.
Values: `all`, `main`, or the index of a screen from `.screens()`.
@default 'main'
*/
readonly screen?: 'all' | 'main' | number;
}
@default 'main'
*/
readonly screen?: 'all' | 'main' | number;
}

interface SetOptions {
/**
__macOS only.__
export interface SetOptions {
/**
__macOS only.__
The screen to set the wallpaper on.
The screen to set the wallpaper on.
Values: `all`, `main`, or the index of a screen from `.screens()`.
Values: `all`, `main`, or the index of a screen from `.screens()`.
*On Linux and Windows it's hard-coded to `main`.*
*On Linux and Windows it's hard-coded to `main`.*
@default 'all'
*/
readonly screen?: 'all' | 'main' | number;
@default 'all'
*/
readonly screen?: 'all' | 'main' | number;

/**
__macOS only.__
/**
__macOS only.__
Scaling method. Values: `auto` `fill` `fit` `stretch` `center`.
Scaling method. Values: `auto` `fill` `fit` `stretch` `center`.
@default 'auto'
*/
readonly scale?: 'auto' | 'fill' | 'fit' | 'stretch' | 'center';
}
@default 'auto'
*/
readonly scale?: 'auto' | 'fill' | 'fit' | 'stretch' | 'center';
}

// eslint-disable-next-line no-redeclare
declare const wallpaper: {
// TODO: remove this in the next major version
// when removed, each of the methods in this interface can be refactored to an explicit function export
// and `wallpaper` namespace may be removed completely along with the `export = wallpaper` export.
default: typeof wallpaper;

/**
Get the path to the wallpaper image currently set.
/**
Get the path to the wallpaper image currently set.
@returns The path of the current desktop wallpaper.
@returns The path of the current desktop wallpaper.
@example
```
import wallpaper = require('wallpaper');
@example
```
import {getWallpaper} from 'wallpaper';
(async () => {
await wallpaper.get();
//=> '/Users/sindresorhus/unicorn.jpg'
})();
```
*/
get(options?: wallpaper.GetOptions): Promise<string>;
await getWallpaper();
//=> '/Users/sindresorhus/unicorn.jpg'
```
*/
export function getWallpaper(options?: GetOptions): Promise<string>;

/**
Set a new wallpaper.
/**
Set a new wallpaper.
@param imagePath - The path to the image to set as the desktop wallpaper.
@param imagePath - The path to the image to set as the desktop wallpaper.
@example
```
import wallpaper = require('wallpaper');
@example
```
import {setWallpaper} from 'wallpaper';
(async () => {
await wallpaper.set('unicorn.jpg');
})();
```
*/
set(imagePath: string, options?: wallpaper.SetOptions): Promise<void>;
await setWallpaper('unicorn.jpg');
```
*/
export function setWallpaper(imagePath: string, options?: SetOptions): Promise<void>;

/**
__macOS only.__
/**
__macOS only.__
@returns The available screens.
@returns The available screens.
@example
```
import wallpaper from 'wallpaper';
@example
```
import {screens} from 'wallpaper';
(async () => {
await wallpaper.screens();
//=> ['Color LCD']
})();
```
*/
screens?(): Promise<string[]>;
await screens();
//=> ['Color LCD']
```
*/
export function screens(): Promise<string[]>;

/**
__macOS only.__
/**
__macOS only.__
Set a solid color.
Set a solid color.
@param color - The color to set as a RGB Hex value. For example, `000000` for black.
@param color - The color to set as a RGB Hex value. For example, `000000` for black.
@example
```
import wallpaper from 'wallpaper';
(async () => {
await wallpaper.setSolidColor('000000');
})();
```
*/
setSolidColor?(rgbHexColor: string, options?: wallpaper.SetOptions): Promise<void>;
};
@example
```
import {setSolidColorWallpaper} from 'wallpaper';
export = wallpaper;
await setSolidColorWallpaper('000000');
```
*/
export function setSolidColorWallpaper(rgbHexColor: string, options?: SetOptions): Promise<void>;
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';
import process from 'node:process';
import * as macos from './source/macos.js';
import * as linux from './source/linux/index.js';
import * as windows from './source/windows.js';

let wallpaper;
if (process.platform === 'darwin') {
wallpaper = require('./source/macos.js');
wallpaper = macos;
} else if (process.platform === 'win32') {
wallpaper = require('./source/windows.js');
wallpaper = windows;
} else {
wallpaper = require('./source/linux/index.js');
wallpaper = linux;
}

module.exports = wallpaper;
// TODO: remove this in the next major version
module.exports.default = wallpaper;
export const {getWallpaper, setWallpaper, setSolidColorWallpaper, screens} = wallpaper;
32 changes: 16 additions & 16 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {expectType} from 'tsd';
import wallpaper = require('.');
import {getWallpaper, setWallpaper, screens} from './index.js';

expectType<Promise<string>>(wallpaper.get());
expectType<Promise<string>>(wallpaper.get({screen: 'all'}));
expectType<Promise<string>>(wallpaper.get({screen: 'main'}));
expectType<Promise<string>>(wallpaper.get({screen: 0}));
expectType<Promise<string>>(getWallpaper());
expectType<Promise<string>>(getWallpaper({screen: 'all'}));
expectType<Promise<string>>(getWallpaper({screen: 'main'}));
expectType<Promise<string>>(getWallpaper({screen: 0}));

expectType<Promise<void>>(wallpaper.set('unicorn.jpg'));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {screen: 'all'}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {screen: 'main'}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {screen: 0}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {scale: 'auto'}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {scale: 'fill'}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {scale: 'fit'}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {scale: 'stretch'}));
expectType<Promise<void>>(wallpaper.set('unicorn.jpg', {scale: 'center'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg'));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {screen: 'all'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {screen: 'main'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {screen: 0}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {scale: 'auto'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {scale: 'fill'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {scale: 'fit'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {scale: 'stretch'}));
expectType<Promise<void>>(setWallpaper('unicorn.jpg', {scale: 'center'}));

if (wallpaper.screens) {
expectType<Promise<string[]>>(wallpaper.screens());
if (screens) {
expectType<Promise<string[]>>(screens());
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"email": "[email protected]",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -32,9 +34,9 @@
"photo"
],
"devDependencies": {
"ava": "^2.1.0",
"tsd": "^0.15.1",
"xo": "^0.39.0"
"ava": "^3.15.0",
"tsd": "^0.19.0",
"xo": "^0.46.4"
},
"ava": {
"serial": true
Expand Down
50 changes: 24 additions & 26 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ Works on macOS 10.14.4+, Linux, and Windows 10+.

## Install

```
$ npm install wallpaper
```sh
npm install wallpaper
```

## Usage

```js
const wallpaper = require('wallpaper');
import {getWallpaper, setWallpaper} from 'wallpaper';

(async () => {
await wallpaper.set('unicorn.jpg');
await setWallpaper('unicorn.jpg');

await wallpaper.get();
//=> '/Users/sindresorhus/unicorn.jpg'
})();
await getWallpaper();
//=> '/Users/sindresorhus/unicorn.jpg'
```

## API

### .get(options?)
### getWallpaper(options?)

Returns a `Promise<string>` with the path of the current desktop wallpaper.

Expand All @@ -43,9 +41,9 @@ Default: `'main'`

The screen to get the wallpaper from.

If you set `'all'` then `.get()` will return a `Promise<string[]>`.
If you set `'all'` then `getWallpaper()` will return a `Promise<string[]>`.

### .set(imagePath, options?)
### setWallpaper(imagePath, options?)

Returns a `Promise`.

Expand Down Expand Up @@ -77,18 +75,7 @@ Default: `'auto'`

Scaling method.

### .screens() *(macOS only)*

Returns a `Promise<string[]>` with the available screens.

```js
(async () => {
await wallpaper.screens();
//=> ['Color LCD']
})();
```

### .setSolidColor(color, options?) *(macOS only)*
### setSolidColorWallpaper(color, options?) *(macOS only)*

Returns a `Promise`.

Expand All @@ -111,9 +98,20 @@ Default: `'all'`
The screen to set the wallpaper on.

```js
(async () => {
await wallpaper.setSolidColor('000000');
})();
import {setSolidColorWallpaper} from 'wallpaper';

await setSolidColorWallpaper('000000');
```

### screens() *(macOS only)*

Returns a `Promise<string[]>` with the available screens.

```js
import {screens} from 'wallpaper';

await screens();
//=> ['Color LCD']
```

## FAQ
Expand Down
Loading

0 comments on commit 8a5561c

Please sign in to comment.