Show:
Module: parch

Represents a single route segment, providing a consistent output segment regardless of trailing/leading slashes

Table of Contents

Constructor

RouteSegment
(
  • segment
)

Parameters:

  • segment String

    A single route segment

Example:

new RouteSegment("/foo"); => { path: "/foo", segment: "/foo" }
new RouteSegment("foo"); => { path: "/foo", segment: "foo" }
new RouteSegment("/foo/"); => { path: "/foo", segment: "/foo/" }
new RouteSegment("foo/"); => { path: "/foo", segment: "foo/" }

Methods

_buildSegment () String

Builds a consistent path segment, regardless of slashes

Returns:

String:

path segment

hasLeadingSlash () Boolean

Determines if a path segment contains a leading slash /

Returns:

Example:

new RouteSegment("foo").hasLeadingSlash(); => false
new RouteSegment("foo/").hasLeadingSlash(); => false
new RouteSegment("/foo/").hasLeadingSlash(); => true
new RouteSegment("/foo").hasLeadingSlash(); => true
hasTrailingSlash () Boolean

Determines if a path segment contains a trailing slash /

Returns:

Example:

new RouteSegment("foo").hasTrailingSlash(); => false
new RouteSegment("/foo").hasTrailingSlash(); => false
new RouteSegment("/foo/").hasTrailingSlash(); => true
new RouteSegment("foo/").hasTrailingSlash(); => true

Properties

path

String

The normalized path segment after removing/adding slashes

segment

String

Segment represents the original path segment that was passed in