-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
662573a
commit 16a06f6
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>NPM Package Search</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>NPM Package Search</h1> | ||
<div class="search-container"> | ||
<input type="text" id="search-input" placeholder="Enter package name"> | ||
<button id="search-button">Search</button> | ||
</div> | ||
<h2>Results:</h2> | ||
<div id="results"></div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const resultsDiv = document.getElementById('results'); | ||
resultsDiv.style.display = 'none'; | ||
|
||
document.getElementById('search-button').addEventListener('click', function() { | ||
const query = document.getElementById('search-input').value; | ||
fetch(`https://registry.npmjs.org/-/v1/search?text=${query}&size=10`) | ||
.then(response => { | ||
if (response.status === 429) { | ||
throw new Error('Rate limit exceeded. Please try again later.'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
resultsDiv.style.display = 'block'; | ||
resultsDiv.innerHTML = ''; | ||
if (data.objects.length === 0) { | ||
resultsDiv.innerHTML = '<p>No packages found.</p>'; | ||
} else { | ||
data.objects.forEach(pkg => { | ||
const pkgElement = document.createElement('div'); | ||
pkgElement.classList.add('package'); | ||
pkgElement.innerHTML = ` | ||
<h3><a href="https://www.npmjs.com/package/${pkg.package.name}" target="_blank">${pkg.package.name}</a></h3> | ||
<p>${pkg.package.description}</p> | ||
`; | ||
resultsDiv.appendChild(pkgElement); | ||
}); | ||
} | ||
}) | ||
.catch(error => { | ||
const resultsDiv = document.getElementById('results'); | ||
resultsDiv.innerHTML = `<p>Error: ${error.message}</p>`; | ||
console.error('Error fetching packages:', error); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
height: 100vh; | ||
background-image: linear-gradient(to top, #37ecba 0%, #72afd3 100%); | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
} | ||
|
||
.container { | ||
max-width: 800px; | ||
margin: 5rem auto 0; | ||
padding: 20px; | ||
border-radius: 8px; | ||
background: rgba(255, 255, 255, 0.8); | ||
backdrop-filter: blur(10px); | ||
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1); | ||
overflow-y: auto; | ||
} | ||
|
||
h1, h2 { | ||
text-align: center; | ||
} | ||
|
||
.search-container { | ||
display: flex; | ||
justify-content: center; | ||
margin-bottom: 20px; | ||
} | ||
|
||
input { | ||
width: 300px; | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px 0 0 4px; | ||
border-right: none; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
background-color: #007bff; | ||
color: white; | ||
border: none; | ||
border-radius: 0 4px 4px 0; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
#results { | ||
max-height: 400px; | ||
overflow-y: auto; | ||
border: 1px solid #ccc; | ||
padding: 10px; | ||
border-radius: 4px; | ||
} | ||
|
||
.package { | ||
margin: 10px 0; | ||
padding: 10px; | ||
border-bottom: 1px solid #ccc; | ||
} | ||
|
||
.package h3 { | ||
margin: 0; | ||
} | ||
|
||
.package p { | ||
margin: 5px 0; | ||
} | ||
|
||
.package a { | ||
text-decoration: none; | ||
color: #007bff; | ||
} | ||
|
||
.package a:hover { | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters