@stryke/json 0.5.2 â 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/pointer/parse.cjs +25 -24
- package/dist/pointer/parse.d.ts +1 -1
- package/dist/pointer/parse.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ This package is part of Storm Software's **đŠī¸ Stryke** monorepo. Stryke pac
|
|
|
22
22
|
|
|
23
23
|
<h3 align="center">đģ Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
|
|
24
24
|
|
|
25
|
-
[](https://prettier.io/) [](http://nx.dev/) [](https://nextjs.org/) [](http://commitizen.github.io/cz-cli/)  [](https://fumadocs.vercel.app/) 
|
|
26
26
|
|
|
27
27
|
> [!IMPORTANT] This repository, and the apps, libraries, and tools contained
|
|
28
28
|
> within, is still in it's initial development phase. As a result, bugs and
|
package/dist/pointer/parse.cjs
CHANGED
|
@@ -11,39 +11,40 @@ exports.parent = parent;
|
|
|
11
11
|
exports.parseJsonPointer = parseJsonPointer;
|
|
12
12
|
exports.unescapePointerSegment = unescapePointerSegment;
|
|
13
13
|
var _isNumber = require("@stryke/type-checks/is-number");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
u =
|
|
17
|
-
c =
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
var _isString = require("@stryke/type-checks/is-string");
|
|
15
|
+
const s = /~1/g,
|
|
16
|
+
u = /~0/g,
|
|
17
|
+
c = /~/g,
|
|
18
|
+
l = /\//g;
|
|
19
|
+
function escapePointerSegment(r) {
|
|
20
|
+
return !r.includes("/") && !r.includes("~") ? r : r.replace(c, "~0").replace(l, "~1");
|
|
20
21
|
}
|
|
21
|
-
function unescapePointerSegment(
|
|
22
|
-
return
|
|
22
|
+
function unescapePointerSegment(r) {
|
|
23
|
+
return r.includes("~") ? r.replace(s, "/").replace(u, "~") : r;
|
|
23
24
|
}
|
|
24
|
-
function parseJsonPointer(
|
|
25
|
-
return
|
|
25
|
+
function parseJsonPointer(r) {
|
|
26
|
+
return r ? r.slice(1).split("/").map(n => unescapePointerSegment(n)) : [];
|
|
26
27
|
}
|
|
27
|
-
function formatJsonPointer(
|
|
28
|
-
return isRoot(
|
|
28
|
+
function formatJsonPointer(r) {
|
|
29
|
+
return isRoot(r) ? "" : `/${r.map(n => escapePointerSegment(String(n))).join("/")}`;
|
|
29
30
|
}
|
|
30
|
-
const isRoot =
|
|
31
|
+
const isRoot = r => (0, _isString.isString)(r) ? r === "" : (0, _isNumber.isNumber)(r) ? r === 0 : Array.isArray(r) && r.length === 0;
|
|
31
32
|
exports.isRoot = isRoot;
|
|
32
|
-
function parent(
|
|
33
|
-
if (
|
|
34
|
-
return
|
|
33
|
+
function parent(r) {
|
|
34
|
+
if (r.length === 0) throw new Error("NO_PARENT");
|
|
35
|
+
return r.slice(0, -1);
|
|
35
36
|
}
|
|
36
|
-
function isValidIndex(
|
|
37
|
-
if ((0, _isNumber.isNumber)(
|
|
38
|
-
const
|
|
39
|
-
return String(
|
|
37
|
+
function isValidIndex(r) {
|
|
38
|
+
if ((0, _isNumber.isNumber)(r)) return !0;
|
|
39
|
+
const n = Number.parseInt(r, 10);
|
|
40
|
+
return String(n) === r && n >= 0;
|
|
40
41
|
}
|
|
41
|
-
const isInteger =
|
|
42
|
-
const
|
|
42
|
+
const isInteger = r => {
|
|
43
|
+
const n = r.length;
|
|
43
44
|
let t = 0,
|
|
44
45
|
e;
|
|
45
|
-
for (; t <
|
|
46
|
-
if (e =
|
|
46
|
+
for (; t < n;) {
|
|
47
|
+
if (e = r.codePointAt(t), e >= 48 && e <= 57) {
|
|
47
48
|
t++;
|
|
48
49
|
continue;
|
|
49
50
|
}
|
package/dist/pointer/parse.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare function formatJsonPointer(path: JsonPointerPath): string;
|
|
|
26
26
|
/**
|
|
27
27
|
* Returns true if JSON Pointer points to root value, false otherwise.
|
|
28
28
|
*/
|
|
29
|
-
export declare const isRoot: (path: string | number) => boolean;
|
|
29
|
+
export declare const isRoot: (path: string | number | JsonPointerPath) => boolean;
|
|
30
30
|
/**
|
|
31
31
|
* Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].
|
|
32
32
|
*/
|
package/dist/pointer/parse.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNumber as o}from"@stryke/type-checks/is-number";const
|
|
1
|
+
import{isNumber as o}from"@stryke/type-checks/is-number";import{isString as i}from"@stryke/type-checks/is-string";const s=/~1/g,u=/~0/g,c=/~/g,l=/\//g;export function escapePointerSegment(r){return!r.includes("/")&&!r.includes("~")?r:r.replace(c,"~0").replace(l,"~1")}export function unescapePointerSegment(r){return r.includes("~")?r.replace(s,"/").replace(u,"~"):r}export function parseJsonPointer(r){return r?r.slice(1).split("/").map(n=>unescapePointerSegment(n)):[]}export function formatJsonPointer(r){return isRoot(r)?"":`/${r.map(n=>escapePointerSegment(String(n))).join("/")}`}export const isRoot=r=>i(r)?r==="":o(r)?r===0:Array.isArray(r)&&r.length===0;export function parent(r){if(r.length===0)throw new Error("NO_PARENT");return r.slice(0,-1)}export function isValidIndex(r){if(o(r))return!0;const n=Number.parseInt(r,10);return String(n)===r&&n>=0}export const isInteger=r=>{const n=r.length;let t=0,e;for(;t<n;){if(e=r.codePointAt(t),e>=48&&e<=57){t++;continue}return!1}return!0};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/json",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing JSON parsing/stringify utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"jsonc-parser": "3.3.1",
|
|
15
15
|
"lines-and-columns": "2.0.4",
|
|
16
16
|
"superjson": "2.2.2",
|
|
17
|
-
"@stryke/type-checks": ">=0.1.
|
|
18
|
-
"@stryke/types": ">=0.7.
|
|
17
|
+
"@stryke/type-checks": ">=0.1.4",
|
|
18
|
+
"@stryke/types": ">=0.7.3"
|
|
19
19
|
},
|
|
20
20
|
"publishConfig": { "access": "public" },
|
|
21
21
|
"devDependencies": {},
|