utils
utils
utils
Packages generic utilities
Metadata
| Instantiating |
- arrayFind
- arrayFromStringCommands
- combine
- createJavaUUID
- deleteQueryVariable
- extends
- fixURL
- generateRandomString
- getComponents
- getPath
- init
- insertQueryVariable
- isGeneratedRandomString
- javaUUIDtoCFUUID
- listContainsAny
- listContainsAnyNoCase
- listDiff
- listExtends
- listFilter
- listIntersection
- listMerge
- listReverse
- listSlice
- normaliseFileList
- prettyDate
- struct
- structCreate
- structMerge
arrayFind()
Returns the index of the first element that matches the specified value. 0 if not found.
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| ar | array | Yes | The array to search | ||
| value | Any | Yes | The value to find |
arrayFromStringCommands()
This function is used to build an array of items from a set of defaults, and also a string of commands to add or subtract items form the default. For example, core defines a list of internet spider user agents ("google,slurp,meany,java"), and you may want to use all of them except "java" and also add two called "blarg" and "yuck". You can do that with this function like so:
arrayFromStringCommands("google,slurp,meany,java", "*:-java,+blarg,yuck")
Currently, this function is only used for the above mentioned example, however it might be useful in the future to allow plugins to be added and removed at runtime.
This function is defined in Application.cfc because it is used on FarCry init. It is here (utils.cfc) for Unit testing, and the possibility of future use.
Examples
#application.fapi.plusMinusStateMachine(myUglyDate)#
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| asteriskDefaults | string | Yes | |||
| stateCommandString | string | Yes |
combine()
combines a list js or css files into a single file, which is output, and cached if caching is enabled. Returns the path to the cached file.
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| id | string | No | ID | an id that is used to prefix the combine file | |
| files | string | Yes | a delimited list of jss or css paths to combine | ||
| type | string | No | js,css | ||
| delimiter | string | No | , | the delimiter used in the provided paths string | |
| prepend | string | No | Content to be placed BEFORE all the included files | ||
| append | string | No | Content to be placed AFTER all the included files |
createJavaUUID()
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| None | |||||
deleteQueryVariable()
Deletes a var from a query string.
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| variable | string | Yes | The variable to remove | ||
| qs | string | No | [runtime expression] |
extends()
Returns true if the specified component extends another
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| desc | string | Yes | The component to test | ||
| anc | string | Yes | The ancestor to check for |
fixURL()
Refreshes the page with the specified query string values removed, replaced, or added. New values can be specified with a query string, struct, or named arguments.
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| url | string | No | [runtime expression] | The url to use | |
| removevalues | string | No | List of values to remove from the query string. Prefix with '+' to remove these values in addition to the defaults. | ||
| addvalues | any | No | A query string or a struct of values, to add to the query string | ||
| ampDelim | string | No | & | Delimiter to use for ampersands | |
| charset | string | No | utf-8 | The character encoding in which the url values are encoded. |
generateRandomString()
Generate a very-hard-to-predict 40-character string
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| seed | string | No | An optional random-looking string (like a UUID) to add a few more bits of randomness |
getComponents()
Returns a list of components for a package
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| package | string | Yes | |||
| locations | string | No | |||
| path | struct | No | [runtime expression] |
getPath()
Finds the component in core/plugins/project, and returns its path
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| package | string | Yes | |||
| component | string | Yes | |||
| locations | string | No | |||
| path | struct | No | [runtime expression] | Application file paths | |
| projectDirectoryName | string | No | [runtime expression] | ||
| scope | string | No | ONE | ONE: return path of first matching component only. ALL: return a list of all matching paths. |
init()
Constructor
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| aJarPaths | array | No | [runtime expression] |
insertQueryVariable()
Inserts the specified key and value, replacing the existing value for that key
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| url | string | Yes | The url to modify | ||
| key | string | Yes | The key to insert | ||
| value | string | Yes | The value to insert | ||
| ampDelim | string | No | & | Delimiter to use for ampersands | |
| charset | string | No | utf-8 | The character encoding in which the url values are encoded. |
isGeneratedRandomString()
Return true if the given string looks like it came from generateRandomString()
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| testString | string | Yes |
javaUUIDtoCFUUID()
Most java generators generate UUIDs in a form that do not conform to CFs UUID format. This fixes them.
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| sJavaUUID | String | Yes |
listContainsAny()
Returns true if the first list contains any of the items in the second list
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list1 | string | Yes | The list being searched | ||
| list2 | string | Yes | The list of search terms | ||
| delimiters | string | No | , | Delimiters used by lists |
listContainsAnyNoCase()
Returns true if the first list contains any of the items in the second list
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list1 | string | Yes | The list being searched | ||
| list2 | string | Yes | The list of search terms | ||
| delimiters | string | No | , | Delimiters used by lists |
listDiff()
Returns the items in list2 that aren't in list2
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list1 | string | Yes | |||
| list2 | string | Yes | |||
| delimiters | string | No | , |
listExtends()
Returns a list of the components the specified one extends (inclusive)
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| path | string | Yes | The package path of the component |
listFilter()
Filters the items in a list though a regular expression
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list | string | Yes | The list being filtered | ||
| filter | string | Yes | The regular expression to filter by | ||
| delimiters | string | No | , | Delimiters used by list |
listIntersection()
Returns the items in list2 that are also in list2
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list1 | string | Yes | |||
| list2 | string | Yes | |||
| delimiters | string | No | , |
listMerge()
Adds items from the second list to the first, where they aren't already present
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list1 | string | Yes | The list being built on | ||
| list2 | string | Yes | The list being added | ||
| delimiters | string | No | , | The delimiters used the lists |
listReverse()
Reverses a list
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list | string | Yes | |||
| delimiters | string | No | , |
listSlice()
Returns the specified elements of the list
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| list | string | Yes | The list being sliced | ||
| start | numeric | No | 1 | The start index of the slice. Negative numbers are reverse indexes: -1 is last item. | |
| end | numeric | No | -1 | The end index of the slice. Negative values are reverse indexes: -1 is last item. | |
| delimiters | string | No | , | Delimiters used by list |
normaliseFileList()
Turns a list of relative file paths, and a single base path, and normalises them into a single list
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| baseHREF | string | No | The base path | ||
| lFiles | string | Yes | The list of relative file paths |
prettyDate()
This is a private version of the function. Do not call this function directly. Please use the fapi.cfc version
Provides date formatting in the style of Twitter’s timeline: "just now", "5 minutes ago", "yesterday", "2 weeks ago".
Examples
#application.fapi.prettyDate(myUglyDate)#
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| uglyDate | string | Yes | |||
| bUseTime | boolean | No | true | Should the comparison include the time part in its equation. |
struct()
This Package has been deprecated.
Shortcut for creating structs
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| None | |||||
structCreate()
This Package has been deprecated.
Creates and populates a struct with the provided arguments
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| None | |||||
structMerge()
Performs a deep merge on two structs
Arguments
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| struct1 | struct | Yes | |||
| struct2 | struct | Yes | |||
| replace | boolean | No | true |