Git Product home page Git Product logo

infofile-utils's Introduction

IPG Automotive Infofile Utilities

JavaScript library for reading and writing IPG Automotive infofiles.

Getting Started

Installation:

npm install --save @ipguk/infofile-utils

Importing the library:

const infofile = require("@ipguk/infofile-utils");

Supported OS's

  • Windows
  • Linux

Requirements

Usage

Getting values from an infofile:

getDouble Returns a double value from an infofile for a given key or an array of keys. The value will be returned as a number.

Getting a single double value from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the double value for the keys "WheelCarrier.fl.mass"
const wheelCarrierValue = infofile.getDouble({file, keys:"WheelCarrier.fl.mass"});

// console.log the value, returns a double e.g. "0.5"
console.log(wheelCarrierValue)

Getting an array of double values from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the double values for the keys "WheelCarrier.fl.mass" and "WheelCarrier.fr.mass"
const wheelCarrierValues = infofile.getDouble({file, keys:["WheelCarrier.fl.mass", "WheelCarrier.fr.mass"]});

// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "WheelCarrier.fl.mass", value: 0.5}, {keys: "WheelCarrier.fr.mass", value: 0.5}]
console.log(wheelCarrierValues)
getValue A universal function for getting values from an infofile. All numerical key values are returned as numbers. All other key values are returned as strings.

Getting a single value from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the value for the keys "WheelCarrier.fl.mass"
const wheelCarrierValue = infofile.getValue({file, keys:"WheelCarrier.fl.mass"});

// console.log the value (returns an object like this {keys: "WheelCarrier.fl.mass", value: 0.0})
console.log(wheelCarrierValue)

Getting an array of values from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the values for the keys "WheelCarrier.fl.mass" and "SuspF.Spring.Kind"
const values = infofile.getValue({file, keys:["WheelCarrier.fl.mass", "SuspF.Spring.Kind"]});

// console.log the values (returns an array of objects like this [{keys: "WheelCarrier.fl.mass", value: 0.0}, {keys: "SuspF.Spring.Kind", value: "Hookean 1"}])
console.log(values)
getLong Returns a long value from an infofile for a given key or an array of keys. The value will be returned as a number.

Getting a single long value from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the long value for the keys "Body.mass"
const bodyMassValue = infofile.getLong({file, keys:"Body.mass"});

// console.log the value, returns a long e.g. 1801
console.log(bodyMassValue)

Getting an array of long values from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the long values for the keys "Body.mass" and "nAxle"
const longValues = infofile.getLong({file, keys:["Body.mass", "nAxle"]});

// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "Body.mass", value: 1801}, {keys: "nAxle", value: 2}]
console.log(longValues)
getString Returns a string value from an infofile for a given keys or an array of keys.

Getting a single string value from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the string value for the keys "Aero.Crosswind.Kind"
const aeroCrosswindKind = infofile.getString({file, keys:"Aero.Crosswind.Kind"});

// console.log the value, returns a string e.g. "Step"
console.log(aeroCrosswindKind)

Getting an array of string values from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the string values for the keys "Body.mass" and "Aero.Kind"
const stringValues = infofile.getString({file, keys:["Aero.Crosswind.Kind", "Aero.Kind"]});

// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "Aero.Crosswind.Kind", value: "Step"}, {keys: "Aero.Kind", value: "Coeff6x1 1"}]
console.log(stringValues)
getText Returns a text value from an infofile for a given keys or an array of keys. This is an array of strings are are split by newlines in the infofile.

Getting a single text value from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the text value for the keys "Description"
const description = infofile.getText({file, keys:"Description"});

// console.log the value, returns an array of strings e.g. ["This is a description", "of the infofile"]
console.log(description)

Getting an array of text values from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the text values for the keys "Description" and "Aero.Coeff"
const textValues = infofile.getText({file, keys:["Description", "Aero.Coeff"]});

