4.14.0 • Published 9 days ago

gatsby-core-utils v4.14.0

Weekly downloads
729,276
License
MIT
Repository
github
Last release
9 days ago

gatsby-core-utils

Utilities used in multiple Gatsby packages.

Usage

npm install gatsby-core-utils

createContentDigest

Encrypts an input using md5 hash of hexadecimal digest.

const { createContentDigest } = require("gatsby-core-utils")

const options = {
  key: "value",
  foo: "bar",
}

const digest = createContentDigest(options)
// ...

cpuCoreCount

Calculate the number of CPU cores on the current machine

This function can be controlled by an env variable GATSBY_CPU_COUNT setting the first argument to true.

valuedescription
Counts amount of real cores by running a shell command
logical_coresrequire("os").cpus() to count all virtual cores
any numberSets cpu count to that specific number
const { cpuCoreCount } = require("gatsby-core-utils")

const coreCount = cpuCoreCount(false)
// ...
const { cpuCoreCount } = require("gatsby-core-utils")
process.env.GATSBY_CPU_COUNT = "logical_cores"

const coreCount = cpuCoreCount()
// ...

joinPath

A utility that joins paths with a / on windows and unix-type platforms. This can also be used for URL concatenation.

const { joinPath } = require("gatsby-core-utils")

const BASEPATH = "/mybase/"
const pathname = "./gatsby/is/awesome"
const url = joinPath(BASEPATH, pathname)
// ...

isCI

A utility that enhances isCI from 'ci-info` with support for Vercel and Heroku detection

const { isCI } = require("gatsby-core-utils")

if (isCI()) {
  // execute CI-specific code
}
// ...

getCIName

A utility that returns the name of the current CI environment if available, null otherwise

const { getCIName } = require("gatsby-core-utils")

const CI_NAME = getCIName()
console.log({ CI_NAME })
// {CI_NAME: null}, or
// {CI_NAME: "Vercel"}
// ...

createRequireFromPath

A cross-version polyfill for Node's Module.createRequire.

const { createRequireFromPath } = require("gatsby-core-utils")

const requireUtil = createRequireFromPath("../src/utils/")

// Require `../src/utils/some-tool`
requireUtil("./some-tool")
// ...

Mutex

When working inside workers or async operations you want some kind of concurrency control that a specific work load can only concurrent one at a time. This is what a Mutex does.

By implementing the following code, the code is only executed one at a time and the other threads/async workloads are awaited until the current one is done. This is handy when writing to the same file to disk.

const { createMutex } = require("gatsby-core-utils/mutex")

const mutex = createMutex("my-custom-mutex-key")
await mutex.acquire()

await fs.writeFile("pathToFile", "my custom content")

await mutex.release()

Hashing

Parts of hash-wasm are re-exported from gatsby-core-utils or used in custom functions. When working on hashing where you'd normally use crypto from Node.js, you can use these functions instead. They especially show their advantage on large inputs so don't feel obliged to always use them. Refer to hash-wasm's documentation for more details on usage for the re-exported functions.

const { md5File, md5, createMD5, sha256, sha1 } = require("gatsby-core-utils")

// For md5, createMD5, sha256, sha1 refer to hash-wasm
await md5(`some-string`)

