| Current Path : /home/emeraadmin/www/4d695/ |
| Current File : /home/emeraadmin/www/4d695/parse-conflict-json.zip |
PK �[�\�c�r% % package.jsonnu �[��� {
"_id": "parse-conflict-json@3.0.1",
"_inBundle": true,
"_location": "/npm/parse-conflict-json",
"_phantomChildren": {},
"_requiredBy": [
"/npm",
"/npm/@npmcli/arborist"
],
"author": {
"name": "GitHub Inc."
},
"bugs": {
"url": "https://github.com/npm/parse-conflict-json/issues"
},
"dependencies": {
"json-parse-even-better-errors": "^3.0.0",
"just-diff": "^6.0.0",
"just-diff-apply": "^5.2.0"
},
"description": "Parse a JSON string that has git merge conflicts, resolving if possible",
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.12.0",
"tap": "^16.0.1"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"files": [
"bin/",
"lib/"
],
"homepage": "https://github.com/npm/parse-conflict-json#readme",
"license": "ISC",
"main": "lib",
"name": "parse-conflict-json",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/parse-conflict-json.git"
},
"scripts": {
"lint": "eslint \"**/*.js\"",
"lintfix": "npm run lint -- --fix",
"postlint": "template-oss-check",
"posttest": "npm run lint",
"snap": "tap",
"template-oss-apply": "template-oss-apply --force",
"test": "tap"
},
"tap": {
"check-coverage": true,
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.12.0"
},
"version": "3.0.1"
}
PK �[�\OC�i i lib/index.jsnu �[��� const parseJSON = require('json-parse-even-better-errors')
const { diff } = require('just-diff')
const { diffApply } = require('just-diff-apply')
const globalObjectProperties = Object.getOwnPropertyNames(Object.prototype)
const stripBOM = content => {
content = content.toString()
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
// because the buffer-to-string conversion in `fs.readFileSync()`
// translates it to FEFF, the UTF-16 BOM.
if (content.charCodeAt(0) === 0xFEFF) {
content = content.slice(1)
}
return content
}
const PARENT_RE = /\|{7,}/g
const OURS_RE = /<{7,}/g
const THEIRS_RE = /={7,}/g
const END_RE = />{7,}/g
const isDiff = str =>
str.match(OURS_RE) && str.match(THEIRS_RE) && str.match(END_RE)
const parseConflictJSON = (str, reviver, prefer) => {
prefer = prefer || 'ours'
if (prefer !== 'theirs' && prefer !== 'ours') {
throw new TypeError('prefer param must be "ours" or "theirs" if set')
}
str = stripBOM(str)
if (!isDiff(str)) {
return parseJSON(str)
}
const pieces = str.split(/[\n\r]+/g).reduce((acc, line) => {
if (line.match(PARENT_RE)) {
acc.state = 'parent'
} else if (line.match(OURS_RE)) {
acc.state = 'ours'
} else if (line.match(THEIRS_RE)) {
acc.state = 'theirs'
} else if (line.match(END_RE)) {
acc.state = 'top'
} else {
if (acc.state === 'top' || acc.state === 'ours') {
acc.ours += line
}
if (acc.state === 'top' || acc.state === 'theirs') {
acc.theirs += line
}
if (acc.state === 'top' || acc.state === 'parent') {
acc.parent += line
}
}
return acc
}, {
state: 'top',
ours: '',
theirs: '',
parent: '',
})
// this will throw if either piece is not valid JSON, that's intended
const parent = parseJSON(pieces.parent, reviver)
const ours = parseJSON(pieces.ours, reviver)
const theirs = parseJSON(pieces.theirs, reviver)
return prefer === 'ours'
? resolve(parent, ours, theirs)
: resolve(parent, theirs, ours)
}
const isObj = obj => obj && typeof obj === 'object'
const copyPath = (to, from, path, i) => {
const p = path[i]
if (isObj(to[p]) && isObj(from[p]) &&
Array.isArray(to[p]) === Array.isArray(from[p])) {
return copyPath(to[p], from[p], path, i + 1)
}
to[p] = from[p]
}
// get the diff from parent->ours and applying our changes on top of theirs.
// If they turned an object into a non-object, then put it back.
const resolve = (parent, ours, theirs) => {
const dours = diff(parent, ours)
for (let i = 0; i < dours.length; i++) {
if (globalObjectProperties.find(prop => dours[i].path.includes(prop))) {
continue
}
try {
diffApply(theirs, [dours[i]])
} catch (e) {
copyPath(theirs, ours, dours[i].path, 0)
}
}
return theirs
}
module.exports = Object.assign(parseConflictJSON, { isDiff })
PK �[�\�r��
LICENSE.mdnu �[��� <!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
ISC License
Copyright npm, Inc.
Permission to use, copy, modify, and/or distribute this
software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this
permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
USE OR PERFORMANCE OF THIS SOFTWARE.
PK �[�\�c�r% % package.jsonnu �[��� PK �[�\OC�i i a lib/index.jsnu �[��� PK �[�\�r��
LICENSE.mdnu �[��� PK � ^