Skip to content

Commit

Permalink
Merge pull request #5 from brendo/use-is-pointer-internally
Browse files Browse the repository at this point in the history
Use isPointer internally
  • Loading branch information
jdwije committed Aug 16, 2017
2 parents 05e3d81 + 02faef9 commit f6722a3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const data = {
foo: 99
};

set(data, '#/foo', 77);
set(data, '#/foo', 77);

console.log(data); // { foo: 77 }
```
Expand Down Expand Up @@ -146,7 +146,7 @@ development.

### Requirements

- nodeJS >= 6
- NodeJS >= 6

### Setup

Expand All @@ -157,9 +157,7 @@ you can find more in `package.json`.

- `npm build`: build all source code and documentation
- `npm test`: run all unit test.
- `npm benchmark`: run the benchmark suite.
- `npm benchmark`: run the benchmark suite (requires `npm build` to have been run)

Make your changes and commit your code. When you are ready, send a pull request
to this repository.


2 changes: 1 addition & 1 deletion benchmarks/dereference-address-schema.benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as derefSync from 'json-schema-deref-sync';
import { dereference } from './../src/index';
import { dereference } from './../dist/index';
import resolve from './../tests/mockResolve';
import benchmark from './benchmark';

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/dereference-petstore-swagger.benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as derefSync from 'json-schema-deref-sync';
import * as $RefParser from 'json-schema-ref-parser';
import { dereference } from './../src/index';
import { dereference } from './../dist/index';
import resolve from './../tests/mockResolve';
import benchmark from './benchmark';

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/dereference-temando-swagger.benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as derefSync from 'json-schema-deref-sync';
import * as $RefParser from 'json-schema-ref-parser';
import { dereference } from './../src/index';
import { dereference } from './../dist/index';
import resolve from './../tests/mockResolve';
import benchmark from './benchmark';

Expand Down
3 changes: 2 additions & 1 deletion src/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// ## Dependencies

import * as has from 'lodash.has';
import { isPointer } from './isPointer';

// #### Implementation

Expand All @@ -35,7 +36,7 @@ export const get: Jst.getPointer = (schema, pointer) => {
// A JSON `pointer` must begin with the symbols '#', '/' or be an empty
// string ''. So as a first step, we check that this assumption is true and
// bail if not.
if (!(pointer.indexOf('#') === 0 || pointer.indexOf('/') === 0 || pointer === '')) {
if (!isPointer(pointer)) {
throw new Error(`invalid JSON pointer specified: '${pointer}'`);
}

Expand Down
3 changes: 2 additions & 1 deletion src/isPointer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// A JSON `pointer` must begin with the symbols '#', '/' or be an empty string ''.
export const isPointer = (input: string): boolean => {
if (typeof input !== 'string') {
return false;
Expand All @@ -7,7 +8,7 @@ export const isPointer = (input: string): boolean => {
return true;
}

if (input.match(/^#|^\//) !== null) {
if (/^#|^\//.test(input)) {
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/set.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as has from 'lodash.has';
import { isPointer } from './isPointer';

export const set: Jst.setPointer = (obj, pointer, value) => {

// A JSON `pointer` must begin with the symbols '#', '/' or be an empty
// string ''. So as a first step, we check that this assumption is true and
// bail if not.
if (!(pointer.indexOf('#') === 0 || pointer.indexOf('/') === 0 || pointer === '')) {
if (!isPointer(pointer)) {
throw new Error(`invalid JSON pointer specified: '${pointer}'`);
}

Expand Down

0 comments on commit f6722a3

Please sign in to comment.