Comparing version 3.1.0 to 4.0.0
/** | ||
Create a lazy promise that defers execution until it's awaited or when `.then()` or `.catch()` is called. | ||
*/ | ||
declare class PLazy<ValueType> extends Promise<ValueType> { | ||
export default class PLazy<ValueType> extends Promise<ValueType> { | ||
/** | ||
@@ -10,3 +10,3 @@ Create a `PLazy` promise from a promise-returning or async function. | ||
``` | ||
import PLazy = require('p-lazy'); | ||
import PLazy from 'p-lazy'; | ||
@@ -19,14 +19,9 @@ const lazyPromise = new PLazy(resolve => { | ||
(async () => { | ||
await doSomethingFun; | ||
// `someHeavyOperation` is called | ||
console.log(await lazyPromise); | ||
})(); | ||
await doSomethingFun; | ||
// `someHeavyOperation` is called | ||
console.log(await lazyPromise); | ||
``` | ||
*/ | ||
static from<ValueType>( | ||
fn: () => ValueType | PromiseLike<ValueType> | ||
): PLazy<ValueType>; | ||
static from<ValueType>(function_: () => ValueType | PromiseLike<ValueType>): PLazy<ValueType>; | ||
} | ||
export = PLazy; |
10
index.js
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
// TODO: Use private class fields when ESLint support it. | ||
class PLazy extends Promise { | ||
export default class PLazy extends Promise { | ||
constructor(executor) { | ||
@@ -12,5 +12,5 @@ super(resolve => { | ||
static from(fn) { | ||
static from(function_) { | ||
return new PLazy(resolve => { | ||
resolve(fn()); | ||
resolve(function_()); | ||
}); | ||
@@ -42,3 +42,1 @@ } | ||
} | ||
module.exports = PLazy; |
{ | ||
"name": "p-lazy", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Create a lazy promise that defers execution until it's awaited or when `.then()` or `.catch()` is called", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-lazy", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -37,7 +40,7 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"delay": "^5.0.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -7,3 +7,2 @@ # p-lazy | ||
## Install | ||
@@ -15,7 +14,6 @@ | ||
## Usage | ||
```js | ||
const PLazy = require('p-lazy'); | ||
import PLazy from 'p-lazy'; | ||
@@ -28,10 +26,8 @@ const lazyPromise = new PLazy(resolve => { | ||
(async () => { | ||
await doSomethingFun; | ||
// `someHeavyOperation` is called | ||
console.log(await lazyPromise); | ||
})(); | ||
await doSomethingFun; | ||
// `someHeavyOperation` is called | ||
console.log(await lazyPromise); | ||
``` | ||
## API | ||
@@ -55,3 +51,2 @@ | ||
## Related | ||
@@ -64,6 +59,1 @@ | ||
- [More…](https://github.com/sindresorhus/promise-fun) | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4907
Yes
53
55