Skip to content

Commit

Permalink
chore(*): -
Browse files Browse the repository at this point in the history
  • Loading branch information
enenumxela committed Feb 8, 2025
1 parent 23df270 commit ca2b305
Show file tree
Hide file tree
Showing 25 changed files with 551 additions and 538 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ package main
import (
"fmt"

"go.source.hueristiq.com/url/domain/parser"
"go.source.hueristiq.com/url/parser"
)

func main() {
p := parser.New()
p := parser.NewDomainParser()

parsed := p.Parse("subdomain.example.com")

Expand All @@ -108,7 +108,7 @@ import (
)

func main() {
p := parser.New()
p := parser.NewURLParser()

parsed, err := p.Parse("https://subdomain.example.com:8080/path/file.txt")
if err != nil {
Expand All @@ -131,7 +131,7 @@ func main() {
Set a default scheme:

```go
p := parser.NewParser(parser.WithDefaultScheme("https"))
p := parser.NewURLParser(parser.URLParserWithDefaultScheme("https"))
```

## Contributing
Expand Down
1 change: 0 additions & 1 deletion domain/doc.go

This file was deleted.

71 changes: 0 additions & 71 deletions domain/domain.go

This file was deleted.

1 change: 0 additions & 1 deletion domain/parser/doc.go

This file was deleted.

160 changes: 0 additions & 160 deletions domain/parser/parser.go

This file was deleted.

18 changes: 14 additions & 4 deletions extractor/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
// - Ability to handle ASCII and Unicode TLDs.
// - Extraction of IPv4, IPv6 addresses, and ports from URLs.
//
// Usage Example:
// Example Usage:
//
// extractor := New(WithScheme())
// regex := extractor.CompileRegex()
// urls := regex.FindAllString(text, -1) // Extracts URLs from text
// package main
//
// import (
// "fmt"
// "go.source.hueristiq.com/url/extractor"
// )
//
// func main() {
// e := extractor.New(extractor.WithScheme())
// regex := e.CompileRegex()
// urls := regex.FindAllString("Visit https://example.com", -1)
// fmt.Println(urls) // Output: ["https://example.com"]
// }
//
// This package is designed to be highly flexible, enabling developers to extract URLs
// from various sources while applying custom constraints as needed.
Expand Down
38 changes: 25 additions & 13 deletions extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Extractor struct {
// and default patterns based on whether the user requires a scheme or host.
//
// Returns:
// - regex: A compiled regular expression object for URL matching.
// - regex (*regexp.Regexp): A compiled regular expression object for URL matching.
//
// Example:
//
Expand Down Expand Up @@ -129,10 +129,10 @@ func (e *Extractor) CompileRegex() (regex *regexp.Regexp) {
return
}

// OptionFunc defines a function type for configuring Extractor instances.
// Option defines a function type for configuring Extractor instances.
// It allows users to pass options that modify the behavior of the Extractor, such as whether
// to include schemes or hosts in URL extraction.
type OptionFunc func(*Extractor)
type Option func(extractor *Extractor)

// Interface defines the interface that Extractor should implement.
// It ensures that Extractor has the ability to compile regex patterns for URL extraction.
Expand Down Expand Up @@ -271,11 +271,11 @@ var _ Interface = (*Extractor)(nil)
// to include URL schemes or hosts.
//
// Arguments:
// - options: A variadic list of OptionFunc to configure the Extractor.
// - options (...Option): A variadic list of Option to configure the Extractor.
//
// Returns:
// - *Extractor: A pointer to the configured Extractor instance.
func New(options ...OptionFunc) (extractor *Extractor) {
// - extractor (*Extractor): A pointer to the configured Extractor instance.
func New(options ...Option) (extractor *Extractor) {
extractor = &Extractor{}

for _, option := range options {
Expand All @@ -287,7 +287,10 @@ func New(options ...OptionFunc) (extractor *Extractor) {

// WithScheme returns an option function that configures the Extractor
// to require URL schemes in the extraction process.
func WithScheme() OptionFunc {
//
// Returns:
// - option (Option):
func WithScheme() (option Option) {
return func(e *Extractor) {
e.withScheme = true
}
Expand All @@ -297,8 +300,11 @@ func WithScheme() OptionFunc {
// a custom regex pattern for matching URL schemes.
//
// Arguments:
// - pattern: A regex pattern to match URL schemes.
func WithSchemePattern(pattern string) OptionFunc {
// - pattern (string): A regex pattern to match URL schemes.
//
// Returns:
// - option (Option):
func WithSchemePattern(pattern string) (option Option) {
return func(e *Extractor) {
e.withScheme = true
e.withSchemePattern = pattern
Expand All @@ -307,7 +313,10 @@ func WithSchemePattern(pattern string) OptionFunc {

// WithHost returns an option function that configures the Extractor
// to require URL hosts in the extraction process.
func WithHost() OptionFunc {
//
// Returns:
// - option (Option):
func WithHost() (option Option) {
return func(e *Extractor) {
e.withHost = true
}
Expand All @@ -317,8 +326,11 @@ func WithHost() OptionFunc {
// a custom regex pattern for matching URL hosts.
//
// Arguments:
// - pattern: A regex pattern to match URL hosts.
func WithHostPattern(pattern string) OptionFunc {
// - pattern (string): A regex pattern to match URL hosts.
//
// Returns:
// - option (Option):
func WithHostPattern(pattern string) (option Option) {
return func(e *Extractor) {
e.withHost = true
e.withHostPattern = pattern
Expand All @@ -330,7 +342,7 @@ func WithHostPattern(pattern string) OptionFunc {
// each string is properly escaped for use in regex matching.
//
// Arguments:
// - strs: A variadic list of strings to be matched.
// - strs (...string): A variadic list of strings to be matched.
//
// Returns:
// - string: A regex pattern matching any of the given strings.
Expand Down
Loading

0 comments on commit ca2b305

Please sign in to comment.