@codefresh-io/docker-reference

中文文档
0.1.0发布于 2026/01/25MITTypeScriptCommonJS近 30 天下载 6411

A node.js package to parse docker image reference

原始使用文档
文档目录3 节
  1. Getting started
  2. Using parsers
  3. Grammer for the package

Docker-Reference

A small package to parse and work with docker images references.

Getting started

To use docker-reference you should start with creating a Reference instance:

const { Reference } = require('@codefresh-io/docker-reference');

const imageReference = new Reference({
    domain: 'r.cfcr.io',
    repository: 'codefresh/demochat',
    tag: 'master',
    digest: 'sha256:58fe87ff24d5a3ac35c887dcef82eb619565987c1083282f876c7c2657a5f94e'
});

console.log(imageReference.repositoryUrl); // r.cfcr.io/codefresh/demochat
console.log(imageReference.toString()); // r.cfcr.io/codefresh/demochat:master@sha256:58fe87ff24d5a3ac35c887dcef82eb619565987c1083282f876c7c2657a5f94e

Using parsers

You can also use parser to create your Reference instance:

const { parseQualifiedName } = require('@codefresh-io/docker-reference');

const imageReference = parseQualifiedName('r.cfcr.io/codefresh/demochat:master@sha256:58fe87ff24d5a3ac35c887dcef82eb619565987c1083282f876c7c2657a5f94e');

console.log(imageReference.domain);     // r.cfcr.io
console.log(imageReference.repository); // codefresh/demochat
console.log(imageReference.tag);        // master
console.log(imageReference.digest);     // sha256:58fe87ff24d5a3ac35c887dcef82eb619565987c1083282f876c7c2657a5f94e

There are 3 parsers in the package:

  1. parseQualifiedName:

    This should be use when parsing a string representing a qualified image reference, meaning the string should contain at least the domain and the repository of the image.

  2. parseFamiliarName:

    This should be use when parsing a string representing a familiar image reference, meaning the string might not contains the domain part and this case the domain part would become docker.io. Also when the domain is missing and the repository contains only one part the repository would be prefixed with library/.

    This parser would parse all qualified image reference the same as parseQualifiedName parser

  3. parseAll:

    This should be use when parsing a string representing a familiar image reference or identifier.

    This parser would parse all qualified image reference the same as parseQualifiedName parser and parse every familiar image reference the same as parseFamiliarName

Grammer for the package

pattaren
referencename [ ":" tag ] [ "@" digest ]
name[domain '/'] path-component ['/' path-component]*
domaindomain-component ['.' domain-component]* [':' port-number]
domain-component`/([a-zA-Z0-9]
port-number/[0-9]+/
path-componentalpha-numeric [separator alpha-numeric]*
alpha-numeric/[a-z0-9]+/
separator`/[_.]
tag/[\w][\w.-]{0,127}/
digestdigest-algorithm ":" digest-hex
digest-algorithmdigest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]*
digest-algorithm-separator/[+.-_]/
digest-algorithm-component/[A-Za-z][A-Za-z0-9]*/
digest-hex/[0-9a-fA-F]{32,}/ (At least 128 bit digest value)
identifier/[a-f0-9]{64}/
short-identifier/[a-f0-9]{6,64}/

版本与发布记录

@codefresh-io/docker-reference 共发布 11 个版本,首次发布于 2017/06/04;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0latest2026/01/259 个月前
0.0.112021/12/134 年前
0.0.102021/12/134 年前
0.0.82021/07/315 年前
0.0.72021/07/315 年前
0.0.62021/07/315 年前

关于 @codefresh-io/docker-reference 的常见问题

@codefresh-io/docker-reference 是什么?

A node.js package to parse docker image reference

如何安装 @codefresh-io/docker-reference?

在项目目录运行 npm install @codefresh-io/docker-reference,或使用 pnpm add / yarn add / bun add。

@codefresh-io/docker-reference 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codefresh-io/docker-reference 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codefresh-io/docker-reference 可以商用吗?

@codefresh-io/docker-reference 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codefresh-io/docker-reference 的下载量有多少?

根据 npm 官方下载统计,@codefresh-io/docker-reference 在 2026/10/10 – 2026/11/08 这 30 天内被下载 6,411 次,日均约 214 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codefresh-io/docker-reference 还在维护吗?

最新版本 0.1.0 发布于 2026/01/25(9 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2017/06/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。