Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@intelligo.ai/object-to-schema

Package Overview
Dependencies
Maintainers
8
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intelligo.ai/object-to-schema - npm Package Compare versions

Comparing version 2.2.5 to 2.2.6

2

dist/__tests__/__mapper__/mapper.js

@@ -11,5 +11,5 @@ "use strict";

test('creates an object that is the result of applying all transformations on the data object', function () {
expect(mapper_1.mapObject(data_json_1.default, transformations_json_1.transformations)).toMatchSnapshot();
expect((0, mapper_1.mapObject)(data_json_1.default, transformations_json_1.transformations)).toMatchSnapshot();
});
});
//# sourceMappingURL=mapper.js.map

@@ -10,3 +10,3 @@ "use strict";

test('mapper creates a schema that encompases all data from multiple results', function () {
var createdSchema = data_json_1.default.info.reduce(function (accSchema, object) { return schemaCreator_1.mapObjectToSchema(object, accSchema); }, {});
var createdSchema = data_json_1.default.info.reduce(function (accSchema, object) { return (0, schemaCreator_1.mapObjectToSchema)(object, accSchema); }, {});
expect(createdSchema).toMatchSnapshot();

@@ -13,0 +13,0 @@ });

@@ -22,2 +22,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.extractExampleFromSchema = extractExampleFromSchema;
var ramda_1 = __importDefault(require("ramda"));

@@ -33,3 +34,2 @@ function extractExampleFromSchema(schemaWithExamples) {

}
exports.extractExampleFromSchema = extractExampleFromSchema;
function cases(value) {

@@ -36,0 +36,0 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractExampleFromSchema = exports.mapObjectToSchema = exports.mapObject = void 0;
var mapper_1 = require("./mapper");
exports.mapObject = mapper_1.mapObject;
Object.defineProperty(exports, "mapObject", { enumerable: true, get: function () { return mapper_1.mapObject; } });
var schemaCreator_1 = require("./schemaCreator");
exports.mapObjectToSchema = schemaCreator_1.mapObjectToSchema;
Object.defineProperty(exports, "mapObjectToSchema", { enumerable: true, get: function () { return schemaCreator_1.mapObjectToSchema; } });
var exampleRecordExtractor_1 = require("./exampleRecordExtractor");
exports.extractExampleFromSchema = exampleRecordExtractor_1.extractExampleFromSchema;
Object.defineProperty(exports, "extractExampleFromSchema", { enumerable: true, get: function () { return exampleRecordExtractor_1.extractExampleFromSchema; } });
//# sourceMappingURL=index.js.map

@@ -33,2 +33,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.mapObject = mapObject;
var object_path_1 = __importDefault(require("object-path"));

@@ -46,6 +47,5 @@ var ramda_1 = __importDefault(require("ramda"));

var initialObject = createTargetObject(transformations, originalObj);
var postProcessedObject = postProcessing_1.postProcessCreatedObject(initialObject, transformations);
return transform_1.pruneEmpty(postProcessedObject);
var postProcessedObject = (0, postProcessing_1.postProcessCreatedObject)(initialObject, transformations);
return (0, transform_1.pruneEmpty)(postProcessedObject);
}
exports.mapObject = mapObject;
function createTargetObject(transformations, originalObj, targetObject) {

@@ -81,7 +81,7 @@ if (targetObject === void 0) { targetObject = {}; }

}
var transformGenerator = transform_1.generateTransform(transforms);
var transformGenerator = (0, transform_1.generateTransform)(transforms);
var transform = transformGenerator.next();
var valueToSet = object_path_1.default.get(originalObj, stringUtil_1.unUnidotify(transform.value.source)) || transform.value.target.defaultValue || null;
var valueToSet = object_path_1.default.get(originalObj, (0, stringUtil_1.unUnidotify)(transform.value.source)) || transform.value.target.defaultValue || null;
while (!transform.done
&& !(object_path_1.default.has(originalObj, stringUtil_1.unUnidotify(transform.value.source))
&& !(object_path_1.default.has(originalObj, (0, stringUtil_1.unUnidotify)(transform.value.source))
&& (!((_a = transform.value.target.predefinedTransformations) === null || _a === void 0 ? void 0 : _a.length)

@@ -94,3 +94,3 @@ || getValueAfterTransformations(transform.value.target, valueToSet)))

}
valueToSet = object_path_1.default.get(originalObj, stringUtil_1.unUnidotify(transform.value.source)) || transform.value.target.defaultValue || null;
valueToSet = object_path_1.default.get(originalObj, (0, stringUtil_1.unUnidotify)(transform.value.source)) || transform.value.target.defaultValue || null;
}

