Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

json-e

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-e - npm Package Compare versions

Comparing version
4.6.0
to
4.7.0
+1
-1
json_e.egg-info/PKG-INFO
Metadata-Version: 2.1
Name: json-e
Version: 4.6.0
Version: 4.7.0
Summary: A data-structure parameterization system written for embedding context in JSON objects

@@ -5,0 +5,0 @@ Home-page: https://json-e.js.org

@@ -135,3 +135,3 @@ from __future__ import absolute_import, print_function, unicode_literals

@builtin("split", variadic=is_string_or_number, minArgs=1)
@builtin("split", argument_tests=[is_string, is_string_or_number], minArgs=2)
def split(s, d=""):

@@ -138,0 +138,0 @@ if not d and is_string(s):

@@ -72,2 +72,4 @@ from .shared import InterpreterError, string

test_math_operands("/", left, right)
if right == 0:
raise InterpreterError("division by zero")
return operator.truediv(left, right)

@@ -74,0 +76,0 @@ elif node.token.kind == "*":

@@ -183,2 +183,4 @@ from .AST import (

node = self.parse()
if node is None:
raise SyntaxError.unexpected(self.current_token, expectedTokens)
arr.append(node)

@@ -185,0 +187,0 @@

@@ -95,2 +95,4 @@ from __future__ import absolute_import, print_function, unicode_literals

tree = parser.parse()
if not parser.current_token:
raise SyntaxError("unterminated ${..} expression")
if parser.current_token.kind != terminator:

@@ -306,2 +308,37 @@ raise SyntaxError.unexpected(parser.current_token)

@operator("$find")
def find(template, context):
EACH_RE = r"each\([a-zA-Z_][a-zA-Z0-9_]*(,\s*([a-zA-Z_][a-zA-Z0-9_]*))?\)"
checkUndefinedProperties(template, [r"\$find", EACH_RE])
value = renderValue(template["$find"], context)
if not isinstance(value, list):
raise TemplateError("$find value must evaluate to an array")
each_keys = [k for k in template if k.startswith("each(")]
if len(each_keys) != 1:
raise TemplateError("$find requires exactly one other property, each(..)")
each_key = each_keys[0]
each_args = [x.strip() for x in each_key[5:-1].split(",")]
each_var = each_args[0]
each_idx = each_args[1] if len(each_args) > 1 else None
each_template = template[each_key]
if not isinstance(each_template, string):
raise TemplateError("each can evaluate string expressions only")
subcontext = context.copy()
for i, elt in enumerate(value):
if each_idx is None:
subcontext[each_var] = elt
else:
subcontext[each_var] = elt
subcontext[each_idx] = i
if parse(each_template, subcontext):
return renderValue(elt, subcontext)
return DeleteMarker
@operator("$match")

@@ -398,3 +435,3 @@ def matchConstruct(template, context):

# handle by(..) if given, applying the schwartzian transform
# handle by(..) if given, producing a list of keys to be sorted
by_keys = [k for k in template if k.startswith("by(")]

@@ -410,13 +447,13 @@ if len(by_keys) == 1:

subcontext[by_var] = e
yield parse(by_expr, subcontext), e
yield parse(by_expr, subcontext)
to_sort = list(xform())
sort_keys = list(xform())
elif len(by_keys) == 0:
to_sort = [(e, e) for e in value]
sort_keys = value
else:
raise TemplateError("only one by(..) is allowed")
# check types
# check types of the values to be sorted all match
try:
eltype = type(to_sort[0][0])
eltype = type(sort_keys[0])
except IndexError:

@@ -426,9 +463,16 @@ return []

raise TemplateError("$sorted values to be sorted must have the same type")
if not all(isinstance(e[0], eltype) for e in to_sort):
if not all(isinstance(e, eltype) for e in sort_keys):
raise TemplateError("$sorted values to be sorted must have the same type")
# unzip the schwartzian transform
return list(e[1] for e in sorted(to_sort))
# If not using `by(..)`, just sort the values.
if sort_keys is value:
return sorted(value)
# Otherwise, index into the sort_keys array for each element.
return list(
pair[1]
for pair in sorted(enumerate(value), key=lambda pair: sort_keys[pair[0]])
)
def containsFunctions(rendered):

@@ -435,0 +479,0 @@ if hasattr(rendered, "__call__"):

Metadata-Version: 2.1
Name: json-e
Version: 4.6.0
Version: 4.7.0
Summary: A data-structure parameterization system written for embedding context in JSON objects

@@ -5,0 +5,0 @@ Home-page: https://json-e.js.org

@@ -5,3 +5,3 @@ import json

version = "4.6.0"
version = "4.7.0"

@@ -8,0 +8,0 @@ description = "A data-structure parameterization system written for embedding context in JSON objects"