Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2023-07-13 09:09:17 +00:00
parent 4fad06f438
commit 40a500c743
4168 changed files with 298222 additions and 374905 deletions

View file

@ -1,33 +1,31 @@
/**
Define a [lazily evaluated](https://en.wikipedia.org/wiki/Lazy_evaluation) property on an object.
@param object - Object to add property to.
@param object - Object to add the property to.
@param propertyName - Name of the property to add.
@param fn - Called the first time `propertyName` is accessed.
@param valueGetter - Called the first time `propertyName` is accessed.
@example
```
import defineLazyProp = require('define-lazy-prop');
import defineLazyProperty from 'define-lazy-prop';
const unicorn = {
// …
};
defineLazyProp(unicorn, 'rainbow', () => expensiveComputation());
defineLazyProperty(unicorn, 'rainbow', () => expensiveComputation());
app.on('user-action', () => {
doSomething(unicorn.rainbow);
});
```
*/
declare function defineLazyProp<
ObjectType extends {[key: string]: unknown},
export default function defineLazyProperty<
ObjectType extends Record<string, any>,
PropertyNameType extends string,
PropertyValueType
>(
object: ObjectType,
propertyName: PropertyNameType,
fn: () => PropertyValueType
valueGetter: () => PropertyValueType
): ObjectType & {[K in PropertyNameType]: PropertyValueType};
export = defineLazyProp;

View file

@ -1,12 +1,11 @@
'use strict';
module.exports = (object, propertyName, fn) => {
export default function defineLazyProperty(object, propertyName, valueGetter) {
const define = value => Object.defineProperty(object, propertyName, {value, enumerable: true, writable: true});
Object.defineProperty(object, propertyName, {
configurable: true,
enumerable: true,
get() {
const result = fn();
const result = valueGetter();
define(result);
return result;
},
@ -16,4 +15,4 @@ module.exports = (object, propertyName, fn) => {
});
return object;
};
}

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:

View file

@ -1,16 +1,19 @@
{
"name": "define-lazy-prop",
"version": "2.0.0",
"version": "3.0.0",
"description": "Define a lazily evaluated property on an object",
"license": "MIT",
"repository": "sindresorhus/define-lazy-prop",
"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"
},
"scripts": {
"test": "xo && ava && tsd"
@ -41,8 +44,8 @@
"deferred"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

View file

@ -1,43 +1,40 @@
# define-lazy-prop [![Build Status](https://travis-ci.org/sindresorhus/define-lazy-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/define-lazy-prop)
# define-lazy-prop
> Define a [lazily evaluated](https://en.wikipedia.org/wiki/Lazy_evaluation) property on an object
Useful when the value of a property is expensive to generate, so you want to delay the computation until the property is needed. For example, improving startup performance by deferring nonessential operations.
## Install
```
$ npm install define-lazy-prop
```
## Usage
```js
const defineLazyProp = require('define-lazy-prop');
import defineLazyProperty from 'define-lazy-prop';
const unicorn = {
// …
};
defineLazyProp(unicorn, 'rainbow', () => expensiveComputation());
defineLazyProperty(unicorn, 'rainbow', () => expensiveComputation());
app.on('user-action', () => {
doSomething(unicorn.rainbow);
});
```
## API
### defineLazyProp(object, propertyName, fn)
### defineLazyProperty(object, propertyName, valueGetter)
#### object
Type: `Object`
Type: `object`
Object to add property to.
Object to add the property to.
#### propertyName
@ -45,20 +42,14 @@ Type: `string`
Name of the property to add.
#### fn
#### valueGetter
Type: `Function`
Called the first time `propertyName` is accessed. Expected to return a value.
## Related
- [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value
- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily
- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)