@@ -106,8 +106,8 @@ return transform.done ? [] : [transform.value];

var _b = __read(_a, 2), path = _b[0], transforms = _b[1];
return [path, transforms.map(function (transform) { return transform.target; })];
return [path, (transforms !== null && transforms !== void 0 ? transforms : []).map(function (transform) { return transform.target; })];
});
}
function eliminateLowPriority(originalObj, treeLeafs) {
var transforms = transform_1.treeLeafsToTransforms(treeLeafs);
var tranformsByTarget = transform_1.groupTransformsByTarget(transforms);
var transforms = (0, transform_1.treeLeafsToTransforms)(treeLeafs);
var tranformsByTarget = (0, transform_1.groupTransformsByTarget)(transforms);
var highestPriorityTransforms = Object

@@ -119,3 +119,3 @@ .entries(tranformsByTarget)

path,
chooseHighestPriorityTransforms(originalObj)(transform_1.sortTransformsByPriority(transforms))
chooseHighestPriorityTransforms(originalObj)((0, transform_1.sortTransformsByPriority)(transforms))
];

@@ -150,3 +150,3 @@ })

var _a;
var value = object_path_1.default.get(originalObj, stringUtil_1.unUnidotify(source));
var value = object_path_1.default.get(originalObj, (0, stringUtil_1.unUnidotify)(source));
var valueToSet = value === 0 ? value : (value || target.defaultValue || null);

@@ -211,3 +211,3 @@ if (target.predefinedTransformations) {

_b[key] = buildTree(value.map(function (transform) { return ({
source: transform.source.split(key + "[].")[1],
source: transform.source.split("".concat(key, "[]."))[1],
target: transform.target

@@ -217,3 +217,3 @@ }); })),

}, leafTransforms.reduce(function (acc, leaf) {
object_path_1.default.push(acc, stringUtil_1.unidotify(leaf.source), leaf.target);
object_path_1.default.push(acc, (0, stringUtil_1.unidotify)(leaf.source), leaf.target);
return acc;

@@ -220,0 +220,0 @@ }, {}));

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.postProcessCreatedObject = postProcessCreatedObject;
var object_path_1 = __importDefault(require("object-path"));

@@ -20,3 +21,2 @@ var strategies = {

}
exports.postProcessCreatedObject = postProcessCreatedObject;
function followInstruction(object, instruction) {

@@ -23,0 +23,0 @@ return Object

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.mapObjectToSchema = mapObjectToSchema;
var ramda_1 = __importDefault(require("ramda"));

@@ -20,17 +21,16 @@ var generalUtil_1 = require("./utils/generalUtil");

}
exports.mapObjectToSchema = mapObjectToSchema;
function resolveOperation(schema, obj, key) {
var nestedValue = obj[key];
var archType = generalUtil_1.resolveValueArchtype(nestedValue);
var archType = (0, generalUtil_1.resolveValueArchtype)(nestedValue);
switch (archType) {
case 'EMPTY':
return transform_1.assignSchema(schema, key, handleEmptyValue(schema, key));
return (0, transform_1.assignSchema)(schema, key, handleEmptyValue(schema, key));
case 'SIMPLE':
var type = generalUtil_1.resolveType(nestedValue);
return transform_1.assignSchema(schema, key, simpleType(type, nestedValue));
var type = (0, generalUtil_1.resolveType)(nestedValue);
return (0, transform_1.assignSchema)(schema, key, simpleType(type, nestedValue));
case 'ARRAY':
var schemaValue = schema[key];
return transform_1.assignSchema(schema, key, handleArrayValues(nestedValue, schemaValue));
return (0, transform_1.assignSchema)(schema, key, handleArrayValues(nestedValue, schemaValue));
case 'OBJECT':
return transform_1.assignSchema(schema, key, handleObjectValues(nestedValue, schema, key));
return (0, transform_1.assignSchema)(schema, key, handleObjectValues(nestedValue, schema, key));
}

@@ -68,3 +68,3 @@ }

