8000 -- initial commit -- · jspython-dev/jspython-examples@da74047 · GitHub
[go: up one dir, main page]

Skip to content

Commit da74047

Browse files
committed
-- initial commit --
0 parents  commit da74047

File tree

11 files changed

+194
-0
lines changed

11 files changed

+194
-0
lines changed

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/release
8+
/lib
9+
/docs
10+
/md-docs
11+
12+
# dependencies
13+
/node_modules
14+
15+
# IDEs and editors
16+
/.idea
17+
.project
18+
.classpath
19+
.c9/
20+
*.launch
21+
.settings/
22+
*.sublime-workspace
23+
24+
# IDE - VSCode
25+
.vscode/*
26+
!.vscode/settings.json
27+
!.vscode/tasks.json
28+
!.vscode/launch.json
29+
!.vscode/extensions.json
30+
31+
# misc
32+
/.sass-cache
33+
/connect.lock
34+
/coverage
35+
/libpeerconnection.log
36+
npm-debug.log
37+
yarn-error.log
38+
testem.log
39+
/typings
40+
41+
# System Files
42+
.DS_Store
43+
Thumbs.db
44+
45+
package-lock.json
46+
*.tgz

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"*.jspy": "python"
4+
},
5+
"typescript.tsdk": "node_modules\\typescript\\lib"
6+
}

axios-test.jspy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import axios
2+
res = axios.get("https://restcountries.eu/rest/v2")
3+
print(res.data.length)
4+
print(res.data[236].name)

data/csv-sample.csv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
OrderId,OrderDate,OrderPriority,OrderQuantity,Sales,Discount,ShipMode,Profit,UnitPrice,ShippingCost,CustomerName,Country,City,CustomerSegment,ProductCategory,ProductSubCategory,ProductName,ProductContainer,ProductBaseMargin,ShipDate
2+
1,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Critical,24,159.43,0.05,Regular Air,-120.59,6.48,8.73,Sally Hughsby,Brazil,Campinas,Consumer,Office Supplies,Paper,Xerox 227,Small Box,0.37,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
3+
2,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Medium,1,187.2,0.01,Regular Air,-796.76,205.99,5.26,Kelly Williams,Germany,München,Corporate,Technology,Telephones and Communication,i470,Small Box,0.56,Sun Feb 26 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
4+
3,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Medium,5,235.49,0.06,Regular Air,21.78,47.9,5.86,Peter Buhler,Switzerland,Geneve,Consumer,Office Supplies,Paper,Xerox 1938,Small Box,0.37,Mon Feb 27 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
5+
4,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Not Specified,46,3725.53,0,Regular Air,748.67,76.72,19.95,John Lucas,USA,Portland,Corporate,Office Supplies,Appliances,Honeywell Enviracaire® Portable Air Cleaner for up to 8 x 10 Room,Large Box,0.54,Mon Feb 27 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
6+
5,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Not Specified,46,225.13,0.01,Express Air,-205.75,4.48,7.24,Raymond Book,France,Lyon,Consumer,Furniture,Office Furnishings,"Stacking Tray, Side-Loading, Legal, Smoke",Small Box,0.54,Mon Feb 27 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
7+
6,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),High,40,104.39,0.07,Regular Air,38.45,2.61,0.5,Emily Grady,UK,Cowes,Home Office,Office Supplies,Labels,Avery 494,Small Box,0.39,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
8+
7,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),,,677.43,0.1,Regular Air,75.48,50.98,22.24,Neil Knudson,USA,Portland,Corporate,Furniture,Office Furnishings,"Dana Fluorescent Magnifying Lamp, White, 36""",Large Box,0.55,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
9+
8,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Low,2,25.52,0.01,Regular Air,21.77,9.65,6.22,Henry MacAllister,France,Reims,Small Business,Furniture,Office Furnishings,"Eldon Expressions™ Desk Accessory, Wood Pencil Holder, Oak",Small Box,0.55,Fri Mar 03 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
10+
9,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Low,35,1599.07,0.04,Regular Air,296.66,55.99,3.3,Troy Blackwell,Venezuela,San Cristobal,Home Office,Technology,Telephones and Communication,Accessory24,Small Pack,0.59,
11+
10,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),,,3674.08,0.01,Delivery Truck,112.44,150.98,30,Craig Leslie,France,Versailles,Consumer,Furniture,Chairs & Chairmats,Novimex Swivel Fabric Task Chair,Jumbo Drum,0.74,Mon Feb 27 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
12+
11,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Medium,33,2269.41,0.05,Regular Air,630.18,70.97,3.5,Bobby Trafton,Finland,Oulu,Small Business,Office Supplies,Appliances,Tripp Lite Isotel 8 Ultra 8 Outlet Metal Surge,Small Box,0.59,Sun Feb 26 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
13+
12,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),,,159.11,0.07,Regular Air,64.01,5.43,0.95,Joy Smith,UK,Cowes,Consumer,Office Supplies,Paper,"Wirebound Message Book, 4 per Page",Wrap Bag,0.36,Wed Mar 01 2017 00:00:00 GMT+0200 (Eastern European Standard Time)
14+
13,Sat Feb 25 2017 00:00:00 GMT+0200 (Eastern European Standard Time),Low,5,20.28,0.05,Express Air,-4.32,2.98,2.03,Joni Wasserman,Switzerland,Geneve,Consumer,Office Supplies,Pens & Art Supplies,"Premium Writing Pencils, Soft,

data/save-test.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
prop1,prop2
2+
val10,val20
3+
val11,val21
4+
val12,val22

data/save-test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"prop1":"val10","prop2":"val20"},{"prop1":"val11","prop2":"val21"},{"prop1":"val12","prop2":"val22"}]

p-test.jspy

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import p-utils as
2+
3+
# test array
4+
arr = [1,2,3,4]
5+
# print(P)
6+
P.Array.extendPrototype()
7+
avg = arr.avg(arr)
8+
print(avg == 2.5, "Avg")
9+
10+
sum = P.Array.sum(arr)
11+
print(sum == 10, "Sum")
12+
13+
count = P.Array.count(arr)
14+
print(count == 4, "Count")
15+
16+
min = P.Array.min(arr)
17+
print(min == 1, "Min")
18+
19+
max = P.Array.max(arr)
20+
print(max == 4, "Max")
21+
22+
objArr = [
23+
{value:1},
24+
{value:2},
25+
{value:3}
26+
]
27+
28+
avg = P.Array.avg(objArr, r => r.value)
29+
print(avg == 2, "Avg obj")
30+
31+
sum = P.Array.sum(objArr, r => r.value)
32+
print(sum == 6, "Sum obj")
33+
34+
count = P.Array.count(objArr, r => r.value)
35+
print(count == 3, "Count obj")
36+
37+
min = P.Array.min(objArr, r => r.value)
38+
print(min == 1, "Min obj")
39+
40+
max = P.Array.max(objArr, r => r.value)
41+
print(max == 3, "Max obj")
42+

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "project",
3+
"version": "1.0.0",
4+
"description": "JSPython example projects",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"dependencies": {
10+
"axios": "^0.19.0",
11+
"datapipe-js": "0.0.1",
12+
"papaparse": "^5.1.0"
13+
},
14+
"author": "",
15+
"license": "MIT"
16+
}

parse.jspy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import papaparse
2+
from fs import readFileSync as rfs, writeFileSync
3+
import json5 as JSON5
4+
5+
dataFolder = "./data/"
6+
content = rfs(dataFolder + "csv-sample.csv", "utf8")
7+
print(content)
8+
9+
res = papaparse.parse(content)
10+
print(res.data.length)
11+
saveData = [{
12+
"prop1": "val10",
13+
"prop2": "val20"
14+
}, {
15+
"prop1": "val11",
16+
"prop2": "val21"
17+
}, {
18+
"prop1": "val12",
19+
"prop2": "val22"
20+
}]
21+
csvData = papaparse.unparse(saveData)
22+
jsonData = JSON.stringify(saveData)
23+
writeFileSync(dataFolder + "save-test.csv", csvData)
24+
writeFileSync(dataFolder + "save-test.json", jsonData)
25+
savedContent = rfs(dataFolder + "save-test.json", "utf8")
26+
jsonRes = JSON5.parse(savedContent)
27+
print(jsonRes)
28+
print(papaparse)

readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# JSPython Examples
2+
3+
## Before you run
4+
Install cli
5+
```
6+
npm install @jspython-dev/jspython-cli -g
7+
```
8+
9+
go to project folder and install dependencies
10+
11+
```
12+
npm install
13+
```
14+
15+
Run project
16+
```
17+
jspython-cli test.jspy
18+
```
19+
20+

test.jspy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
print("|------------------------------|")
3+
print("| Welcome My JSPython program! |")
4+
print("|------------------------------|")
5+
x = [1, 2, 3, 4]
6+
x
7+
.map((r, i) =>
8+
v = r * i
9+
return v
10+
)
11+
.filter(r => r * r)
12+
.join(",")
13+

0 commit comments

Comments
 (0)
0