baidusearch-cli
v0.1.1
Published
A TypeScript library for searching Baidu (百度搜索) programmatically
Maintainers
Readme
baidusearch-cli
A TypeScript library for searching Baidu (百度搜索) programmatically. Inspired by library baidusearch-cli
Features
- 🚀 Simple and easy-to-use API
- 📦 Support both CommonJS and ES Modules
- 🔍 Get structured search results from Baidu
- 💪 Written in TypeScript with full type definitions
- 🛠️ CLI tool included
- ⚡ Built with modern tools (axios, cheerio)
- 🔄 Automated CI/CD with GitHub Actions
- 📝 Automatic changelog generation
Installation
npm install baidusearch-cliUsage
As a Library
import { search } from 'baidusearch-cli';
// Basic usage
const results = await search('Node.js');
console.log(results);
// With options
const results = await search('TypeScript', {
numResults: 20,
debug: true,
});
results.forEach((result) => {
console.log(`${result.rank}. ${result.title}`);
console.log(` ${result.abstract}`);
console.log(` ${result.url}\n`);
});As a CLI Tool
# Install globally
npm install -g baidusearch-cli
# Basic search
baidusearch-cli "Node.js"
# Specify number of results
baidusearch-cli "TypeScript" 20
# Enable debug mode
baidusearch-cli "JavaScript" 10 1Or use with npx:
npx baidusearch-cli "Node.js"API
search(keyword: string, options?: SearchOptions): Promise<SearchResult[]>
Search Baidu with the given keyword.
Parameters
keyword(string): The search keyword (required)options(SearchOptions): Optional configurationnumResults(number): Number of results to return (default: 10)debug(boolean): Enable debug logging (default: false)
Returns
Promise of SearchResult[]:
interface SearchResult {
title: string; // Result title
abstract: string; // Result abstract/description
url: string; // Result URL
rank: number; // Result ranking
}Development
# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
# Lint code
npm run lint
npm run lint:fix
# Format code
npm run format
npm run format:check
# Type check
npm run type-check
# Run tests
npm testScripts
Build
npm run build- Build the projectnpm run dev- Watch mode for developmentnpm run type-check- Type check without emitting files
Code Quality
npm run lint- Lint TypeScript filesnpm run lint:fix- Fix linting issuesnpm run format- Format code with Prettiernpm run format:check- Check code formatting
Release
npm run release- Create a new release (auto-detects version bump)npm run release:patch- Create a patch release (1.0.x)npm run release:minor- Create a minor release (1.x.0)npm run release:major- Create a major release (x.0.0)
CI/CD
This project uses GitHub Actions for continuous integration and deployment:
Workflows
CI (
.github/workflows/ci.yml)- Runs on every push and pull request
- Lints code with ESLint
- Builds the project on Node.js 16, 18, and 20
- Runs tests
Release (
.github/workflows/release.yml)- Triggers on version tags (e.g.,
v1.0.0) - Automatically generates changelog
- Creates GitHub release
- Publishes to NPM
- Triggers on version tags (e.g.,
Publish (
.github/workflows/publish.yml)- Manual workflow for publishing
- Bumps version
- Updates CHANGELOG.md
- Publishes to NPM
- Creates GitHub release
CodeQL (
.github/workflows/codeql.yml)- Security scanning
- Runs weekly and on pushes to main
Commitlint (
.github/workflows/commitlint.yml)- Validates commit messages follow conventional commits
Publishing
Option 1: Manual Release
# Create a new release locally
npm run release:patch # or minor/major
# Push tags
git push --follow-tags origin main
# The release workflow will automatically publish to NPMOption 2: GitHub Actions Workflow
- Go to Actions tab in GitHub
- Select "Publish" workflow
- Click "Run workflow"
- Choose version bump type (patch/minor/major)
- The workflow will handle version bump, changelog, and publishing
Setup Required
To enable automated publishing, add these secrets to your GitHub repository:
NPM_TOKEN- Your NPM automation token (https://www.npmjs.com/settings/~/tokens)
Contributing
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
Commit Message Convention
This project follows Conventional Commits:
feat: add new feature
fix: bug fix
docs: documentation changes
style: formatting, missing semi colons, etc
refactor: code refactoring
perf: performance improvements
test: add missing tests
chore: maintenance tasksLicense
MIT
Credits
This TypeScript version is based on the original Python implementation.