function handleArrayValues(nestedValue, schemaValue) {
if (generalUtil_1.resolveValueArchtype(nestedValue[0]) == 'OBJECT') {
if ((0, generalUtil_1.resolveValueArchtype)(nestedValue[0]) == 'OBJECT') {
var arraySchema = nestedValue.reduce(function (accSchema, obj) { return mapObjectToSchema(obj, accSchema); }, schemaValue ? schemaValue[0] : {});

@@ -74,3 +74,3 @@ return [arraySchema];

else {
var type = generalUtil_1.resolveType(nestedValue[0]);
var type = (0, generalUtil_1.resolveType)(nestedValue[0]);
return [

@@ -77,0 +77,0 @@ JSON.stringify({

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.identity = identity;
exports.unique = unique;
exports.resolveType = resolveType;
exports.resolveValueArchtype = resolveValueArchtype;
function unique(val, idx, arr) {
return arr.indexOf(val) === idx;
}
exports.unique = unique;
function identity(value) {
return value;
}
exports.identity = identity;
function resolveValueArchtype(value) {

@@ -25,3 +27,2 @@ var type = resolveType(value);

}
exports.resolveValueArchtype = resolveValueArchtype;
function resolveType(value) {

@@ -49,3 +50,2 @@ if (value == null) {

}
exports.resolveType = resolveType;
//# sourceMappingURL=generalUtil.js.map

@@ -15,2 +15,3 @@ declare function fromTracerDate(tracerDate: number): string | undefined;

titleCase: (str: string | string[]) => string | string[];
companyNameFormat: (str: string | string[]) => string | string[];
toDate: (str: string | string[]) => string | string[];

@@ -17,0 +18,0 @@ arrayToString: (arr: string[], separator: string) => string;

@@ -14,12 +14,17 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.strategies = void 0;
var transform_1 = require("./transform");
var object_path_1 = require("object-path");
var toLowerCase = transform_1.applyToOneOrMany(function (str) { return str.toLowerCase(); });
var toUpperCase = transform_1.applyToOneOrMany(function (str) { return str.toUpperCase(); });
var titleCase = transform_1.applyToOneOrMany(function (str) { return str
.split(/\s/)
.map(function (word) { return "" + word[0].toUpperCase() + word.slice(1); })
.join(' '); });
var toDate = transform_1.applyToOneOrMany(function (str) { return new Date(str).toISOString(); });
var stringToArray = transform_1.applyToOneOrMany(function (str, separator) { return str.split(separator); });
var toLowerCase = (0, transform_1.applyToOneOrMany)(function (str) { return str.toLowerCase(); });
var toUpperCase = (0, transform_1.applyToOneOrMany)(function (str) { return str.toUpperCase(); });
var titleCase = (0, transform_1.applyToOneOrMany)(titleCaseTransformer);
var companyNameFormat = (0, transform_1.applyToOneOrMany)(companyNameTransformer);
function titleCaseTransformer(str) {
return str
.split(/\s/)
.map(function (word) { return "".concat(word[0].toUpperCase()).concat(word.slice(1).toLowerCase()); })
.join(' ');
}
var toDate = (0, transform_1.applyToOneOrMany)(function (str) { return new Date(str).toISOString(); });
var stringToArray = (0, transform_1.applyToOneOrMany)(function (str, separator) { return str.split(separator); });
function fromTracerDate(tracerDate) {

@@ -32,3 +37,3 @@ if (!tracerDate) {

var day = String(tracerDate).substr(6, 2);
return new Date(year + "-" + month + "-" + day).toString();
return new Date("".concat(year, "-").concat(month, "-").concat(day)).toString();
}

@@ -91,4 +96,4 @@ function tracerPropertyDocumentType(documentType) {

return value
.filter(function (entry) { return object_path_1.get(entry, path); })
.map(function (entry) { return object_path_1.get(entry, path); })
.filter(function (entry) { return (0, object_path_1.get)(entry, path); })
.map(function (entry) { return (0, object_path_1.get)(entry, path); })
.join(separator);

@@ -102,4 +107,4 @@ }

return value
.filter(function (entry) { return object_path_1.get(entry, path); })
.map(function (entry) { return object_path_1.get(entry, path); });
.filter(function (entry) { return (0, object_path_1.get)(entry, path); })
.map(function (entry) { return (0, object_path_1.get)(entry, path); });
}

@@ -128,3 +133,3 @@ function companyAddressType(addressType) {

var pathToCheck = options.pathToCheck, condition = options.condition, conditionValue = options.conditionValue, valueToMap = options.valueToMap, pathToMap = options.pathToMap;
var valueToCheck = object_path_1.get(value, pathToCheck);
var valueToCheck = (0, object_path_1.get)(value, pathToCheck);
var pass;

@@ -153,3 +158,3 @@ switch (condition) {

pathToMap ?
object_path_1.get(value, pathToMap) :
(0, object_path_1.get)(value, pathToMap) :
valueToMap :

@@ -165,9 +170,9 @@ undefined;

var key = keysToJoin_1_1.value;
var valueToCheck = object_path_1.get(value, key);
var valueToCheck = (0, object_path_1.get)(value, key);
if (valueToCheck) {
if (seperator) {
valueToMap = valueToMap ? valueToMap + (seperator + " " + valueToCheck) : valueToCheck;
valueToMap = valueToMap ? valueToMap + "".concat(seperator, " ").concat(valueToCheck) : valueToCheck;
continue;
}
valueToMap = valueToMap ? valueToMap + (" " + valueToCheck) : valueToCheck;
valueToMap = valueToMap ? valueToMap + " ".concat(valueToCheck) : valueToCheck;
}

@@ -186,2 +191,16 @@ valueToMap = valueToMap.trim();

}
function companyNameTransformer(str) {
var businessStructureAbbreviations = [
'Col', 'Corp', 'Inc', 'LC', 'LLC', 'LLLP', 'LLP', 'LP', 'Ltd', 'PC', 'PLLC', 'GP', 'Co'
];
var businessStructureAbbreviationsSet = new Set(businessStructureAbbreviations.map(function (abbr) { return abbr.toLowerCase(); }));
var words = str.split(/\s/);
var lastWord = words[words.length - 1];
var isBusinessStructureAbbreviation = businessStructureAbbreviationsSet.has(lastWord.toLowerCase().replace('.', ''));
if (isBusinessStructureAbbreviation) {
var formattedName = titleCaseTransformer(words.slice(0, -1).join(' '));
return "".concat(formattedName, " ").concat(lastWord);
}
return titleCaseTransformer(words.join(' '));
}
exports.strategies = {

@@ -192,2 +211,3 @@ predefinedTransformations: {

titleCase: function (str) { return titleCase(str); },
companyNameFormat: function (str) { return companyNameFormat(str); },
toDate: function (str) { return toDate(str); },

@@ -194,0 +214,0 @@ arrayToString: function (arr, separator) { return arr.join(separator); },

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unidotify = unidotify;
exports.unUnidotify = unUnidotify;
exports.replaceAll = replaceAll;
function unidotify(str) {

@@ -7,3 +10,2 @@ var unicodeDot = '\u2024';

}
exports.unidotify = unidotify;
function unUnidotify(str) {

@@ -13,7 +15,5 @@ var unicodeDot = '\u2024';

}
exports.unUnidotify = unUnidotify;
function replaceAll(original, substitute) {
return function (str) { return str.split(original).join(substitute); };
}
exports.replaceAll = replaceAll;
//# sourceMappingURL=stringUtil.js.map
import { Transform, SomeObj, TreeLeaf } from './types';
export declare function generateTransform(transforms: Transform[]): Iterator<Transform>;
export declare function applyToOneOrMany<P, A>(fn: (oneOrMany: P, args?: string | string[]) => A): (oneOrMany: P | P[], args?: string | string[] | undefined) => A | A[];
export declare function applyToOneOrMany<P, A>(fn: (oneOrMany: P, args?: string | string[]) => A): (oneOrMany: P | P[], args?: string | string[]) => A | A[];
export declare function assignSchema(schema: SomeObj, key: string, value: any): SomeObj & {

@@ -5,0 +5,0 @@ [x: string]: any;

@@ -8,3 +8,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -61,2 +61,9 @@ if (y = 0, t) op = [op[0] & 2, t.value];

Object.defineProperty(exports, "__esModule", { value: true });
exports.generateTransform = generateTransform;
exports.applyToOneOrMany = applyToOneOrMany;
exports.assignSchema = assignSchema;
exports.treeLeafsToTransforms = treeLeafsToTransforms;
exports.groupTransformsByTarget = groupTransformsByTarget;
exports.sortTransformsByPriority = sortTransformsByPriority;
exports.pruneEmpty = pruneEmpty;
var ramda_1 = __importDefault(require("ramda"));

@@ -98,3 +105,2 @@ var _ = require('lodash');

}
exports.generateTransform = generateTransform;
function applyToOneOrMany(fn) {

@@ -107,3 +113,2 @@ return function withFunction(oneOrMany, args) {

}
exports.applyToOneOrMany = applyToOneOrMany;
function assignSchema(schema, key, value) {

@@ -113,3 +118,2 @@ var _a;

}
exports.assignSchema = assignSchema;
function treeLeafsToTransforms(treeLeafs) {

@@ -122,11 +126,8 @@ var transforms = treeLeafs.flatMap(function (_a) {

}
exports.treeLeafsToTransforms = treeLeafsToTransforms;
function groupTransformsByTarget(transforms) {
return ramda_1.default.groupBy(function (transform) { return transform.target.path; })(transforms);
}
exports.groupTransformsByTarget = groupTransformsByTarget;
function sortTransformsByPriority(transforms) {
return ramda_1.default.sort(function (ta, tb) { var _a, _b, _c, _d; return ((_b = (_a = ta.target) === null || _a === void 0 ? void 0 : _a.priority) !== null && _b !== void 0 ? _b : 1000) - ((_d = (_c = tb.target) === null || _c === void 0 ? void 0 : _c.priority) !== null && _d !== void 0 ? _d : 1000); }, transforms);
}
exports.sortTransformsByPriority = sortTransformsByPriority;
function pruneEmpty(obj) {

@@ -146,3 +147,2 @@ return function prune(current) {

}
exports.pruneEmpty = pruneEmpty;
//# sourceMappingURL=transform.js.map

@@ -1,5 +0,5 @@

declare type SomeObj = {
type SomeObj = {
[key: string]: any;
};
declare type InstructionStrategies = {
type InstructionStrategies = {
[key: string]: (object: SomeObj, instruction: any) => SomeObj;

@@ -14,3 +14,3 @@ };

}
declare type TreeLeaf = [string, Transform['target'][]];
type TreeLeaf = [string, Transform['target'][]];
export interface ITarget {

@@ -26,9 +26,9 @@ path: string;

}
declare type Transform = {
type Transform = {
source: string;
target: ITarget;
};
declare type ValType = 'ARRAY' | 'STRING' | 'BOOLEAN' | 'OBJECT' | 'NULL' | 'NUMBER' | 'UNDEFINED';
declare type ValArchtype = 'SIMPLE' | 'EMPTY' | 'ARRAY' | 'OBJECT';
type ValType = 'ARRAY' | 'STRING' | 'BOOLEAN' | 'OBJECT' | 'NULL' | 'NUMBER' | 'UNDEFINED';
type ValArchtype = 'SIMPLE' | 'EMPTY' | 'ARRAY' | 'OBJECT';
export { SomeObj, Transform, InstructionStrategies, ValType, ValArchtype, TreeLeaf, };
//# sourceMappingURL=types.d.ts.map

@@ -0,0 +0,0 @@ module.exports = {

{
"name": "@intelligo.ai/object-to-schema",
"version": "2.2.5",
"version": "2.2.6",
"description": "",

@@ -15,10 +15,10 @@ "main": "dist/index.js",

"devDependencies": {
"@types/jest": "^24.0.21",
"@types/lodash": "^4.14.149",
"@types/object-path": "^0.11.0",
"@types/ramda": "github:types/npm-ramda#dist",
"jest": "^24.9.0",
"ts-jest": "^25.3.0",
"typescript": "^3.8.3",
"@types/node": "^13.9.8"
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.7",
"@types/node": "^22.5.0",
"@types/object-path": "^0.11.4",
"@types/ramda": "^0.30.1",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"typescript": "^5.5.4"
},

@@ -30,2 +30,2 @@ "dependencies": {

}
}
}

@@ -0,0 +0,0 @@ # object-to-schema-mapper

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc