From 67e927bdb621e5a7254e2c971670c43ee76fe102 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 29 Aug 2023 11:16:18 +0100 Subject: [PATCH] Docs: ensure all functions include method signature #3777 --- docs/api-channel.md | 10 ++++++++++ docs/api-colour.md | 14 +++++++++++++ docs/api-composite.md | 2 ++ docs/api-constructor.md | 6 ++++++ docs/api-input.md | 4 ++++ docs/api-operation.md | 40 ++++++++++++++++++++++++++++++++++++++ docs/api-output.md | 32 ++++++++++++++++++++++++++++++ docs/api-resize.md | 8 ++++++++ docs/api-utility.md | 22 +++++++++++++++++++++ docs/build.js | 2 +- docs/search-index/build.js | 2 +- 11 files changed, 140 insertions(+), 2 deletions(-) diff --git a/docs/api-channel.md b/docs/api-channel.md index 7e50b817c..bd751d4d2 100644 --- a/docs/api-channel.md +++ b/docs/api-channel.md @@ -1,4 +1,6 @@ ## removeAlpha +> removeAlpha() ⇒ Sharp + Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel. See also [flatten](/api-operation#flatten). @@ -15,6 +17,8 @@ sharp('rgba.png') ## ensureAlpha +> ensureAlpha([alpha]) ⇒ Sharp + Ensure the output image has an alpha transparency channel. If missing, the added alpha channel will have the specified transparency level, defaulting to fully-opaque (1). @@ -48,6 +52,8 @@ const rgba = await sharp(rgb) ## extractChannel +> extractChannel(channel) ⇒ Sharp + Extract a single channel from a multi-channel image. @@ -78,6 +84,8 @@ const [red1, red2, ...] = await sharp(input) ## joinChannel +> joinChannel(images, options) ⇒ Sharp + Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with `toColourspace()`. By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels. @@ -102,6 +110,8 @@ For raw pixel input, the `options` object should contain a `raw` attribute, whic ## bandbool +> bandbool(boolOp) ⇒ Sharp + Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image. diff --git a/docs/api-colour.md b/docs/api-colour.md index 87af7e2ec..e3847c8eb 100644 --- a/docs/api-colour.md +++ b/docs/api-colour.md @@ -1,4 +1,6 @@ ## tint +> tint(rgb) ⇒ Sharp + Tint the image using the provided chroma while preserving the image luminance. An alpha channel may be present and will be unchanged by the operation. @@ -21,6 +23,8 @@ const output = await sharp(input) ## greyscale +> greyscale([greyscale]) ⇒ Sharp + Convert to 8-bit greyscale; 256 shades of grey. This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results. By default the output image will be web-friendly sRGB and contain three (identical) color channels. @@ -41,6 +45,8 @@ const output = await sharp(input).greyscale().toBuffer(); ## grayscale +> grayscale([grayscale]) ⇒ Sharp + Alternative spelling of `greyscale`. @@ -52,6 +58,8 @@ Alternative spelling of `greyscale`. ## pipelineColourspace +> pipelineColourspace([colourspace]) ⇒ Sharp + Set the pipeline colourspace. The input image will be converted to the provided colourspace at the start of the pipeline. @@ -82,6 +90,8 @@ await sharp(input) ## pipelineColorspace +> pipelineColorspace([colorspace]) ⇒ Sharp + Alternative spelling of `pipelineColourspace`. @@ -97,6 +107,8 @@ Alternative spelling of `pipelineColourspace`. ## toColourspace +> toColourspace([colourspace]) ⇒ Sharp + Set the output colourspace. By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels. @@ -120,6 +132,8 @@ await sharp(input) ## toColorspace +> toColorspace([colorspace]) ⇒ Sharp + Alternative spelling of `toColourspace`. diff --git a/docs/api-composite.md b/docs/api-composite.md index 2eb15de90..40062ebed 100644 --- a/docs/api-composite.md +++ b/docs/api-composite.md @@ -1,4 +1,6 @@ ## composite +> composite(images) ⇒ Sharp + Composite image(s) over the processed (resized, extracted etc.) image. The images to composite must be the same size or smaller than the processed image. diff --git a/docs/api-constructor.md b/docs/api-constructor.md index e8538855a..7b6d94e8f 100644 --- a/docs/api-constructor.md +++ b/docs/api-constructor.md @@ -1,9 +1,13 @@ ## Sharp +> Sharp + **Emits**: Sharp#event:info, Sharp#event:warning ### new +> new Sharp([input], [options]) + Constructor factory to create an instance of `sharp`, to which further methods are chained. JPEG, PNG, WebP, GIF, AVIF or TIFF format image data can be streamed out from this object. @@ -159,6 +163,8 @@ await sharp({ ## clone +> clone() ⇒ [Sharp](#Sharp) + Take a "snapshot" of the Sharp instance, returning a new instance. Cloned instances inherit the input of their parent instance. This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream. diff --git a/docs/api-input.md b/docs/api-input.md index b720bd14e..70b4fa75b 100644 --- a/docs/api-input.md +++ b/docs/api-input.md @@ -1,4 +1,6 @@ ## metadata +> metadata([callback]) ⇒ Promise.<Object> \| Sharp + Fast access to (uncached) image metadata without decoding any compressed pixel data. This is read from the header of the input image. @@ -81,6 +83,8 @@ function getNormalSize({ width, height, orientation }) { ## stats +> stats([callback]) ⇒ Promise.<Object> + Access to pixel-derived image statistics for every channel in the image. A `Promise` is returned when `callback` is not provided. diff --git a/docs/api-operation.md b/docs/api-operation.md index 418745533..768697f91 100644 --- a/docs/api-operation.md +++ b/docs/api-operation.md @@ -1,4 +1,6 @@ ## rotate +> rotate([angle], [options]) ⇒ Sharp + Rotate the output image by either an explicit angle or auto-orient based on the EXIF `Orientation` tag. @@ -57,6 +59,8 @@ const resizeThenRotate = await sharp(input) ## flip +> flip([flip]) ⇒ Sharp + Mirror the image vertically (up-down) about the x-axis. This always occurs before rotation, if any. @@ -75,6 +79,8 @@ const output = await sharp(input).flip().toBuffer(); ## flop +> flop([flop]) ⇒ Sharp + Mirror the image horizontally (left-right) about the y-axis. This always occurs before rotation, if any. @@ -91,6 +97,8 @@ const output = await sharp(input).flop().toBuffer(); ## affine +> affine(matrix, [options]) ⇒ Sharp + Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any. You must provide an array of length 4 or a 2x2 affine transformation matrix. @@ -142,6 +150,8 @@ inputStream ## sharpen +> sharpen([options], [flat], [jagged]) ⇒ Sharp + Sharpen the image. When used without parameters, performs a fast, mild sharpen of the output image. @@ -193,6 +203,8 @@ const data = await sharp(input) ## median +> median([size]) ⇒ Sharp + Apply median filter. When used without parameters the default window is 3x3. @@ -217,6 +229,8 @@ const output = await sharp(input).median(5).toBuffer(); ## blur +> blur([sigma]) ⇒ Sharp + Blur the image. When used without parameters, performs a fast 3x3 box blur (equivalent to a box linear filter). @@ -248,6 +262,8 @@ const gaussianBlurred = await sharp(input) ## flatten +> flatten([options]) ⇒ Sharp + Merge alpha transparency channel, if any, with a background, then remove the alpha channel. See also [removeAlpha](/api-channel#removealpha). @@ -268,6 +284,8 @@ await sharp(rgbaInput) ## unflatten +> unflatten() + Ensure the image has an alpha channel with all white pixel values made fully transparent. @@ -293,6 +311,8 @@ await sharp(rgbInput) ## gamma +> gamma([gamma], [gammaOut]) ⇒ Sharp + Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma` then increasing the encoding (brighten) post-resize at a factor of `gamma`. This can improve the perceived brightness of a resized image in non-linear colour spaces. @@ -315,6 +335,8 @@ Supply a second argument to use a different output gamma value, otherwise the fi ## negate +> negate([options]) ⇒ Sharp + Produce the "negative" of the image. @@ -339,6 +361,8 @@ const output = await sharp(input) ## normalise +> normalise([options]) ⇒ Sharp + Enhance output image contrast by stretching its luminance to cover a full dynamic range. Uses a histogram-based approach, taking a default range of 1% to 99% to reduce sensitivity to noise at the extremes. @@ -369,6 +393,8 @@ const output = await sharp(input) ## normalize +> normalize([options]) ⇒ Sharp + Alternative spelling of normalise. @@ -388,6 +414,8 @@ const output = await sharp(input) ## clahe +> clahe(options) ⇒ Sharp + Perform contrast limiting adaptive histogram equalization [CLAHE](https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE). @@ -419,6 +447,8 @@ const output = await sharp(input) ## convolve +> convolve(kernel) ⇒ Sharp + Convolve the image with the specified kernel. @@ -453,6 +483,8 @@ sharp(input) ## threshold +> threshold([threshold], [options]) ⇒ Sharp + Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0. @@ -471,6 +503,8 @@ Any pixel value greater than or equal to the threshold value will be set to 255, ## boolean +> boolean(operand, operator, [options]) ⇒ Sharp + Perform a bitwise boolean operation with operand image. This operation creates an output image where each pixel is the result of @@ -495,6 +529,8 @@ the selected bitwise boolean `operation` between the corresponding pixels of the ## linear +> linear([a], [b]) ⇒ Sharp + Apply the linear formula `a` * input + `b` to the image to adjust image levels. When a single number is provided, it will be used for all image channels. @@ -529,6 +565,8 @@ await sharp(rgbInput) ## recomb +> recomb(inputMatrix) ⇒ Sharp + Recombine the image with the specified matrix. @@ -559,6 +597,8 @@ sharp(input) ## modulate +> modulate([options]) ⇒ Sharp + Transforms the image using brightness, saturation, hue rotation, and lightness. Brightness and lightness both operate on luminance, with the difference being that brightness is multiplicative whereas lightness is additive. diff --git a/docs/api-output.md b/docs/api-output.md index cc00ada54..7610a8e63 100644 --- a/docs/api-output.md +++ b/docs/api-output.md @@ -1,4 +1,6 @@ ## toFile +> toFile(fileOut, [callback]) ⇒ Promise.<Object> + Write output image data to a file. If an explicit output format is not selected, it will be inferred from the extension, @@ -39,6 +41,8 @@ sharp(input) ## toBuffer +> toBuffer([options], [callback]) ⇒ Promise.<Buffer> + Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported. @@ -108,6 +112,8 @@ await sharp(pixelArray, { raw: { width, height, channels } }) ## withMetadata +> withMetadata([options]) ⇒ Sharp + Include all metadata (EXIF, XMP, IPTC) from the input image in the output image. This will also convert to and add a web-friendly sRGB ICC profile if appropriate, unless a custom output profile is provided. @@ -167,6 +173,8 @@ const data = await sharp(input) ## toFormat +> toFormat(format, options) ⇒ Sharp + Force output to a given format. @@ -190,6 +198,8 @@ const data = await sharp(input) ## jpeg +> jpeg([options]) ⇒ Sharp + Use these JPEG options for output image. @@ -235,6 +245,8 @@ const data = await sharp(input) ## png +> png([options]) ⇒ Sharp + Use these PNG options for output image. By default, PNG output is full colour at 8 or 16 bits per pixel. @@ -278,6 +290,8 @@ const data = await sharp(input) ## webp +> webp([options]) ⇒ Sharp + Use these WebP options for output image. @@ -319,6 +333,8 @@ const outputWebp = await sharp(inputWebp, { animated: true }) ## gif +> gif([options]) ⇒ Sharp + Use these GIF options for the output image. The first entry in the palette is reserved for transparency. @@ -378,6 +394,8 @@ await sharp('in.gif', { animated: true }) ## jp2 +> jp2([options]) ⇒ Sharp + Use these JP2 options for output image. Requires libvips compiled with support for OpenJPEG. @@ -420,6 +438,8 @@ const data = await sharp(input) ## tiff +> tiff([options]) ⇒ Sharp + Use these TIFF options for output image. The `density` can be set in pixels/inch via [withMetadata](#withmetadata) @@ -461,6 +481,8 @@ sharp('input.svg') ## avif +> avif([options]) ⇒ Sharp + Use these AVIF options for output image. Whilst it is possible to create AVIF images smaller than 16x16 pixels, @@ -498,6 +520,8 @@ const data = await sharp(input) ## heif +> heif([options]) ⇒ Sharp + Use these HEIF options for output image. Support for patent-encumbered HEIC images using `hevc` compression requires the use of a @@ -528,6 +552,8 @@ const data = await sharp(input) ## jxl +> jxl([options]) ⇒ Sharp + Use these JPEG-XL (JXL) options for output image. This feature is experimental, please do not use in production systems. @@ -557,6 +583,8 @@ Image metadata (EXIF, XMP) is unsupported. ## raw +> raw([options]) + Force output to be raw, uncompressed pixel data. Pixel ordering is left-to-right, top-to-bottom, without padding. Channel ordering will be RGB or RGBA for non-greyscale colourspaces. @@ -592,6 +620,8 @@ const data = await sharp('input.png') ## tile +> tile([options]) ⇒ Sharp + Use tile-based deep zoom (image pyramid) output. Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions. @@ -653,6 +683,8 @@ readableStream ## timeout +> timeout(options) ⇒ Sharp + Set a timeout for processing, in seconds. Use a value of zero to continue processing indefinitely, the default behaviour. diff --git a/docs/api-resize.md b/docs/api-resize.md index a8caca9d0..e95ea3151 100644 --- a/docs/api-resize.md +++ b/docs/api-resize.md @@ -1,4 +1,6 @@ ## resize +> resize([width], [height], [options]) ⇒ Sharp + Resize image to `width`, `height` or `width x height`. When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are: @@ -146,6 +148,8 @@ const scaleByHalf = await sharp(input) ## extend +> extend(extend) ⇒ Sharp + Extend / pad / extrude one or more edges of the image with either the provided background colour or pixels derived from the image. This operation will always occur after resizing and extraction, if any. @@ -204,6 +208,8 @@ sharp(input) ## extract +> extract(options) ⇒ Sharp + Extract/crop a region of the image. - Use `extract` before `resize` for pre-resize extraction. @@ -245,6 +251,8 @@ sharp(input) ## trim +> trim(trim) ⇒ Sharp + Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel. Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels. diff --git a/docs/api-utility.md b/docs/api-utility.md index 43abb068b..a4d2e7430 100644 --- a/docs/api-utility.md +++ b/docs/api-utility.md @@ -1,4 +1,6 @@ ## versions +> versions + An Object containing the version numbers of sharp, libvips and its dependencies. @@ -9,6 +11,8 @@ console.log(sharp.versions); ## interpolators +> interpolators : enum + An Object containing the available interpolators and their proper values @@ -27,6 +31,8 @@ An Object containing the available interpolators and their proper values ## format +> format ⇒ Object + An Object containing nested boolean values representing the available input and output formats/methods. @@ -37,6 +43,8 @@ console.log(sharp.format); ## vendor +> vendor + An Object containing the platform and architecture of the current and installed vendored binaries. @@ -48,6 +56,8 @@ console.log(sharp.vendor); ## queue +> queue + An EventEmitter that emits a `change` event when a task is either: - queued, waiting for _libuv_ to provide a worker thread - complete @@ -62,6 +72,8 @@ sharp.queue.on('change', function(queueLength) { ## cache +> cache([options]) ⇒ Object + Gets or, when options are provided, sets the limits of _libvips'_ operation cache. Existing entries in the cache will be trimmed after any change in limits. This method always returns cache statistics, @@ -89,6 +101,8 @@ sharp.cache(false); ## concurrency +> concurrency([concurrency]) ⇒ number + Gets or, when a concurrency is provided, sets the maximum number of threads _libvips_ should use to process _each image_. These are from a thread pool managed by glib, @@ -132,6 +146,8 @@ sharp.concurrency(0); // 4 ## counters +> counters() ⇒ Object + Provides access to internal task counters. - queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool. - process is the number of resize tasks currently being processed. @@ -144,6 +160,8 @@ const counters = sharp.counters(); // { queue: 2, process: 4 } ## simd +> simd([simd]) ⇒ boolean + Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support. @@ -169,6 +187,8 @@ const simd = sharp.simd(false); ## block +> block(options) + Block libvips operations at runtime. This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable, @@ -191,6 +211,8 @@ sharp.block({ ## unblock +> unblock(options) + Unblock libvips operations at runtime. This is useful for defining a list of allowed operations. diff --git a/docs/build.js b/docs/build.js index dba31c2e7..de08b65de 100644 --- a/docs/build.js +++ b/docs/build.js @@ -29,7 +29,7 @@ const jsdoc2md = require('jsdoc-to-markdown'); }); const cleanMarkdown = markdown - .replace(/(## [A-Za-z0-9]+)[^\n]*/g, '$1') // simplify headings to match those of documentationjs, ensures existing URLs work + .replace(/(## )([A-Za-z0-9]+)([^\n]*)/g, '$1$2\n> $2$3\n') // simplify headings to match those of documentationjs, ensures existing URLs work .replace(/<\/a>/g, '') // remove anchors, let docute add these (at markdown to HTML render time) .replace(/\*\*Kind\*\*: global[^\n]+/g, '') // remove all "global" Kind labels (requires JSDoc refactoring) .trim(); diff --git a/docs/search-index/build.js b/docs/search-index/build.js index 120b5fa3b..67df86d23 100644 --- a/docs/search-index/build.js +++ b/docs/search-index/build.js @@ -40,7 +40,7 @@ for (const match of matches) { ].forEach((section) => { const contents = fs.readFileSync(path.join(__dirname, '..', `api-${section}.md`), 'utf8'); const matches = contents.matchAll( - /## (?[A-Za-z]+)\n(?<firstparagraph>.+?)\n\n.+?(?<parameters>\| Param .+?\n\n)?\*\*Example/gs + /## (?<title>[A-Za-z]+)\n[^\n]+\n(?<firstparagraph>.+?)\n\n.+?(?<parameters>\| Param .+?\n\n)?\*\*Example/gs ); for (const match of matches) { const { title, firstparagraph, parameters } = match.groups;