The SwiftUtilities package provides various tools and utility functions that are useful in sample code and in tests for those examples.
The included utility functions are as follows:
The String
class is extended with the following functions:
Generates a guaranteed-unique name which can be used for anything from unique strings in an array to names for files, S3 buckets, data objects, or any other named object.
-
withPrefix
: A string used at the beginning of the specified name. By default, no prefix is applied. -
withExtension
: A string specifying an extension to add to the end of the name, for file names. Do not include the period (".") in the string; it is added for you. By default, no extension is added. -
isValid
: A Boolean indicating whether or not the generated name should be a valid one. For the purposes of this function, it is assumed that a valid name cannot start with a comma (","), and should not include either numbers or the percent ("%") symbol. Between these, the resulting string is usually not valid for most use cases. By default, this isfalse
, which causes a valid name to be returned.
A String
containing the generated unique name. The name is a UUID,
although it might be altered based on the provided options.
Returns a Lorem Ipsum-style string containing the specified number of randomly
generated paragraphs. If paragraphs
is not specified, then five paragraphs of
Lorem Ipsum text are returned. Each paragraph is four to eight sentences long,
and each sentence contains three to nine words.
The Lorem Ipsum text is suitable for use in test files and example strings because it doesn't need translation and it doesn't unnecessarily make test code larger than necessary.
paragraphs
: The number of paragraphs to generate. If not specified, the resulting string contains five paragraphs.
A String
containing up to paragraphs
paragraphs of Lorem Ipsum-style
generated text.
This package includes automated tests for each function. Before you run the tests, make sure you configure your environment to allow access to AWS and download and install the Swift tools if you don't already have them.
To run the tests, make sure you have Swift installed, then issue the command
swift test
to run the tests.
$ cd SwiftUtilities
$ swift test
The tests will compile and run, outputting the results to the console. You can also run the tests in Xcode if you prefer.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0