-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
88e1879
commit 8a5561c
Showing
24 changed files
with
318 additions
and
350 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.