conversikit
Advanced tools
Comparing version 1.7.0 to 1.7.1
104
index.js
@@ -0,6 +1,54 @@ | ||
const toConvertArrayJson = async (value) => { | ||
try { | ||
if (typeof value != "object" || value.length === 0) { | ||
return {}; | ||
} | ||
let finalJson = {}; | ||
for (let i = 0; i < value.length; i++) { | ||
if (finalJson.hasOwnProperty(value[i])) { | ||
finalJson[`d_${value[i]}`] = value[++i] || ''; | ||
continue; | ||
} | ||
finalJson[value[i]] = value[++i] || ''; | ||
} | ||
return finalJson; | ||
} catch (error) { | ||
return {}; | ||
} | ||
} | ||
let data = [ | ||
"name", "Ankit", | ||
"roll", "10", | ||
"age", "17", | ||
"gender", "Male", | ||
"address", "123 Main Street", | ||
"city", "Exampleville", | ||
"state", "ABC", | ||
"zipcode", "12345", | ||
"email", "ankit@example.com", | ||
"phone", "555-555-5555", | ||
"parent_name", "Parent Name", | ||
"parent_phone", "555-555-5556", | ||
"parent_email", "parent@example.com", | ||
"guardian_name", "Guardian Name", | ||
"guardian_phone", "555-555-5557", | ||
"guardian_email", "guardian@example.com", | ||
"emergency_contact", "Emergency Contact", | ||
"emergency_phone", "555-555-5558", | ||
"emergency_relationship", "Relative", | ||
"class", "10th Grade", | ||
"section", "A", | ||
"school", "Random High School" | ||
] | ||
console.log("data == ", toConvertArrayJson(data)); | ||
module.exports = { | ||
convertUpperCase: async (value) => { | ||
toConvertUpperCase: async (value) => { | ||
//check the type of the value | ||
if (typeof value != "string") { | ||
if (typeof value != "string" || !value || value === '') { | ||
return ""; | ||
@@ -11,5 +59,5 @@ } | ||
}, | ||
convertLowerCase: async (value) => { | ||
toConvertLowerCase: async (value) => { | ||
//check the type of the value | ||
if (typeof value != "string") { | ||
if (typeof value != "string" || !value || value === '') { | ||
return ""; | ||
@@ -20,20 +68,46 @@ } | ||
capitalizeCase: async (value) => { | ||
//check the type of the value | ||
if (typeof value != "string" || !value || value === '') { | ||
toConvertCapitalizeCase: async (value) => { | ||
try { | ||
//check the type of the value | ||
if (typeof value != "string" || !value || value === '') { | ||
return value; | ||
} | ||
//split the data | ||
let data = value.split(' '); | ||
let finalData = ''; | ||
//convert into capitalized data | ||
for (let i = 0; i < data.length; i++) finalData = finalData + data[i][0].toUpperCase() + data[i].slice(1) + " "; | ||
//check the final data is empty of not | ||
if (finalData.length > 0) finalData = finalData.trim(); | ||
return finalData; | ||
} catch (error) { | ||
return value; | ||
} | ||
}, | ||
//split the data | ||
let data = value.split(' '); | ||
let finalData = ''; | ||
toConvertArrayJson: async (value) => { | ||
try { | ||
if (typeof value != "object" || value.length === 0) { | ||
return {}; | ||
} | ||
//convert into capitalized data | ||
for (let i = 0; i < data.length; i++) finalData = finalData + data[i][0].toUpperCase() + data[i].slice(1) + " "; | ||
let finalJson = {}; | ||
//check the final data is empty of not | ||
if (finalData.length > 0) finalData = finalData.trim(); | ||
for (let i = 0; i < value.length; i++) { | ||
if (finalJson.hasOwnProperty(value[i])) { | ||
finalJson[`d_${value[i]}`] = value[++i] || ''; | ||
continue; | ||
} | ||
finalJson[value[i]] = value[++i] || ''; | ||
} | ||
return finalJson; | ||
return finalData; | ||
} catch (error) { | ||
return {}; | ||
} | ||
} | ||
} |
{ | ||
"name": "conversikit", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "convert anything", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
}, | ||
"author": "", | ||
"author": "Arun Pradhan", | ||
"license": "ISC", | ||
@@ -16,0 +16,0 @@ "bugs": { |
101
README.md
# conversikit | ||
convert anything | ||
<b>convertUpperCase(value) :-</b> its used for update all letter to upper case | ||
<b>toConvertUpperCase(string) :-</b> its used for update all letter to upper case | ||
<b>toConvertLowerCase(string) :-</b> its used for update all letter to lower case | ||
<b>toConvertCapitalizeCase(string) :-</b> Convert into capitalize word. | ||
<b>toConvertArrayJson(array) :-</b> Convert a array to json format. | ||
<b>convertLowerCase(value) :-</b> its used for update all letter to lower case | ||
<h1>Example</h1> | ||
<code> | ||
const conversikit = require('conversikit'); | ||
@@ -15,7 +18,7 @@ | ||
let data = await conversikit.convertUpperCase("thank you my man"); //THANK YOU MY MAN | ||
let data = await conversikit.toConvertUpperCase("thank you my man"); //THANK YOU MY MAN | ||
let data1 = await conversikit.convertLowerCase("thank you my Man"); //thank you my man | ||
let data1 = await conversikit.toConvertLowerCase("thank you my Man"); //thank you my man | ||
let data1 = await conversikit.capitalizeCase("thank you my Man"); //Thank You My Man | ||
let data1 = await conversikit.toConvertCapitalizeCase("thank you my Man"); //Thank You My Man | ||
@@ -25,4 +28,90 @@ } | ||
d(); | ||
</code> | ||
<h1> Convert Array to JSON</h1> | ||
<code> | ||
const conversikit = require('conversikit'); | ||
let data = [ | ||
"name", "Ankit", | ||
"roll", "10", | ||
"age", "17", | ||
"gender", "Male", | ||
"address", "123 Main Street", | ||
"city", "Exampleville", | ||
"state", "ABC", | ||
"zipcode", "12345", | ||
"email", "ankit@example.com", | ||
"phone", "555-555-5555", | ||
"parent_name", "Parent Name", | ||
"parent_phone", "555-555-5556", | ||
"parent_email", "parent@example.com", | ||
"guardian_name", "Guardian Name", | ||
"guardian_phone", "555-555-5557", | ||
"guardian_email", "guardian@example.com", | ||
"emergency_contact", "Emergency Contact", | ||
"emergency_phone", "555-555-5558", | ||
"emergency_relationship", "Relative", | ||
"class", "10th Grade", | ||
"section", "A", | ||
"school", "Random High School" | ||
]; | ||
let data = await conversikit.toConvertArrayJson(data); | ||
console.log("Result = ",data); | ||
</code> | ||
<h5>Output ---></h5> | ||
<code> | ||
Result = { | ||
name: 'Ankit', | ||
roll: '10', | ||
age: '17', | ||
gender: 'Male', | ||
address: '123 Main Street', | ||
city: 'Exampleville', | ||
state: 'ABC', | ||
zipcode: '12345', | ||
email: 'ankit@example.com', | ||
phone: '555-555-5555', | ||
parent_name: 'Parent Name', | ||
parent_phone: '555-555-5556', | ||
parent_email: 'parent@example.com', | ||
guardian_name: 'Guardian Name', | ||
guardian_phone: '555-555-5557', | ||
guardian_email: 'guardian@example.com', | ||
emergency_contact: 'Emergency Contact', | ||
emergency_phone: '555-555-5558', | ||
emergency_relationship: 'Relative', | ||
class: '10th Grade', | ||
section: 'A', | ||
school: 'Random High School' | ||
} | ||
</code> | ||
<h5><b><u>If duplicate key is present in array -></u></b></h5> | ||
<code> | ||
let data = ["hi", "hello", "thank man", "you","good","hi", "hello", "thank man", "you","good","hi", "hello", "thank man", "you","good"]; | ||
let data1 = await conversikit.toConvertArrayJson(data); | ||
<p>Result:- | ||
{ | ||
hi: 'hello', | ||
'thank man': 'you', | ||
good: 'hi', | ||
hello: 'thank man', | ||
you: 'good', | ||
d_hi: 'hello', | ||
'd_thank man': 'you', | ||
d_good: '' | ||
} | ||
</p> | ||
</code> | ||
<center><h1>Thank You</h1></center> |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
6259
95
1
116