
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
github.com/sollniss/pattern
Go library to generate string patterns.
import (
"fmt"
"github.com/sollniss/pattern"
)
func main() {
gen := pattern.New(
pattern.Repeat(2, 4,
pattern.Repeat(5, 5, pattern.OneOfByte([]byte("1234567890"))),
pattern.Literal("-"),
pattern.Repeat(2, 4, pattern.OneOfRune([]rune("xyz"))),
pattern.Literal("-"),
),
pattern.Potentially(0.3, pattern.OneOfString([]string{"AAAA", "BBBB", "CCCC", "DDDD"})),
pattern.Literal("-"),
pattern.Shuffle(pattern.Literal("a"), pattern.Literal("b"), pattern.Literal("c")),
pattern.Sequence(1, 999, 4),
)
for i := 0; i < 10; i++ {
fmt.Println(gen.String())
}
}
Outputs:
58525-zzz-30662-yxx-71228-xz-21148-xyz--bca0001
22813-yzyx-74510-yx-40801-yzyz--cab0002
61736-yx-76951-yxxz--cab0003
79908-zxx-96321-zxz-71442-yz-DDDD-acb0004
97571-xz-87210-xy--cab0005
11168-zzz-34216-xy-92184-zz-13246-zxy--abc0006
76919-yx-13975-xx-34534-yyz--cab0007
99940-yzz-31787-yyx--acb0008
13386-zz-60143-yzy-47725-zzxx-CCCC-cab0009
53765-zzyx-87695-zyxz-74415-yxyz--cab0010
The package exposes an interface Part
which all generator fuctions implement. The generator returned by New
also implements this interface, which allows combination of multiple generators.
type Part interface {
// Append appends the Part to the output pattern.
Append([]byte) []byte
}
Group(p ...Part) Part
Group returns a Part
that wraps p
into a single Part
.
Repeat(min uint32, max uint32, p ...Part) Part
Repeat returns a Part
that repeats p
between min
and max
times randomly.
Potentially(c float64, p Part) Part
Potentially returns a Part
that will include p
with probability c
.
Literal(s string) Part
Literal returns a Part
that will always output s
.
OneOf(p ...Part) Part
OneOf returns a Part
that selects one of p
randomly in each iteration.
The package also provides the convenience functions OneOfString
, OneOfByte
and OneOfRune
.
Shuffle(p ...Part) Part
Shuffle returns a Part
that randomly rearranges p
in each iteration.
Sequence(start uint64, max uint64, width int) Part
Sequence returns a Part
that will on each iteration increment a number from start
to max
and display the number zero-padded to width
.
Sequence is thread safe.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.