A packing note containing $& can survive JSON parsing and still change when inserted into a text template. JavaScript interprets special dollar sequences when a string is passed as the replacement argument to replace(). If the note is data, return it from a replacer function instead.
This can affect a Shopify 3PL adapter that prepares plain-text work instructions. A drop shipping file and a stocked-order feed can both carry notes whose punctuation must reach the next step unchanged.
Make the insertion literal
MDN's replace() reference documents replacement-string patterns and explains that these patterns do not apply to text returned by a replacer function. The following local example requires one explicit placeholder and inserts the note through a function.
const assert = require('node:assert/strict');
const TOKEN = '{{packingNote}}';
function fillPackingNote(template, note) {
if (typeof template !== 'string' || typeof note !== 'string') {
throw new TypeError('Template and note must be strings');
}
const first = template.indexOf(TOKEN);
if (first < 0 || template.indexOf(TOKEN, first + TOKEN.length) !== -1) {
throw new TypeError('Expected exactly one packing-note placeholder');
}
return template.replace(TOKEN, () => note);
}
const template = 'Pack:{{packingNote}}|done';
assert.equal(template.replace(TOKEN, '$&'), template);
assert.equal(template.replace(TOKEN, '$$'), 'Pack:$|done');
const notes = ['$&', '$`', "$'", '$$', '$1', '$<name>', '',
'Use $5 ribbon', '{{packingNote}}', 'Line one\nLine two', '包装'];
for (const note of notes) {
assert.equal(fillPackingNote(template, note), 'Pack:' + note + '|done');
}
assert.equal(template, 'Pack:{{packingNote}}|done');
assert.throws(() => fillPackingNote('No placeholder', 'x'), TypeError);
assert.throws(() => fillPackingNote(TOKEN + TOKEN, 'x'), TypeError);
assert.throws(() => fillPackingNote(null, 'x'), TypeError);
assert.throws(() => fillPackingNote(template, undefined), TypeError);
console.log('Literal packing-note insertion checks passed');
Save the example as literal-note.cjs and run it with Node.js. The first two assertions expose string-replacement behavior. The loop then checks literal insertion for dollar sequences, empty text, a repeated placeholder inside the note, a newline and non-ASCII text. Additional checks reject a missing placeholder, an ambiguous template and non-string inputs.
An empty note is intentionally accepted here. If an empty instruction is prohibited in your shopify fulfillment contract, enforce that separate rule before insertion. Avoid trimming or rewriting the note merely to make this formatting function pass.
Keep text formatting separate from other checks
The function returns plain text. It does not escape HTML, produce safe SQL, verify instruction authority or decide whether a packing request is operationally acceptable. A destination that interprets markup or another language needs handling appropriate to that destination. The placeholder itself is fixed application text rather than a regular expression supplied by a caller.
For a china fulfillment connection, test the final instruction received by the intended system as well as this local result. A later formatter could still alter the note. This example sends no request and demonstrates no production integration.
An illustrative integration brief using International Fulfillment for Folligen would need to define the note field and the receiving format before adopting this code. The brief's name is not evidence of a customer account. Confirm the actual text contract with the china 3PL handling the proposed workflow.
YX Fulfillment's Shopify setup guide covers operational questions that sit outside this JavaScript formatting check.
Warehouse workstations and equipment.

Top comments (0)