// md5File gives you the MD5 hex hash for a given filepath
await md5File(`package.json`)
gatsby-source-filesystem-frontmatter@studiobear/gatsby-theme-blog-ionicgatsby-plugin-wirehead-tree@stvad/gatsby-theme-garden@kennethwangdotdev/gatsby-theme-dotdevgatsby-remark-images-esgatsby-plugin-sharp-es@everything-registry/sub-chunk-1721gatsby-source-hygraph-cmsruairi-testsaashq-telemetry@ascorbic/create-test@ascorbic/gatsby@ascorbic/gatsby-plugin-netlify@ascorbic/gatsby-plugin-sharp@arcblock/gatsby-transformer-remark@agragregra/parcel-namer-beautify@alicloud/gatsby-plugin-mdx-fork@builder.io/gatsby@cieloazul310/gatsby-theme-aoi-blog-core@chesteralan/gatsby-source-graphql@7hci/gatsby-pge@bolt-app/babel-preset-gatsby@bongnv/gatsby-transformer-remark@bonobolabs/gatsby@devreltools/gatsbyjs-theme-team@fido.id/gatsby-source-workable@guanghechen/gatsby-yozora-images@gvrs/gatsby-transformer-blurhash@gvrs/gatsby-transformer-image-mask@gromy/gatsby-plugin-image@iansinnott/gatsby-source-notion-collection@gatsbyjs/gatsby-theme-website@gatsbyjs/parcel-namer-relative-to-cwd@gautham20/gatsby-plugin-sharp@infinitebrahmanuniverse/nolb-gatsby-c@lgenzelis/gatsby-plugin-sharp@lgenzelis/gatsby-transformer-remark@macko911/gatsby@magecom/gatsby-source-wordpress-experimental-fork-media-items-fix@m5r/gatsby-transformer-blurhash@mtdev/gatsby-theme-terminal@nickymeuleman/gatsby-theme-blog@dylanvann/gatsby@jamo/gatsby-telemetry@jeff-tian/gatsby-plugin-sharp@jeff-tian/gatsby-remark-images-remote@jeremybarbet/gatsby-cli@kabartolo/gatsby-theme-chicago-docs-core@preetjdp/gatsby-transformer-blurhash@rasahq/gatsby-transformer-remark-inline@prose/gatsby@progital/gatsby-source-filesystem@progital/gatsby-source-wordpress-experimental@redocly/gatsby-plugin-manifest@redocly/gatsby-plugin-sharp@redocly/gatsby-remark-images@rennehir/gatsby-theme-personal-site@stampany/gatsby-theme-instagram-basic@techberg/gatsby-source-yuque@phmu/gatsby-source-wordpress-experimental@nsuave/gatsby-theme-terminal@pixel-point/gatsby-source-wordpress@pixel-point/gatsby-source-wordpress-experimental@pkorsholm/gatsby-source-medusa@skok/gatsby-plugin-preload-fonts@synesthesia/gatsby-theme-garden@smithc/gatsby-source-contentful@tamsaunders/gatsby-transformer-remark@silencerweb/gatsby-source-wordpress-experimental@sidarthar/gatsby-plugin-image-2@zalastax/nolb-gatsby-c@dotdev/gatsby-source-sanity@docpocalypse/gatsby-theme-core@dseoane/gatsby-theme-blog-core@clue/gatsby-source-contentful@cs125/gatsby-source-filesystem-frontmatter@commercetools-docs/gatsby-theme-docs@cosmicjs/gatsby-source-cosmic@d3vd/gatsby-theme-code-notes@darkh0le/gatsby-theme-code-notes@throttleup/gatsby@throttleup/gatsby-source-wordpress@untitled-docs/gatsby-source-packages@trptcolin/gatsby-source-contentful@valschr/gatsby-source-shopify@undataforum/gatsby-theme-blog@undataforum/gatsby-theme-profilesbabel-plugin-remove-graphql-queriesbabel-preset-gatsbyerxes-telemetrygatsby-roamgatsby-plugin-cloudflare-pagesgatsby-plugin-fastifygatsby-plugin-fastify-accellgatsby-plugin-fastify-klyngengatsby-plugin-eufemia-theme-handlergatsby-recipesgatsby-source-filesystemgatsby-source-filesystem-fast
4.15.0-next.0

9 days ago

4.14.0

10 days ago

4.13.1

10 months ago

4.14.0-next.2

10 months ago

4.14.0-next.1

11 months ago

4.13.0

11 months ago

4.14.0-next.0

11 months ago

4.13.0-next.1

1 year ago

4.12.1

1 year ago

4.12.0

1 year ago

4.12.0-next.1

1 year ago

4.12.0-next.0

1 year ago

4.11.0-next.0

2 years ago

4.11.0-next.1

1 year ago

4.10.0

2 years ago

4.13.0-next.0

1 year ago

4.11.0

1 year ago

4.9.0

2 years ago

4.10.0-next.0

2 years ago

4.10.0-next.1

2 years ago

4.10.0-next.2

2 years ago

4.8.0

2 years ago

4.7.0

2 years ago

4.8.0-next.0

2 years ago

4.9.0-next.1

2 years ago

4.9.0-next.0

2 years ago

4.6.0-next.0

2 years ago

4.7.0-next.0

2 years ago

4.6.0

2 years ago

4.5.0-next.1

2 years ago

4.5.0

2 years ago

4.4.0

2 years ago

4.3.0-next.0

2 years ago

4.0.0

2 years ago

4.3.0-next.1

2 years ago

4.2.0-next.0

2 years ago

3.25.0

2 years ago

4.0.0-next.1

2 years ago

4.0.0-next.0

2 years ago

4.0.0-next.2

2 years ago

4.5.0-next.0

2 years ago

4.1.0-next.0

2 years ago

2.15.0

2 years ago

4.3.1

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

4.4.0-next.2

2 years ago

4.4.0-next.1

2 years ago

4.4.0-next.0

2 years ago

4.1.0

2 years ago

3.24.0

2 years ago

3.23.0-next.0

2 years ago

3.22.0

2 years ago

3.23.0

2 years ago

3.24.0-next.0

2 years ago

3.24.0-next.1

2 years ago

3.25.0-next.0

2 years ago

3.17.0-next.1

2 years ago

3.17.0-next.0

2 years ago

3.22.0-next.0

2 years ago

3.19.0

2 years ago

3.16.0-next.0

2 years ago

3.19.0-next.0

2 years ago

3.19.0-next.1

2 years ago

3.21.0-next.1

2 years ago

3.21.0-next.0

2 years ago

3.20.0

2 years ago

3.21.0-next.2

2 years ago

3.17.0

2 years ago

3.21.0

2 years ago

3.18.1

2 years ago

3.18.0

2 years ago

3.18.0-next.1

2 years ago

3.18.0-next.0

2 years ago

3.15.0

2 years ago

3.20.0-next.0

2 years ago

3.16.0

2 years ago

3.14.0

3 years ago

3.13.0

3 years ago

3.14.0-next.3