// console.log the values, returns an array of objects with the keys "keys" and "value" e.g. [{keys: "Description", value: ["-180 -0.4 0.0 0.1 0.0 -0.01 0.0","-120 -0.2 -1.4 0.7 -0.2 -0.021 0.06","-90 0.0 -1.7 0.9 -0.2 0.0 0.0","-60 0.0 -1.7 0.9 -0.2 0.0 0.0","-30 0.0 -1.7 0.9 -0.2 0.0 0.0","0.0 0.0 -1.7 0.9 -0.2 0.0 0.0","30 0.0 -1.7 0.9 -0.2 0.0 0.0","60 0.0 -1.7 0.9 -0.2 0.0 0.0","90 0.0 -1.7 0.9 -0.2 0.0 0.0","120 0.0 -1.7 0.9 -0.2 0.0 0.0","180 0.0 -1.7 0.9 -0.2 0.0 0.0"]}]
console.log(textValues)

Setting values to a infofile:

setDouble Sets a double value to an infofile for a given keys.

Setting a single double value to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the double value for the keys "SuspF.Spring.l0" to 0.351
status = infofile.setDouble({file, values:{keys: "SuspF.Spring.l0", value: 0.351}});

// console.log the status, returns 0 if successful, -1 if not
console.log(status)

Setting an array of double values to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the double values for the keys "SuspF.Spring.l0" and "Body.mass" to 0.351 and 1830.15
status = infofile.setDouble({file, values:[{keys: SuspF.Spring.l0", value: 0.351}, {keys: "Body.mass", value:  1830.15}]});

// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "SuspF.Spring.l0", status: 0}, {keys: "Body.mass", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setValue A universal function to set values to an infofile.

Setting a single value to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the value for the keys "SuspF.Spring.l0" to 0.351
status = infofile.setValue({file, values:{keys: "SuspF.Spring.l0", value: 0.351}});

// console.log the status, returns 0 if successful, -1 if not
console.log(status)

Setting an array of values to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the values for the keys "SuspF.Spring.l0" and "Aero.Crosswind.Kind" to 0.351 and "Step"
status = infofile.setValue({file, values:[{keys: "SuspF.Spring.l0", value: 0.351}, {keys: "Aero.Crosswind.Kind", value:  "Step"}]});

// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "SuspF.Spring.l0", status: 0}, {keys: "Aero.Crosswind.Kind", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setLong Sets a long value to an infofile for a given keys.

Setting a single long value to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the long value for the keys "Body.mass" to 1801
status = infofile.setLong({file, values:{keys: "Body.mass", value: 1801}});

// console.log the status, returns 0 if successful, -1 if not
console.log(status)

Setting an array of long values to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the long values for the keys "Body.mass" and "nAxle" to 1801 and 2
status = infofile.setLong({file, values:[{keys: "Body.mass", value: 1801}, {keys: "nAxle", value: 2}]});

// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "Body.mass", status: 0}, {keys: "nAxle", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setString Sets a string value to an infofile for a given keys.

Setting a single string value to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the string value for the keys "Aero.Crosswind.Kind" to "Step"
status = infofile.setString({file, values:{keys: "Aero.Crosswind.Kind", value: "Step"}});

// console.log the status, returns 0 if successful, -1 if not
console.log(status)

Setting an array of string values to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the string values for the keys "Aero.Crosswind.Kind" and "Eng.Kind" to "Step" and "Flex"
status = infofile.setString({file, values:[{keys: "Aero.Crosswind.Kind", value: "Step"}, {keys: "Eng.Kind", value: "Flex"}]});

// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "Aero.Crosswind.Kind", status: 0}, {keys: "Eng.Kind", status: 0}] where status is 0 if successful, -1 if not
console.log(status)
setText Sets a text value to an infofile for a given keys. This is an array of strings are are split by newlines in the infofile for each item in the string array.

Setting a single text value to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the text value for the keys "Description" to ["This is a description", "This is a description on a second line"]
status = infofile.setText({file, values:{keys: "Description", value: ["This is a description", "This is a description on a second line"]}});

// console.log the status, returns 0 if successful, -1 if not
console.log(status)

Setting an array of text values to an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// set the text values for the keys "Description" and "Eng.Description" to ["This is a description", "This is a description on a second line"] and ["This is a description", "This is a description on a second line"]
status = infofile.setText({file, values:[{keys: "Description", value: ["This is a description", "This is a description on a second line"]}, {keys: "Eng.Description", value: ["This is a description", "This is a description on a second line"]}]});

// console.log the status, array of objects with the keys "keys" and "status" e.g. [{keys: "Description", status: 0}, {keys: "Eng.Description", status: 0}] where status is 0 if successful, -1 if not
console.log(status)

Other functions

getKey Lists the keys in an infofile, for a given prefix, if no prefix is provided all keys are returned

Listing all keys in an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// list all keys in the infofile
keys = infofile.getKey({file});

// console.log the keys, returns an array of keys e.g. ["Body.mass", "nAxle"]
console.log(keys)

Listing keys in an infofile for a given prefix:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// list all keys in the infofile for the prefix "Aero"
keys = infofile.getKey({ file, prefix: "Aero" });

// console.log the keys, returns an array of keys e.g. ["Aero.Crosswind.Kind", "Aero.Crosswind.Speed"]
console.log(keys)
getKeyKind Lists the getKeyKind, returns String_Key, Text_Key or No_Key

Get the getKeyKind for a single keys:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the getKeyKind for the keys "Body.mass"
keyKind = infofile.getKeyKind({file, keys: "Body.mass"});

// console.log the keyKind, returns String_Key if keys is a single line string, Text_Key if keys is a text array and No_Key if keys is not found
console.log(keyKind)

Get the getKeyKind for a list of keys:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// get the getKeyKind for the keys "Body.mass" and "nAxle"
getKeyKind = infofile.getKeyKind({file, keys: ["Body.mass", "nAxle"]});

// console.log the getKeyKind, returns an array of getKeyKind e.g. ["String_Key", "No_Key"]
console.log(getKeyKind)
deleteKey Deletes a key from an infofile

Delete a single keys from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// delete the keys "Body.mass"
status = infofile.deleteKey({file, keys: "Body.mass"});

// console.log the status, returns 0 if successful, -1 if not
console.log(status)

Delete a list of keys from an infofile:

// import the library
const infofile = require("@ipguk/infofile-utils");

// get the absolute path to the infofile
const file = C:\infofiles\infofile

// delete the keys "Body.mass" and "nAxle"
status = infofile.deleteKey({file, keys: ["Body.mass", "nAxle"]});

// console.log the status, returns an object with the keys "keys" and "status" e.g. {keys: "Body.mass", status: 0}, {keys: "nAxle", status: 0} where status is 0 if successful, -1 if not
console.log(status)

infofile-utils's People

Contributors

dependabot[bot] avatar dmbarry86 avatar jegasriskantha avatar

Watchers

 avatar

Forkers

junyang0412

infofile-utils's Issues

Module declaration file.

Enable the use of this library in typescript applications by creating a module declaration file, in order to prevent this error is vscode.

image

Numbers in scientific notation gets written differently on Windows and Linux.

When writing large numbers to an InfoFile, the InfoFile-API writes it in scientifc notation. However, there seems to be a difference in the formatting of the number depending on if it is written on Linux or Windows. This is causing some snapshot-tests to fail in CarMaker-Composer when they are executed inside a Docker container on GitHub-Actions.

snapshot_test

Note from the image that on Windows the number is written as 1e+006, whereas on Linux it is written as 1e+06.

Steps to reproduce:

  • Use the InfoFile API to write a large number to an InfoFile on both Linux and Windows.

API throws non-descriptive error when setting an empty value

Issue

  • when using the setValue method with an emtpy value like null, undefined,"", " " etc. the API throws "no error"
  • e.g. infofile.setValue({file, values: {keys: "Test.1", value: null}});
    grafik
  • this becomes hard to debug when setting an array of values and one of the values is undefined
  • ideally the API should either write an emtpy object in the infofile or include the key that caused the error in the error message

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.