npm-pack 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
npm_pack/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ """Source bundle of JavaScript, TypeScript, JSX, and CSS learning modules."""
2
+
3
+ from importlib.resources import files
4
+
5
+
6
+ def module_directory():
7
+ """Return the installed directory containing the bundled source files."""
8
+ return files(__package__).joinpath("modules")
9
+
10
+
11
+ __all__ = ["module_directory"]
File without changes
npm_pack/modules/p1.js ADDED
@@ -0,0 +1,36 @@
1
+ const fs = require("fs");
2
+ // Node.js fundamentals
3
+ console.log("=== Node.js Fundamentals ===");
4
+ const name = "Node.js";
5
+ const version = 1;
6
+ const isAsynchronous = true;
7
+ console.log("Name:", name);
8
+ console.log("Version:", version);
9
+ console.log("Asynchronous:", isAsynchronous);
10
+ function greet(user) {
11
+ return `Hello, ${user}!`;
12
+ }
13
+ console.log(greet("Student"));
14
+ // File handling
15
+ console.log("=== File Handling ===");
16
+ fs.writeFileSync("test.txt", "Hello Node.js");
17
+ console.log("File written successfully");
18
+ // Event loop
19
+ console.log("1. Start");
20
+ fs.readFile("test.txt", "utf8", (err, data) => {
21
+ if (err) {
22
+ console.error("File read error:", err.message);
23
+ return;
24
+ }
25
+ console.log("6. File read:", data);
26
+ });
27
+ process.nextTick(() => {
28
+ console.log("3. nextTick");
29
+ });
30
+ Promise.resolve().then(() => {
31
+ console.log("4. Promise");
32
+ });
33
+ setTimeout(() => {
34
+ console.log("5. setTimeout");
35
+ }, 0);
36
+ console.log("2. End");
npm_pack/modules/p2.js ADDED
@@ -0,0 +1,28 @@
1
+
2
+ const express = require("express");
3
+ const app = express();
4
+ // Root route - HTTP response
5
+ app.get("/", (req, res) => {
6
+ res.status(200).send("Welcome to Express.js");
7
+ });
8
+ // 201 - Created
9
+ app.get("/created", (req, res) => {
10
+ res.status(201).send("Resource created");
11
+ });
12
+ // 400 - Bad Request
13
+ app.get("/bad", (req, res) => {
14
+ res.status(400).send("Bad request");
15
+ });
16
+ // 404 - Not Found
17
+ app.get("/notfound", (req, res) => {
18
+ res.status(404).send("Resource not found");
19
+ });
20
+ // Custom response headers
21
+ app.get("/headers", (req, res) => {
22
+ res.set("X-Custom-Header", "AWT-Practical");
23
+ res.set("Content-Type", "text/plain");
24
+ res.status(200).send("Custom headers sent");
25
+ });
26
+ app.listen(3000, () => {
27
+ console.log("Server running on port 3000");
28
+ });
@@ -0,0 +1,27 @@
1
+ const mongoose = require("mongoose");
2
+ // User schema
3
+ const userSchema = new mongoose.Schema({
4
+ name: { type: String, required: true },
5
+ email: { type: String, required: true, unique: true, lowercase: true },
6
+ age: { type: Number, min: 0, max: 120 },
7
+ role: { type: String, enum: ["student", "admin"], default: "student" }
8
+ });
9
+ // Post schema - referencing
10
+ const postSchema = new mongoose.Schema({
11
+ title: { type: String, required: true },
12
+ body: String,
13
+ author: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true }
14
+ });
15
+ // Order schema - embedding
16
+ const orderSchema = new mongoose.Schema({
17
+ customer: { type: String, required: true },
18
+ items: [{ product: { type: String, required: true }, quantity: { type: Number, default: 1, min: 1 }, price: { type: Number, required: true, min: 0 } }]
19
+ });
20
+ // Virtual field
21
+ orderSchema.virtual("total").get(function() {
22
+ return this.items.reduce((sum, item) => sum + item.price * item.quantity, 0);
23
+ });
24
+ const User = mongoose.model("User", userSchema);
25
+ const Post = mongoose.model("Post", postSchema);
26
+ const Order = mongoose.model("Order", orderSchema);
27
+ module.exports = { User, Post, Order };
@@ -0,0 +1,25 @@
1
+ const mongoose = require("mongoose");
2
+ const { User, Post, Order } = require("./p3a");
3
+ async function main() {
4
+ await mongoose.connect("mongodb://127.0.0.1:27017/awt");
5
+ console.log("MongoDB Connected");
6
+ // Create user
7
+ const user = await User.create({ name: "John", email: "john@gmail.com", age: 21 });
8
+ console.log("User:", user);
9
+ // Validation
10
+ try {
11
+ await User.create({ email: "test@gmail.com", age: 150 });
12
+ } catch (err) {
13
+ console.log("Validation Error:", err.message);
14
+ }
15
+ // Referencing
16
+ const post = await Post.create({ title: "MongoDB Models", body: "Learning Mongoose", author: user._id });
17
+ const result = await Post.findById(post._id).populate("author");
18
+ console.log("Post:", result);
19
+ // Embedding
20
+ const order = await Order.create({ customer: "John", items: [{ product: "Book", quantity: 2, price: 50 }, { product: "Pen", price: 10 }] });
21
+ console.log("Order:", order);
22
+ console.log("Total:", order.total);
23
+ await mongoose.disconnect();
24
+ }
25
+ main().catch(err => console.log(err));
npm_pack/modules/p4.js ADDED
@@ -0,0 +1,16 @@
1
+ const express = require("express");
2
+ const mongoose = require("mongoose");
3
+ const studentRoutes = require("./routes/p4c");
4
+ const app = express();
5
+ app.use(express.json());
6
+ app.use("/students", studentRoutes);
7
+ mongoose
8
+ .connect("mongodb://127.0.0.1:27017/awt")
9
+ .then(() => {
10
+ console.log("MongoDB Connected");
11
+ app.listen(3000, () => {
12
+ console.log("Server running on port 3000");
13
+ });
14
+ })
15
+ .catch(err => console.log("MongoDB connection error:", err.message));
16
+
@@ -0,0 +1,25 @@
1
+ const Student = require("../models/p4b");
2
+ // Create
3
+ exports.create = async (req, res) => {
4
+ const student = await Student.create(req.body);
5
+ res.json(student);
6
+ };
7
+ // Read
8
+ exports.getAll = async (req, res) => {
9
+ const students = await Student.find();
10
+ res.json(students);
11
+ };
12
+ // Update
13
+ exports.update = async (req, res) => {
14
+ const student = await Student.findByIdAndUpdate(
15
+ req.params.id,
16
+ req.body,
17
+ { new: true }
18
+ );
19
+ res.json(student);
20
+ };
21
+ // Delete
22
+ exports.remove = async (req, res) => {
23
+ await Student.findByIdAndDelete(req.params.id);
24
+ res.json({ message: "Student deleted" });
25
+ };
@@ -0,0 +1,8 @@
1
+
2
+ const mongoose = require("mongoose");
3
+ const studentSchema = new mongoose.Schema({
4
+ name: String,
5
+ email: String,
6
+ age: Number
7
+ });
8
+ module.exports = mongoose.model("Student", studentSchema);
@@ -0,0 +1,8 @@
1
+ const express = require("express");
2
+ const router = express.Router();
3
+ const controller = require("../controllers/p4a");
4
+ router.post("/", controller.create);
5
+ router.get("/", controller.getAll);
6
+ router.put("/:id", controller.update);
7
+ router.delete("/:id", controller.remove);
8
+ module.exports = router;
@@ -0,0 +1,35 @@
1
+
2
+ const username: string = "John";
3
+ const age: number = 21;
4
+ const isStudent: boolean = true;
5
+ console.log(username, age, isStudent);
6
+ // Typed function
7
+ function add(a: number, b: number): number {
8
+ return a + b;
9
+ }
10
+ console.log("Sum:", add(10, 20));
11
+ // Optional parameter
12
+ function greet(name: string, title?: string): string {
13
+ return title ? `${title} ${name}` : `Hello, ${name}`;
14
+ }
15
+ console.log(greet("John"));
16
+ console.log(greet("John", "Mr."));
17
+ // Interface
18
+ interface User {
19
+ id: number;
20
+ name: string;
21
+ email?: string;
22
+ }
23
+ function displayUser(user: User): string {
24
+ return `${user.id} - ${user.name} - ${user.email ?? "No email"}`;
25
+ }
26
+ console.log(displayUser({
27
+ id: 1,
28
+ name: "John"
29
+ }));
30
+ // Union type
31
+ function showId(id: number | string): void {
32
+ console.log("ID:", id);
33
+ }
34
+ showId(101);
35
+ showId("ABC");
@@ -0,0 +1,32 @@
1
+
2
+ const marks: number[] = [75, 82, 90, 68];
3
+ console.log("Marks:", marks);
4
+ console.log("Sorted:", [...marks].sort((a, b) => a - b));
5
+ // Tuple
6
+ const student: [string, number] = ["John", 85];
7
+ console.log("Name:", student[0]);
8
+ console.log("Marks:", student[1]);
9
+ // Record
10
+ const prices: Record<string, number> = {
11
+ apple: 30,
12
+ banana: 10,
13
+ mango: 50
14
+ };
15
+ console.log("Banana:", prices["banana"]);
16
+ // Map
17
+ const scores = new Map<string, number>();
18
+ scores.set("John", 95);
19
+ scores.set("Rahul", 88);
20
+ console.log("John score:", scores.get("John"));
21
+ // Set
22
+ const subjects = new Set<string>(["Java", "Python", "Java", "React"]);
23
+ console.log("Subjects:", [...subjects]);
24
+ // Generic function
25
+ function first<T>(items: T[]): T | undefined {
26
+ return items[0];
27
+ }
28
+ console.log("First number:", first([10, 20, 30]));
29
+ console.log("First name:", first(["John", "Rahul"]));
30
+ // Array method
31
+ const total = marks.reduce((sum, mark) => sum + mark, 0);
32
+ console.log("Total:", total);
npm_pack/modules/p6.ts ADDED
@@ -0,0 +1,79 @@
1
+ // Base class
2
+ class Animal {
3
+ constructor(protected name: string, readonly legs: number) {}
4
+ describe(): string {
5
+ return '${this.name} has ${this.legs} legs';
6
+ }
7
+ makeSound(): string {
8
+ return '${this.name} makes a sound';
9
+ }
10
+ }
11
+ // Inheritance
12
+ class Dog extends Animal {
13
+ constructor(name: string) {
14
+ super(name, 4);
15
+ }
16
+ makeSound(): string {
17
+ return '${this.name} says Woof!';
18
+ }
19
+ }
20
+ class Bird extends Animal {
21
+ constructor(name: string) {
22
+ super(name, 2);
23
+ }
24
+ makeSound(): string {
25
+ return '${this.name} says Tweet!';
26
+ }
27
+ fly(): string {
28
+ return '${this.name} flies';
29
+ }
30
+ }
31
+ const dog = new Dog("Rex");
32
+ const bird = new Bird("Robin");
33
+ console.log(dog.describe());
34
+ console.log(dog.makeSound());
35
+ console.log(bird.makeSound());
36
+ console.log(bird.fly());
37
+ // Polymorphism
38
+ const animals: Animal[] = [dog, bird];
39
+ for (const animal of animals) {
40
+ console.log(animal.makeSound());
41
+ }
42
+ // Abstract class
43
+ abstract class Shape {
44
+ abstract area(): number;
45
+ display(): string {
46
+ return `Area: ${this.area()}`;
47
+ }
48
+ }
49
+ class Circle extends Shape {
50
+ constructor(private radius: number) {
51
+ super();
52
+ }
53
+ area(): number {
54
+ return Math.PI * this.radius ** 2;
55
+ }
56
+ }
57
+ class Rectangle extends Shape {
58
+ constructor(private width: number, private height: number) {
59
+ super();
60
+ }
61
+ area(): number {
62
+ return this.width * this.height;
63
+ }
64
+ }
65
+ console.log(new Circle(5).display());
66
+ console.log(new Rectangle(4, 3).display());
67
+ // Interface
68
+ interface Drivable {
69
+ speed: number;
70
+ drive(): string;
71
+ }
72
+ class Car implements Drivable {
73
+ speed = 0;
74
+ drive(): string {
75
+ this.speed = 60;
76
+ return `Driving at ${this.speed} km/h`;
77
+ }
78
+ }
79
+ console.log(new Car().drive());
@@ -0,0 +1,10 @@
1
+ function Student(props) {
2
+ return (
3
+ <div className="student">
4
+ <h2>{props.name}</h2>
5
+ <p>Course: {props.course}</p>
6
+ <p>Marks: {props.marks}</p>
7
+ </div>
8
+ );
9
+ }
10
+ export default Student
@@ -0,0 +1,14 @@
1
+ import Student from "./components/p7a";
2
+ import "./App.css";
3
+
4
+ function App() {
5
+ return (
6
+ <div className="app">
7
+ <h1>Student Details</h1>
8
+ <Student name="John" course="MSc Computer Science" marks={85} />
9
+ <Student name="Rahul" course="MSc Computer Science" marks={78} />
10
+ <Student name="Priya" course="MSc Computer Science" marks={91} />
11
+ </div>
12
+ );
13
+ }
14
+ export default App;
@@ -0,0 +1,14 @@
1
+ import Student from "./components/p7a";
2
+ import "./App.css";
3
+
4
+ function App() {
5
+ return (
6
+ <div className="app">
7
+ <h1>Student Details</h1>
8
+ <Student name="John" course="MSc Computer Science" marks={85} />
9
+ <Student name="Rahul" course="MSc Computer Science" marks={78} />
10
+ <Student name="Priya" course="MSc Computer Science" marks={91} />
11
+ </div>
12
+ );
13
+ }
14
+ export default App;
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: npm-pack
3
+ Version: 0.1.0
4
+ Summary: A bundle of JavaScript, TypeScript, JSX, and CSS learning modules.
5
+ Keywords: javascript,typescript,jsx,learning,source-bundle
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Programming Language :: JavaScript
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Topic :: Education
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+
13
+ # npm-pack
14
+
15
+ `npm-pack` is a Python-installable source bundle of the JavaScript, TypeScript,
16
+ JSX, and CSS exercises in this project. The bundled files are source assets;
17
+ this package does not translate them into Python modules.
18
+
19
+ ## Install
20
+
21
+ ```console
22
+ python -m pip install npm-pack
23
+ ```
24
+
25
+ The project name on PyPI is `npm-pack`; in Python code, its import name is
26
+ `npm_pack`.
27
+
28
+ ## Locate the source files
29
+
30
+ ```python
31
+ from npm_pack import module_directory
32
+
33
+ print(module_directory())
34
+ ```
35
+
36
+ The bundled modules are in the `modules` directory. Run JavaScript with Node.js,
37
+ and use appropriate TypeScript/React tooling for `.ts` and `.jsx` files.
38
+ Some examples need dependencies and services such as Express, Mongoose, or a
39
+ local MongoDB server.
40
+
41
+ ## Included files
42
+
43
+ `p1.js`, `p2.js`, `p3a.js`, `p3b.js`, `p4.js`, `p4a.js`, `p4b.js`, `p4c.js`,
44
+ `p5a.ts`, `p5b.ts`, `p6.ts`, `p7a.jsx`, `p7b.jsx`, and `p7c.css`.
45
+
46
+ ## Build locally
47
+
48
+ ```console
49
+ python -m pip install build
50
+ python -m build
51
+ ```
52
+
53
+ The PyPI project name must be available when you publish. The current source
54
+ files are included in the distribution, but creating a PyPI account and
55
+ publishing are separate steps.
56
+
57
+ Choose a license before publishing. No license is declared for this source bundle yet.
@@ -0,0 +1,20 @@
1
+ npm_pack/__init__.py,sha256=CkASjgefpUiaP-lYrnYpwwppFKWQCYfsGZnuO4_rH_M,305
2
+ npm_pack/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ npm_pack/modules/p1.js,sha256=3kIHtWiqSYbd9NIoJqYGoYLXvLvh5NsLJ4nfV0B-1V8,954
4
+ npm_pack/modules/p2.js,sha256=QJ3pRgiDYIm2qjrdMczzEW7yIF0QqOKFz5jxtwEuR1M,780
5
+ npm_pack/modules/p3a.js,sha256=oLt7rN4dYJWfmRxG9bw_xKhppRW9Z1vIf6i-gwE7y9Q,1179
6
+ npm_pack/modules/p3b.js,sha256=SKyGFhGttraDFe9OBQuhvIrfRaGm_8OMyZpw1FLM-UM,1044
7
+ npm_pack/modules/p4.js,sha256=OQUMbG_6ajTdLlUKTU4u58aYO6pJYXzy6MDhaim5pTo,494
8
+ npm_pack/modules/p4a.js,sha256=3H_uk2URzeC0gvb-0NxxBdUwYQ6gxKiDs-EBWGbdNS0,629
9
+ npm_pack/modules/p4b.js,sha256=CuHexP89bvIyV00bJ9lBPpMqsr61xHpZeXNc8CHbSyo,199
10
+ npm_pack/modules/p4c.js,sha256=t9VT3TzJGIsKtsiOn-e7XeW8ecJMIqTdY1-zYDPHkCo,304
11
+ npm_pack/modules/p5a.ts,sha256=6hV-28hL4AQbtkhQxxUl5KdCiyxxKntg3TDzkPMqr1M,841
12
+ npm_pack/modules/p5b.ts,sha256=GulBXMDORTBVkF-VTMDINeQh7IhVC1AkKecNrmRVFFQ,986
13
+ npm_pack/modules/p6.ts,sha256=PeBipHMhU4JCnQAQmuzzsAviUqOvMqgTEAd3FgdqpxE,1763
14
+ npm_pack/modules/p7a.jsx,sha256=KNsVg-X0j2vYJH_1-ZsZL78Qg7FjhfHPbOosBH_bscw,214
15
+ npm_pack/modules/p7b.jsx,sha256=oZmp2rCVJmvEH0Gd_3NoQWoppQyHaY0eWT6OkLknwCs,413
16
+ npm_pack/modules/p7c.css,sha256=oZmp2rCVJmvEH0Gd_3NoQWoppQyHaY0eWT6OkLknwCs,413
17
+ npm_pack-0.1.0.dist-info/METADATA,sha256=F0DSxY4I4Kh6qHlShheTIzgwzfH9ntLUw-wuNNXwPKo,1724
18
+ npm_pack-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
+ npm_pack-0.1.0.dist-info/top_level.txt,sha256=ZM2DCr_EV1PxLy-IsATKUD3IwJeG8cFud5wPHAZ7uA4,9
20
+ npm_pack-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ npm_pack