3 years ago

3.14.0-next.2

3 years ago

3.14.0-next.1

3 years ago

3.14.0-next.0

3 years ago

3.15.0-next.0

3 years ago

3.15.0-next.1

3 years ago

3.10.0-next.3

3 years ago

3.12.1

3 years ago

3.12.0

3 years ago

3.13.0-next.0

3 years ago

3.9.1

3 years ago

3.10.1

3 years ago

3.10.0

3 years ago

3.11.0-next.1

3 years ago

3.11.0-next.0

3 years ago

3.11.0

3 years ago

3.11.1

3 years ago

3.12.0-next.2

3 years ago

3.12.0-next.3

3 years ago

3.12.0-next.0

3 years ago

3.12.0-next.1

3 years ago

3.10.0-next.1

3 years ago

3.10.0-next.0

3 years ago

3.10.0-next.2

3 years ago

3.9.0

3 years ago

3.8.2

3 years ago

3.8.1

3 years ago

3.9.0-next.1

3 years ago

3.8.0-next.0

3 years ago

3.8.0-next.1

3 years ago

3.4.0-next.1

3 years ago

3.4.0-next.0

3 years ago

3.8.0

3 years ago

3.5.0-next.0

3 years ago

3.5.0-next.1

3 years ago

3.5.0-next.2

3 years ago

3.5.0-next.3

3 years ago

3.7.0

3 years ago

3.7.0-next.1

3 years ago

3.7.0-next.0

3 years ago

3.6.0-next.0

3 years ago

3.6.0-next.1

3 years ago

3.6.0-next.2

3 years ago

3.6.0

3 years ago

3.9.0-next.0

3 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.2.0-next.1

3 years ago

3.2.0-next.2

3 years ago

3.3.0-next.0

3 years ago

3.3.0-next.1

3 years ago

3.1.0

3 years ago

3.2.0-next.0

3 years ago

3.1.0-next.0

3 years ago

3.0.0

3 years ago

3.0.0-zz-next.2

3 years ago

3.0.0-zz-next.3

3 years ago

2.14.0

3 years ago

3.0.0-next.2

3 years ago

3.0.0-zz-next.0

3 years ago

3.0.0-zz-next.1

3 years ago

3.0.0-next.1

3 years ago

3.0.0-next.0

3 years ago

2.14.0-next.2

3 years ago

2.14.0-next.1

3 years ago

2.13.0

3 years ago

2.13.0-next.2

3 years ago

2.14.0-next.0

3 years ago

2.13.0-next.1

3 years ago

2.12.0

3 years ago

2.13.0-next.0

3 years ago

2.12.0-next.3

3 years ago

2.12.0-next.2

3 years ago

2.12.0-next.1

3 years ago

2.11.0

3 years ago

2.12.0-next.0

3 years ago

2.10.0

3 years ago

2.11.0-next.0

3 years ago

2.10.0-next.1

3 years ago

2.9.0

3 years ago

2.10.0-next.0

3 years ago

2.8.0

3 years ago

2.9.0-next.0

3 years ago

2.7.0

3 years ago

2.7.1

3 years ago

2.6.0

3 years ago

2.7.0-next.1

3 years ago

2.7.0-next.2

3 years ago

2.8.0-next.1

3 years ago

2.8.0-next.0

3 years ago

2.4.0

4 years ago

2.6.0-next.0

4 years ago

2.4.0-next.3

4 years ago

2.5.0-next.0

4 years ago

2.7.0-next.0

3 years ago

2.5.0

4 years ago

2.4.0-next.1

4 years ago

2.3.0

4 years ago

2.4.0-next.0

4 years ago

2.3.0-next.1

4 years ago

2.2.0

4 years ago

2.3.0-next.0

4 years ago

2.1.0

4 years ago

2.2.0-next.0

4 years ago

2.0.0

4 years ago

2.1.0-next.1

4 years ago

2.1.0-next.0

4 years ago

2.0.0-v3rc.0

4 years ago

2.0.0-next.2

4 years ago

1.10.1

4 years ago

2.0.0-next.1

4 years ago

2.0.0-next.0

4 years ago

1.10.0

4 years ago

1.11.0-next.0

4 years ago

1.9.0

4 years ago

1.10.0-next.0

4 years ago

1.8.0

4 years ago

1.9.0-next.0

4 years ago

1.8.0-next.1

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.8.0-next.0

4 years ago

1.6.0

4 years ago

1.7.0-next.0

4 years ago

1.5.0

4 years ago

1.6.0-next.0

4 years ago

1.4.0

4 years ago

1.4.0-next.1

4 years ago

1.5.0-next.0

4 years ago

1.3.24

4 years ago

1.4.0-next.0

4 years ago

1.3.23

4 years ago

1.3.22

4 years ago

1.3.21

4 years ago

1.3.20

4 years ago

1.3.19

4 years ago

1.3.18

4 years ago

1.3.17

4 years ago

1.3.16

4 years ago

1.3.15

4 years ago

1.3.14

4 years ago

1.3.13

4 years ago

1.3.12

4 years ago

1.3.11

4 years ago

1.3.10

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago