i want to post different data types of various form field using axios interceptors in react - axios

const initialValue={
bookname:"abc",
description:"",
sku:'',
ISBN_ASIN_UPC:'',
title:'',
// image_upload:"",
quantity:'',
cost_price:'',
profit:'',
marketplace_commision:'',
author:'',
publisher:'',
publication_date:'',
volume:'',
edition:'',
item_condition:'',
media:'',
book_number:'',
weight:'',
length:'',
width:'',
height:''
}
const [inventoryFormValue,setInventoryFormValue]=useState(initialValue)
const inventoryFormSubmit=async(e)=>{
e.preventDefault()
console.log(inventoryFormValue)
// console.log("file",file)
let response=await API.AddInventory(inventoryFormValue)
console.log(response.data)
if(response.data.status==="succes"){
navigate("/bookCatalog")
}
}
I have taken form data from front end and store in a object in key value pair(i values are string but i want some integer also) i know all the integer will dyanamically behave as string whenever we have not defined as a integer.

What you can do is to typecast the string value to the integer where you know that for particular key the value should be number. Below is the way you can do that
let stringValue = '1';
console.log(typeof stringValue); // string
let convertedToNumber = +convertedToNumber; // this will convert string to number
console.log(typeof convertedToNumber); // number
Note when you get value from form it will always be string so you would need to typecast it. Hope this answers your question.

Related

Nuget.Versioning.SemanticVersion.ToString(format) examples?

I can't seem to find any documentation anywhere on what formats one can pass in to .ToString() on NuGet.Versioning.SemanticVersion. The value seems to be indexing into a list of _formatters but there's no docs on what values are available by default, what the default behavior is, how to tweak it, etc.
e.g. this is all that's in the source code:
//
// Summary:
// Gives a normalized representation of the version. This string is unique to the
// identity of the version and does not contain metadata.
public virtual string ToNormalizedString()
{
return ToString("N", VersionFormatter.Instance);
}
//
// Summary:
// Gives a full representation of the version include metadata. This string is not
// unique to the identity of the version. Other versions that differ on metadata
// will have a different full string representation.
public virtual string ToFullString()
{
return ToString("F", VersionFormatter.Instance);
}
//
// Summary:
// Get the normalized string.
public override string ToString()
{
return ToNormalizedString();
}
//
// Summary:
// Custom string format.
public virtual string ToString(string format, IFormatProvider formatProvider)
{
string formattedString = null;
if (formatProvider == null || !TryFormatter(format, formatProvider, out formattedString))
{
formattedString = ToString();
}
return formattedString;
}
Anybody know where I can find this?
You were so close to finding the list of format characters yourself!
The first two methods you copied into your question reference a property VersionFormatter.Instance. Looking at the VersionFormatter class, the Format method enumerates the list of characters it handles: https://github.com/NuGet/NuGet.Client/blob/08a7a7bd17e504d808329dcc1ffc866d9f59d040/src/NuGet.Core/NuGet.Versioning/VersionFormatter.cs#L65-L101
character
method
N
AppendNormalized(builder, version);
V
AppendVersion(builder, version);
F
AppendFull(builder, version);
R
builder.Append(version.Release);
M
builder.Append(version.Metadata);
x
builder.Append(version.Major);
y
builder.Append(version.Minor);
z
builder.Append(version.Patch);
r
builder.Append(version is NuGetVersion nuGetVersion && nuGetVersion.IsLegacyVersion ? nuGetVersion.Version.Revision : 0);

Problem reading data back from Bluetooth on Flutter flutter_blue_plus

I am trying to read data back from a custom-built bluetooth board that simply sends back a string of data like this:
printf("Read 0x%2.2X%2.2X%2.2X%2.2X\n\r", d1, d2, d3, d4);
And the value I expect to get back is "Read 0xF2000080\n\r"
But what I get in the following flutter code is "RöØd 0xF2000080"
and sometimes different characters are the wrong ones in that string... the code that runs the printf sends back what is stored in memory for many different memory locations
uartTx.onValueChangedStream.listen((event1) {
processIncomingData(event1);
String stringVal = String.fromCharCodes(event1);
LLog.lLog(_tag, "build: uartTx event 1: String value ${stringVal}");
String stringVal2 = "";
event1.forEach((element) {
stringVal2 += element.toRadixString(16);
});
LLog.lLog(_tag, "build: uartTx event 1: String 2 value ${stringVal2}");
String hexVal = hex.encode(event1);
LLog.lLog(_tag, "build: uartTx event 1: Hex value ${hexVal}");
});
void processIncomingData(List<int> newBytes) {
// convert the List<int> to a list of <byte> sized objects
Uint8List convBytes = Uint8List.fromList(newBytes);
// convert the List<int> into a string:
String stringVal = String.fromCharCodes(newBytes);
// which looks a lot like this:
// [9X0CAF01460E4103][AP0200][BL0200][CL0210][DV0A312E302E30]
// [ and ] apparently are delimiters/terminations between commands
LLog.lLog(_tag, 'processIncomingData: Uint8List of bytes received are = $convBytes and the string conversion of that is $stringVal');
I tried to listen for incoming data on a bluetooth connection:
uartTx.onValueChangedStream.listen((event1) {
processIncomingData(event1);
I get bad characters in the List received:
processIncomingData(event1);
void processIncomingData(List<int> newBytes) {
// convert the List<int> to a list of <byte> sized objects
Uint8List convBytes = Uint8List.fromList(newBytes);
which looks like this:
"RöØd 0xF2000080"
I expect just a regular set of ascii characters instead:
"Read 0xF2000080\n\r"

Dart find string value in a list using contains

I have a list of numbers like below -
List contacts = [14169877890, 17781231234, 14161231234];
Now I want to find if one of the above list element would contain the below string value -
String value = '4169877890';
I have used list.any to do the search, but the below print statement inside the if condition is not printing anything.
if (contacts.any((e) => e.contains(value))) {
print(contacts[0]);
}
I am expecting it to print out the first element of the contacts list as it partially contains the string value.
What is it I am doing wrong here?
contacts isn't a List<String>, so your any search can't be true, you need turn element of contracts to string to able to use contains.
void main() {
var contacts = [14169877890, 17781231234, 14161231234];
print(contacts.runtimeType);
var value = '4169877890';
print(value.runtimeType);
var haveAnyValid = contacts.any((element) {
return "$element".contains(value);
});
print(haveAnyValid);
// result
// JSArray<int>
// String
// true
}
Not sure if contacts is an integer and value is a string on purpose or mistake, but this works in dart pad if you convert it to string:
if (contacts.any((e) => e.toString().contains(value))) {
print(contacts[0]);
}
DartPad Link.

Value of text field in protractor- undefined

I am not able to get value of label (as value is not editable and return by API).
I am using getText, but out put is always undefined. The value of this field is 2222.
using below
var activatedid = element(By.xpath("/html/body/app-root/mat-toolbar/div[3]/div[3]"));
activatedid.getText()
.then(function(text) {
console.log(this.text);
Remove this. before text, so you have
var activatedid = element(By.xpath("/html/body/app-root/mat-toolbar/div[3]/div[3]"));
activatedid.getText()
.then(function(text) {
console.log(text);
})

Support for basic datatypes in H5Attributes?

I am trying out the beta hdf5 toolkit of ilnumerics.
Currently I see H5Attributes support only ilnumerics arrays. Is there any plan to extend it for basic datatypes (such as string) as part of the final release?
Does ilnumerics H5 wrappers provide provision for extending any functionality to a particular
datatype?
ILNumerics internally uses the official HDF5 libraries from the HDF Group, of course. H5Attributes in HDF5 correspond to datasets with the limitation of being not capable of partial I/O. Besides that, H5Attributes are plain arrays! Support for basic (scalar) element types is given by assuming the array stored to be scalar.
Strings are a complete different story: strings in general are variable length datatypes. In terms of HDF5 strings are arrays of element type Char. The number of characters in the string determines the length of the array. In order to store a string into a dataset or attribute, you will have to store its individual characters as elements of the array. In ILNumerics, you can convert your string into ILArrray or ILArray (for ASCII data) and store that into the dataset/ attribute.
Please consult the following test case which stores a string as value into an attribute and reads the content back into a string.
Disclaimer: This is part of our internal test suite. You will not be able to compile the example directly, since it depends on the existence of several functions which may are not available. However, you will be able to understand how to store strings into datasets and attributes:
public void StringASCIAttribute() {
string file = "deleteA0001.h5";
string val = "This is a long string to be stored into an attribute.\r\n";
// transfer string into ILArray<Char>
ILArray<Char> A = ILMath.array<Char>(' ', 1, val.Length);
for (int i = 0; i < val.Length; i++) {
A.SetValue(val[i], 0, i);
}
// store the string as attribute of a group
using (var f = new H5File(file)) {
f.Add(new H5Group("grp1") {
Attributes = {
{ "title", A }
}
});
}
// check by reading back
// read back
using (var f = new H5File(file)) {
// must exist in the file
Assert.IsTrue(f.Get<H5Group>("grp1").Attributes.ContainsKey("title"));
// check size
var attr = f.Get<H5Group>("grp1").Attributes["title"];
Assert.IsTrue(attr.Size == ILMath.size(1, val.Length));
// read back
ILArray<Char> titleChar = attr.Get<Char>();
ILArray<byte> titleByte = attr.Get<byte>();
// compare byte values (sum)
int origsum = 0;
foreach (var c in val) origsum += (Byte)c;
Assert.IsTrue(ILMath.sumall(ILMath.toint32(titleByte)) == origsum);
StringBuilder title = new StringBuilder(attr.Size[1]);
for (int i = 0; i < titleChar.Length; i++) {
title.Append(titleChar.GetValue(i));
}
Assert.IsTrue(title.ToString() == val);
}
}
This stores arbitrary strings as 'Char-array' into HDF5 attributes and would work just the same for H5Dataset.
As an alternative solution you may use HDF5DotNet (http://hdf5.net/default.aspx) wrapper to write attributes as strings:
H5.open()
Uri destination = new Uri(#"C:\yourFileLocation\FileName.h5");
//Create an HDF5 file
H5FileId fileId = H5F.create(destination.LocalPath, H5F.CreateMode.ACC_TRUNC);
//Add a group to the file
H5GroupId groupId = H5G.create(fileId, "groupName");
string myString = "String attribute";
byte[] attrData = Encoding.ASCII.GetBytes(myString);
//Create an attribute of type STRING attached to the group
H5AttributeId attrId = H5A.create(groupId, "attributeName", H5T.create(H5T.CreateClass.STRING, attrData.Length),
H5S.create(H5S.H5SClass.SCALAR));
//Write the string into the attribute
H5A.write(attributeId, H5T.create(H5T.CreateClass.STRING, attrData.Length), new H5Array<byte>(attrData));
H5A.close(attributeId);
H5G.close(groupId);
H5F.close(fileId);
H5.close();