npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

photo-metadata-replicate

v1.0.0

Published

Replicate metadata from one source item onto a set of targets: union list fields, fill in scalar fields if present, never clobber.

Readme

photo-metadata-replicate

CI npm version license: MIT

Your user tags one photo and wants it applied to the other forty. This library computes what each target's metadata should become and returns it as plain objects, so you can show the result in a UI, diff it, or hand it to a writer.

The target keeps its keywords, and an empty source field erases nothing. It's pure logic: no file access, no UI, no dependencies.

If your inputs are files on disk and you only need the write to happen, exiftool does that same merge directly and will serve you better:

exiftool -tagsFromFile source.jpg "-Subject+<Subject" targets/

Reach for this library when the metadata lives in objects (a selection in a tagging UI, rows from a database, a model the user is editing) and you need the merged result before anything touches a file.

Install

npm install photo-metadata-replicate

Usage

import { replicateMetadata, type MergeSchema } from "photo-metadata-replicate";

const schema: MergeSchema = {
  Keywords: "union",
  Caption: "overwrite-if-present",
};

const source = { Keywords: ["beach", "sunset"], Caption: "Golden hour" };
const target = { Keywords: ["family"], Caption: "" };

replicateMetadata(schema, source, target);
// => { Keywords: ["family", "beach", "sunset"], Caption: "Golden hour" }

For a whole selection at once:

import { replicateMetadataToAll } from "photo-metadata-replicate";

replicateMetadataToAll(schema, source, [target1, target2, target3]);
// => one merged result per target, same order as input

API

replicateMetadata(schema, source, target)

Merges source into target per schema and returns the result. Fields not in schema are copied from target as-is.

replicateMetadataToAll(schema, source, targets)

Same, applied to each item in targets independently.

MergeSchema

Record<string, MergeStrategy>, one strategy per field.

MergeStrategy

  • "union": for list fields (e.g. Keywords, Subject). Keeps target's items in their original order, appends source's new ones, no duplicates. Declaring it on a scalar field turns that field into a list, so use it only where you expect arrays.
  • "overwrite-if-present": for scalar fields (e.g. Caption, Title, Description). Uses source's value when that value carries information, otherwise keeps target's.

An empty value never overwrites a target and never enters a list. Empty means an absent field, an empty string, an empty array, or an array holding only those.

Metadata

Record<string, MetadataValue | MetadataValue[] | undefined>.

MetadataValue

string | number.

Composing with exiftool-arg-diff

This library only merges metadata. Pair it with exiftool-arg-diff to turn the merged result into exiftool args:

import { diffMetadataArgs, type MetadataSchema } from "exiftool-arg-diff";
import { replicateMetadata, type MergeSchema } from "photo-metadata-replicate";

const mergeSchema: MergeSchema = {
  Keywords: "union",
  Caption: "overwrite-if-present",
};

const diffSchema: MetadataSchema = {
  Keywords: "additive-list",
  Caption: "overwrite",
};

const argsPerTarget = targets.map((target) => {
  const merged = replicateMetadata(mergeSchema, source, target);
  return diffMetadataArgs(diffSchema, target, merged);
});
// null for a target if nothing changed, otherwise the exiftool args to run