@teleporthq/teleport-shared
Advanced tools
Comparing version 0.36.0 to 0.36.6
@@ -0,2 +1,5 @@ | ||
import { UIDLPropDefinition, UIDLStateDefinition } from '@teleporthq/teleport-types'; | ||
export declare const generateLocalDependenciesPrefix: (fromPath: string[], toPath: string[]) => string; | ||
export declare const dynamicPathExistsInDefinitions: (path: string, definitions?: Record<string, UIDLPropDefinition> | Record<string, UIDLStateDefinition>) => boolean; | ||
export declare const getValueFromPath: (path: string, definition?: Record<string, any>) => any; | ||
//# sourceMappingURL=generic.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateLocalDependenciesPrefix = void 0; | ||
exports.getValueFromPath = exports.dynamicPathExistsInDefinitions = exports.generateLocalDependenciesPrefix = void 0; | ||
var generateLocalDependenciesPrefix = function (fromPath, toPath) { | ||
@@ -61,2 +61,47 @@ /* | ||
}; | ||
var dynamicPathExistsInDefinitions = function (path, definitions) { | ||
if (definitions === void 0) { definitions = {}; } | ||
if (!path) { | ||
return false; | ||
} | ||
// Extract the keys from the path string considering both dot and bracket notation | ||
var pathKeys = path.split(/\.|\[\s*['"]?(.+?)['"]?\s*\]/).filter(Boolean); | ||
// Get definition values of prop/state definitions | ||
var obj = Object.keys(definitions).reduce(function (acc, key) { | ||
if ('defaultValue' in definitions[key]) { | ||
acc[key] = definitions[key].defaultValue; | ||
} | ||
return acc; | ||
}, {}); | ||
// If the first key does not exist in the object, return true. | ||
// Which means there might not be a defaultValue that is set for the prop/state | ||
if (!(pathKeys[0] in obj)) { | ||
return true; | ||
} | ||
for (var _i = 0, pathKeys_1 = pathKeys; _i < pathKeys_1.length; _i++) { | ||
var key = pathKeys_1[_i]; | ||
// Check if the key exists in the current object | ||
// NOTE: using 'key in obj' instead of 'obj[key]' is important to avoid returning 'false' when path exists, but value is empty string/undefined/null | ||
if (!(key in obj)) { | ||
return false; | ||
} | ||
// Move to the next nested object | ||
obj = obj[key]; | ||
} | ||
return true; | ||
}; | ||
exports.dynamicPathExistsInDefinitions = dynamicPathExistsInDefinitions; | ||
/* tslint:disable no-any */ | ||
var getValueFromPath = function (path, definition) { | ||
if (definition === void 0) { definition = {}; } | ||
var pathKeys = path.split(/\.|\[(['"]?)(.+?)\1\]/).filter(Boolean); | ||
/* tslint:disable no-any */ | ||
return pathKeys.reduce(function (acc, key) { | ||
if (acc === undefined || acc === null) { | ||
return undefined; | ||
} | ||
return acc[key]; | ||
}, definition); | ||
}; | ||
exports.getValueFromPath = getValueFromPath; | ||
//# sourceMappingURL=generic.js.map |
@@ -170,3 +170,7 @@ "use strict"; | ||
Object.keys(attrs_1).forEach(function (attrKey) { | ||
(0, exports.traverseNodes)(attrs_1[attrKey], fn, node); | ||
var attr = attrs_1[attrKey]; | ||
if (attr.type === 'object') { | ||
return; | ||
} | ||
(0, exports.traverseNodes)(attr, fn, node); | ||
}); | ||
@@ -718,2 +722,3 @@ } | ||
} | ||
case 'object': | ||
case 'element': | ||
@@ -720,0 +725,0 @@ acc[key] = attributeContent; |
@@ -0,2 +1,5 @@ | ||
import { UIDLPropDefinition, UIDLStateDefinition } from '@teleporthq/teleport-types'; | ||
export declare const generateLocalDependenciesPrefix: (fromPath: string[], toPath: string[]) => string; | ||
export declare const dynamicPathExistsInDefinitions: (path: string, definitions?: Record<string, UIDLPropDefinition> | Record<string, UIDLStateDefinition>) => boolean; | ||
export declare const getValueFromPath: (path: string, definition?: Record<string, any>) => any; | ||
//# sourceMappingURL=generic.d.ts.map |
@@ -57,2 +57,45 @@ export var generateLocalDependenciesPrefix = function (fromPath, toPath) { | ||
}; | ||
export var dynamicPathExistsInDefinitions = function (path, definitions) { | ||
if (definitions === void 0) { definitions = {}; } | ||
if (!path) { | ||
return false; | ||
} | ||
// Extract the keys from the path string considering both dot and bracket notation | ||
var pathKeys = path.split(/\.|\[\s*['"]?(.+?)['"]?\s*\]/).filter(Boolean); | ||
// Get definition values of prop/state definitions | ||
var obj = Object.keys(definitions).reduce(function (acc, key) { | ||
if ('defaultValue' in definitions[key]) { | ||
acc[key] = definitions[key].defaultValue; | ||
} | ||
return acc; | ||
}, {}); | ||
// If the first key does not exist in the object, return true. | ||
// Which means there might not be a defaultValue that is set for the prop/state | ||
if (!(pathKeys[0] in obj)) { | ||
return true; | ||
} | ||
for (var _i = 0, pathKeys_1 = pathKeys; _i < pathKeys_1.length; _i++) { | ||
var key = pathKeys_1[_i]; | ||
// Check if the key exists in the current object | ||
// NOTE: using 'key in obj' instead of 'obj[key]' is important to avoid returning 'false' when path exists, but value is empty string/undefined/null | ||
if (!(key in obj)) { | ||
return false; | ||
} | ||
// Move to the next nested object | ||
obj = obj[key]; | ||
} | ||
return true; | ||
}; | ||
/* tslint:disable no-any */ | ||
export var getValueFromPath = function (path, definition) { | ||
if (definition === void 0) { definition = {}; } | ||
var pathKeys = path.split(/\.|\[(['"]?)(.+?)\1\]/).filter(Boolean); | ||
/* tslint:disable no-any */ | ||
return pathKeys.reduce(function (acc, key) { | ||
if (acc === undefined || acc === null) { | ||
return undefined; | ||
} | ||
return acc[key]; | ||
}, definition); | ||
}; | ||
//# sourceMappingURL=generic.js.map |
@@ -156,3 +156,7 @@ var __assign = (this && this.__assign) || function () { | ||
Object.keys(attrs_1).forEach(function (attrKey) { | ||
traverseNodes(attrs_1[attrKey], fn, node); | ||
var attr = attrs_1[attrKey]; | ||
if (attr.type === 'object') { | ||
return; | ||
} | ||
traverseNodes(attr, fn, node); | ||
}); | ||
@@ -695,2 +699,3 @@ } | ||
} | ||
case 'object': | ||
case 'element': | ||
@@ -697,0 +702,0 @@ acc[key] = attributeContent; |
{ | ||
"name": "@teleporthq/teleport-shared", | ||
"version": "0.36.0", | ||
"version": "0.36.6", | ||
"description": "A utility belt for the entire teleportHQ ecosystem", | ||
@@ -28,7 +28,7 @@ "author": "teleportHQ", | ||
"@babel/types": "^7.5.5", | ||
"@teleporthq/teleport-types": "^0.36.0", | ||
"@teleporthq/teleport-types": "^0.36.6", | ||
"jss": "^10.0.0", | ||
"jss-preset-default": "^10.0.0" | ||
}, | ||
"gitHead": "223c0c8f02f64cbfa78eed5ee38836d44efc7f60" | ||
"gitHead": "64a55c39dba17f13dc58805a7a28f74cd96dd03a" | ||
} |
@@ -0,1 +1,3 @@ | ||
import { UIDLPropDefinition, UIDLStateDefinition } from '@teleporthq/teleport-types' | ||
export const generateLocalDependenciesPrefix = (fromPath: string[], toPath: string[]): string => { | ||
@@ -69,1 +71,54 @@ /* | ||
} | ||
export const dynamicPathExistsInDefinitions = ( | ||
path: string, | ||
definitions: Record<string, UIDLPropDefinition> | Record<string, UIDLStateDefinition> = {} | ||
) => { | ||
if (!path) { | ||
return false | ||
} | ||
// Extract the keys from the path string considering both dot and bracket notation | ||
const pathKeys = path.split(/\.|\[\s*['"]?(.+?)['"]?\s*\]/).filter(Boolean) | ||
// Get definition values of prop/state definitions | ||
let obj = Object.keys(definitions).reduce((acc, key) => { | ||
if ('defaultValue' in definitions[key]) { | ||
acc[key] = definitions[key].defaultValue | ||
} | ||
return acc | ||
}, {} as Record<string, unknown>) | ||
// If the first key does not exist in the object, return true. | ||
// Which means there might not be a defaultValue that is set for the prop/state | ||
if (!(pathKeys[0] in obj)) { | ||
return true | ||
} | ||
for (const key of pathKeys) { | ||
// Check if the key exists in the current object | ||
// NOTE: using 'key in obj' instead of 'obj[key]' is important to avoid returning 'false' when path exists, but value is empty string/undefined/null | ||
if (!(key in obj)) { | ||
return false | ||
} | ||
// Move to the next nested object | ||
obj = obj[key] as Record<string, unknown> | ||
} | ||
return true | ||
} | ||
/* tslint:disable no-any */ | ||
export const getValueFromPath = (path: string, definition: Record<string, any> = {}): any => { | ||
const pathKeys = path.split(/\.|\[(['"]?)(.+?)\1\]/).filter(Boolean) | ||
/* tslint:disable no-any */ | ||
return pathKeys.reduce((acc: any, key: string) => { | ||
if (acc === undefined || acc === null) { | ||
return undefined | ||
} | ||
return acc[key] | ||
}, definition) | ||
} |
@@ -208,3 +208,7 @@ import { | ||
Object.keys(attrs).forEach((attrKey) => { | ||
traverseNodes(attrs[attrKey], fn, node) | ||
const attr = attrs[attrKey] | ||
if (attr.type === 'object') { | ||
return | ||
} | ||
traverseNodes(attr, fn, node) | ||
}) | ||
@@ -906,2 +910,3 @@ } | ||
case 'object': | ||
case 'element': | ||
@@ -908,0 +913,0 @@ acc[key] = attributeContent as UIDLAttributeValue |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
286407
4010