npm package: @palmthree-studio/meta-asn-filter
Description: Meta ASN Filter - A tool for filtering and processing ASN data
Author: Palmthree Studio
Latest version: 0.2.11

# Meta ASN Filter 🔍

[![npm version](https://badge.fury.io/js/%40palmthree-studio%2Fmeta-asn-filter.svg)](https://badge.fury.io/js/%40palmthree-studio%2Fmeta-asn-filter)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
[![Tests](https://img.shields.io/badge/tests-passing-brightgreen.svg)](https://github.com/palmthree-studio/meta-asn-filter)

> **High-performance IP address filtering for Meta/Facebook networks (ASN 32934)**

A lightweight, fast, and reliable TypeScript/JavaScript library to detect if an IP address belongs to Meta (formerly Facebook) infrastructure. Perfect for analytics, security filtering, bot detection, and network analysis.

## 🌟 **Star this repository if you find it useful!** ⭐

## 🚀 Features

- ✅ **Lightning fast** IP address detection
- ✅ **IPv4 and IPv6 support** - Complete coverage
- ✅ **TypeScript native** with full type definitions
- ✅ **ESM and CommonJS** compatible
- ✅ **Zero dependencies** runtime (uses cidr-matcher for efficiency)
- ✅ **Monthly updates** - Always up-to-date with latest Meta IP ranges
- ✅ **Comprehensive tests** with 100% coverage
- ✅ **Production ready** - Used in enterprise applications

## 📦 Installation

```bash
# npm
npm install @palmthree-studio/meta-asn-filter

# yarn
yarn add @palmthree-studio/meta-asn-filter

# pnpm
pnpm add @palmthree-studio/meta-asn-filter
```

## 🔧 Usage

### ES Modules (Recommended)

```typescript
import { isMetaIP } from "@palmthree-studio/meta-asn-filter";

// Check if an IP belongs to Meta/Facebook
console.log(isMetaIP("69.63.189.44")); // true - Meta IPv4
console.log(isMetaIP("2a03:2880::1")); // true - Meta IPv6
console.log(isMetaIP("8.8.8.8")); // false - Google DNS
console.log(isMetaIP("2001:4860:4860::8888")); // false - Google IPv6
```

### CommonJS

```javascript
const { isMetaIP } = require("@palmthree-studio/meta-asn-filter");

if (isMetaIP(userIP)) {
  console.log("Traffic from Meta/Facebook detected");
}
```

### Real-world Examples

#### Web Analytics Filtering

```typescript
import { isMetaIP } from "@palmthree-studio/meta-asn-filter";

function shouldTrackVisitor(ip: string): boolean {
  // Filter out Meta crawler traffic from analytics
  return !isMetaIP(ip);
}
```

#### Security & Rate Limiting

```typescript
import { isMetaIP } from "@palmthree-studio/meta-asn-filter";

function applyRateLimit(ip: string) {
  if (isMetaIP(ip)) {
    // Apply special rate limits for Meta services
    return { limit: 1000, window: "1h" };
  }
  return { limit: 100, window: "1h" };
}
```

#### Express.js Middleware

```typescript
import express from "express";
import { isMetaIP } from "@palmthree-studio/meta-asn-filter";

const app = express();

app.use((req, res, next) => {
  const clientIP = req.ip;
  if (isMetaIP(clientIP)) {
    req.isMeta = true;
  }
  next();
});
```

## 📊 Performance

- **~0.001ms** average lookup time
- **972 CIDR ranges** covered (as of latest update)
- **Memory efficient** - Optimized CIDR matching
- **No network calls** - All data bundled

## 🔄 Data Updates

The IP ranges are automatically updated **monthly** from the RADB (Routing Assets Database) to ensure accuracy. The package includes:

- All IPv4 and IPv6 ranges assigned to ASN 32934 (Meta)
- Deduplicated and optimized CIDR blocks
- Verified against official routing tables

## 🛠️ Development

### Building from Source

```bash
# Clone the repository
git clone https://github.com/palmthree-studio/meta-asn-filter.git
cd meta-asn-filter

# Install dependencies
npm install

# Refresh Meta IP data from RADB
npm run refresh

# Build the package
npm run build

# Run tests
npm test
```

### Available Scripts

- `npm run build` - Build ESM, CommonJS, and TypeScript definitions
- `npm run refresh` - Update Meta IP ranges from RADB
- `npm test` - Run Jest test suite
- `npm run dev` - Watch mode for development

## 🧪 Testing

The package includes comprehensive tests covering:

- IPv4 address detection
- IPv6 address detection
- Edge cases and invalid inputs
- Performance benchmarks

```bash
npm test
```

## 📋 API Reference

### `isMetaIP(ip: string): boolean`

Determines if an IP address belongs to Meta (ASN 32934).

**Parameters:**

- `ip: string` - IPv4 or IPv6 address to check

**Returns:**

- `boolean` - `true` if the IP belongs to Meta, `false` otherwise

**Throws:**

- No exceptions - Invalid IPs return `false`

## 🔍 SEO Keywords

IP filtering, Meta Facebook IP ranges, ASN 32934, IPv4 IPv6 detection, TypeScript IP library, network security, bot detection, web crawlers, social media filtering, CIDR matching, Node.js IP utilities

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🏢 About Palmthree Studio

Created and maintained by Younès ELAB [Palmthree Studio](https://github.com/palmthree-studio) - Building developer tools that just work.

## 🌟 Show Your Support

If this package helps you, please consider:

- ⭐ **Starring this repository**
- 🐛 **Reporting bugs or requesting features**
- 💝 **Contributing to the codebase**
- 📢 **Sharing with your network**

**[⭐ Star this repository now!](https://github.com/palmthree-studio/meta-asn-filter)** - It helps others discover this tool!

---

<div align="center">

**Made with ❤️ by [Palmthree Studio](https://github.com/palmthree-studio)**

[Report Bug](https://github.com/palmthree-studio/meta-asn-filter/issues) • [Request Feature](https://github.com/palmthree-studio/meta-asn-filter/issues) • [Documentation](https://github.com/palmthree-studio/meta-asn-filter#readme)

</div>