@sanity/mutator
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -6,2 +6,5 @@ 'use strict'; | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.default = arrayToJSONMatchPath; | ||
@@ -14,4 +17,6 @@ | ||
function stringifySegment(segment, hasLeading) { | ||
var isNumber = typeof segment === 'number'; | ||
var type = typeof segment === 'undefined' ? 'undefined' : _typeof(segment); | ||
var isNumber = type === 'number'; | ||
if (isNumber) { | ||
@@ -21,2 +26,11 @@ return '[' + segment + ']'; | ||
var isObject = type === 'object' && segment != null; | ||
if (isObject) { | ||
return Object.keys(segment).map(function (key) { | ||
var val = segment[key]; | ||
return '[' + key + '==\'' + val + '\']'; | ||
}).join(''); | ||
} | ||
if (IS_DOTTABLE.test(segment)) { | ||
@@ -23,0 +37,0 @@ return hasLeading ? segment : '.' + segment; |
{ | ||
"name": "@sanity/mutator", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A set of models to make it easier to utilize the powerful real time collaborative features of Sanity", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -7,4 +7,6 @@ // @flow | ||
function stringifySegment(segment, hasLeading) { | ||
const isNumber = typeof segment === 'number' | ||
const type = typeof segment | ||
const isNumber = type === 'number' | ||
if (isNumber) { | ||
@@ -14,2 +16,11 @@ return `[${segment}]` | ||
const isObject = type === 'object' && segment != null | ||
if (isObject) { | ||
return Object.keys(segment).map(key => { | ||
const val = segment[key] | ||
return `[${key}=='${val}']` | ||
}).join('') | ||
} | ||
if (IS_DOTTABLE.test(segment)) { | ||
@@ -22,3 +33,3 @@ return hasLeading ? segment : `.${segment}` | ||
export default function arrayToJSONMatchPath(pathArray : Array<string|number>) : string { | ||
export default function arrayToJSONMatchPath(pathArray : Array<string|number|object>) : string { | ||
return pathArray.reduce((acc, segment, index) => { | ||
@@ -25,0 +36,0 @@ return acc + stringifySegment(segment, index === 0) |
@@ -12,3 +12,8 @@ // @flow | ||
[[1, 'foo', 'bar', 4], '[1].foo.bar[4]'], | ||
[[1, '-foo', 'bar', 4], "[1]['-foo'].bar[4]"] | ||
[[1, '-foo', 'bar', 4], "[1]['-foo'].bar[4]"], | ||
[[1, {foo: 'bar', bar: 'baz'}, 4], "[1][foo=='bar'][bar=='baz'][4]"] | ||
// future maybe: | ||
// [[1, [{foo: 'bar'}, {bar: 'baz'}], 4], "[1][foo=='bar'||bar=='baz'][4]"] | ||
// [[1, {foo: 'bar', bar: 'baz'}, 4], "[1][foo=='bar'&&bar=='baz'][4]"] | ||
] | ||
@@ -15,0 +20,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
317674
6645