Skip to content

Commit

Permalink
add default export, test with Webpack and typings
Browse files Browse the repository at this point in the history
Amended cherry-pick @1de6122774251a9688a354e2d23a09029dbefa65
  • Loading branch information
tomalec committed Aug 8, 2019
1 parent 18b4300 commit 18a14f0
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 7 deletions.
39 changes: 39 additions & 0 deletions dist/fast-json-patch.js
Expand Up @@ -660,12 +660,36 @@ function validate(sequence, document, externalValidator) {
}
}
exports.validate = validate;
/**
* Default export for backwards compat
*/
exports.default = {
JsonPatchError: exports.JsonPatchError,
deepClone: exports.deepClone,
getValueByPointer: getValueByPointer,
applyOperation: applyOperation,
applyPatch: applyPatch,
applyReducer: applyReducer,
validator: validator,
validate: validate
};


/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
Expand Down Expand Up @@ -861,6 +885,21 @@ function compare(tree1, tree2, invertible) {
return patches;
}
exports.compare = compare;
/**
* Default export for backwards compat
*/
// import just to re-export as default
var core = __webpack_require__(1);
var helpers_3 = __webpack_require__(0);
exports.default = __assign({}, core, {
// duplex
unobserve: unobserve,
observe: observe,
generate: generate,
compare: compare,
// helpers
JsonPatchError: helpers_3.PatchError, deepClone: helpers_1._deepClone, escapePathComponent: helpers_1.escapePathComponent,
unescapePathComponent: helpers_3.unescapePathComponent });


/***/ }),
Expand Down
4 changes: 2 additions & 2 deletions dist/fast-json-patch.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/core.ts
Expand Up @@ -457,3 +457,18 @@ export function validate<T>(sequence: Operation[], document?: T, externalValidat
}
}
}

/**
* Default export for backwards compat
*/

export default {
JsonPatchError,
deepClone,
getValueByPointer,
applyOperation,
applyPatch,
applyReducer,
validator,
validate
}
21 changes: 21 additions & 0 deletions src/duplex.ts
Expand Up @@ -216,3 +216,24 @@ export function compare(tree1: Object | Array<any>, tree2: Object | Array<any>,
_generate(tree1, tree2, patches, '', invertible);
return patches;
}

/**
* Default export for backwards compat
*/
// import just to re-export as default
import * as core from './core';
import { PatchError as JsonPatchError, unescapePathComponent } from './helpers';

export default {
...core,
// duplex
unobserve,
observe,
generate,
compare,
// helpers
JsonPatchError,
deepClone:_deepClone,
escapePathComponent,
unescapePathComponent
}
4 changes: 2 additions & 2 deletions test/spec/typings/typingsSpec.ts
Expand Up @@ -5,7 +5,7 @@
* @see https://stackoverflow.com/questions/49296151/how-to-write-tests-for-typescript-typing-definition
*/

// import jsonpatch from '../../..';
import jsonpatch from '../../..';
import * as jsonpatchStar from '../../..';
import { applyPatch, Operation } from '../../..';

Expand All @@ -14,7 +14,7 @@ const document = { firstName: "Albert", contactDetails: { phoneNumbers: [] } };
const typedPatch = new Array<Operation>({ op: "replace", path: "/firstName", value: "Joachim" });
const untypedPatch = [{ op: "replace", path: "/firstName", value: "Joachim" }];

// const test_jsonpatch = jsonpatch.applyPatch(document, typedPatch).newDocument;
const test_jsonpatch = jsonpatch.applyPatch(document, typedPatch).newDocument;
const test_jsonpatchStar = jsonpatchStar.applyPatch(document, typedPatch).newDocument;
const test_applyPatch = applyPatch(document, typedPatch).newDocument;

Expand Down

0 comments on commit 18a14f0

Please sign in to comment.