-
Notifications
You must be signed in to change notification settings - Fork 1
Injections API
- Array
- TestingCallback
- DeduplicatingCallback
- Path
- String
- NSRange
Array object extensions.
Meta
- version: 2.0.0
- author: Martin Kopischke <[email protected]>
- license: MIT
Get the last array item for which a callback returns true.
-
callback
TestingCallback Function to execute on each value in the array. -
thisArg
any Object to use asthis
insidecallback
. -
Throws TypeError When
callback
is not a function.
Returns any The value of the last element in the array that satisfies the
provided testing function. Otherwise, undefined
is returned.
Meta
- since: 2.0.0
Get the index of the last array item for which a callback returns true.
-
callback
TestingCallback Function to execute on each value in the array. -
thisArg
any Object to use asthis
insidecallback
. -
Throws TypeError When
callback
is not a function.
Returns any The value of the last element in the array that satisfies the
provided testing function. Otherwise, -1
is returned.
Meta
- since: 2.0.0
Call a callback on every array value while it returns true.
-
callback
TestingCallback Function to execute on each value in the array. -
thisArg
any Object to use asthis
insidecallback
. -
Throws TypeError When
callback
is not a function.
Remove all undefined
and null
values from an array in-place.
Returns Array The compacted original array.
Get the common item subset of two arrays.
Returns Array The common subset of values.
Group array items by the value returned by a callback.
-
callback
TestingCallback Function to execute on each value in the array. -
thisArg
any Object to use asthis
insidecallback
. -
Throws TypeError When
callback
is not a function.
Returns object<any, Array> The grouped array items.
Hoist sub-array items into the main Array in-place.
Returns Array The flattened original array.
De-duplicate Array contents.
By default, this compares contents using Array.prototype.includes
.
-
callback
DeduplicatingCallback Function to execute on each value in the array. -
thisArg
any Object to use asthis
insidecallback
. -
Throws TypeError When
callback
is not a function.
Returns object<any, Array> The grouped array items.
Function that is called for every element of an array.
Type: Function
-
element
any The current element being processed in the array. -
index
number? The index of the current element being processed in the array. -
array
Array? The array the callback function was called upon.
Function to determine if an array element is unique.
Type: Function
-
uniqueValues
Array The current array of unique values. -
element
any The current element being processed in the source array.
Returns boolean Is the value unique?
Path object extensions.
Because JXA’s Path
object is a missed opportunity as long
as it is just a dumb equivalent to the AppleScript alias
.
This functionality is in the spirit of the Ruby Pathname
library,
i.e. Path object manipulation independently from the actual existence
of the designated object in the file system.
Meta
- version: 5.1.0
- author: Martin Kopischke <[email protected]>
- license: MIT
Split a Path into an array of part strings.
Convert a Path into an NSURL object.
Returns object The NSURL matching the path.
Convert a Path to its String representation when serialising to JSON.
Returns string
Check if the Path points to the same effective location as some other path. Paths are standardised before comparison, but not normalised (as that would exclude comparison of invalid paths).
Returns boolean
Check if a Path points to a file system object.
-
Does
boolean the path point to a file system object?
Meta
- since: 5.0.0
Check if a Path points to a volume.
-
Does
boolean the path point to a volume?
Meta
- since: 5.0.0
Check if a Path points to a directory.
-
Does
boolean the path point to a directory?
Meta
- since: 5.0.0
Check if a Path points to a (macOS) package.
-
Does
boolean the path point to a package?
Meta
- since: 5.0.0
Check if a Path points to a simple file.
-
Does
boolean the path point to a file?
Meta
- since: 5.0.0
Check if a Path points to a symbolic link.
-
Does
boolean the path point to a symlink?
Meta
- since: 5.0.0
Check if a Path points to a Finder alias.
-
Does
boolean the path point to an alias?
Meta
- since: 5.0.0
Reduce empty and current Path parts and resolve parent path parts
(where possible, see caveats in stringByStandardizingPath
API reference).
Returns Path
Resolve aliases and symlinks in a Path.
Standardises the path before resolving; when neither alias nor symlink are
part of the path, or the path is not matching a file system object, this is
equivalent to .standardize
- Throws Error When encountering an invalid Finder alias in the path.
Returns Path
Get the last part of a path.
-
The
string last path part.
Strip a path of its last component(s).
-
by
number Number of path components to strip from Path end. (optional, default1
)
Returns Path
Append (a) path part(s) to a path.
Returns Path
Get the extension of a Path.
-
The
string path extension.
Strip the extension from a Path. Note this also strips a trailing slash from a directory path.
Returns Path
Append an extension to a Path.
-
extension
string Extension to append to Path end.
Returns Path
Insert a suffix between the name and extension of a Path. Note this does not try to be smart in any way, so repeated uses will append multiple suffixes.
-
suffix
string The suffix to append to the base Path. -
separator
string The separator between base name and suffix. (optional, default'-'
)
var path = Path('/path/to/file.ext')
path = path.suffix('foo') // '/path/to/file-foo.ext'
path = path.suffix(3) // '/path/to/file-3.ext'
path = path.suffix(3) // '/path/to/file-3-3.ext'
// Find a unique number for a path copy, Finder-like:
var path = Path('/path/to/file.ext')
var index = 1
while (path.suffix(index).exists) index++
path = path.suffix(index)
Returns Path
Meta
- since: 5.0.0
Create a Path from a path string.
Unlike Path(string)
, this expands the home directory indicator ~
.
-
string
string The path.
Returns Path
Create a Path from an array of path part strings.
Returns Path
Create a Path from a file:// URL string.
-
url
string The path URL.
Returns Path?
Create a Path from an NSURL Object.
-
url
object The NSURL to convert.
Returns Path?
Create a Path from an an NSData bookmark.
Returns Path
String object extensions.
Meta
- version: 1.4.0
- author: Martin Kopischke <[email protected]>
- license: MIT
JXA implementation of AppleScript's quoted form of
.
Credits to http://stackoverflow.com/a/33050945/990363.
Returns string The quoted form of the string, suitable for shell usage.
Escape the String for usage as a literal in a RegExp. Credits to http://stackoverflow.com/a/6969486/990363.
Returns string The escaped string, suitable for usage as a RegExp literal.
Get an NSRange object matching the String.
Returns NSRange
Capitalise a string.
To quote the NSString.capitalizedString
documentation: A capitalised string
is a string with the first character in each word changed to its corresponding
uppercase value, and all remaining characters set to their corresponding
lowercase values. A word is any sequence of characters delimited by spaces,
tabs, or line terminators. Some common word delimiting punctuation isn't considered,
so this may not generally produce the desired results for multiword strings.
Returns string
- See: String#toCapitalizedForm for caveats about capitalisation.
- See: https://tc39.es/ecma402/#sec-bestavailablelocale for details how the best locale is found when multiple are supplied.
Capitalise a string, according to any locale-specific case mappings.
-
locale
(string | Array<string>)? The locale(s) to be used to convert to capitalised form. If multiple locales are given in anArray
, the best available locale is used. The default locale is the user's current locale. Note locale comparison with available locales is strict, so make sure you use the canonical, properly cased form of the locale identifier (xx[-XX]
). -
Throws TypeError When a non-string locale argument is passed.
-
Throws RangeError When an invalid locale specifier is passed.
Returns string
Transform a string.
-
transform
string The NSStringTransform to apply. -
reverse
boolean Apply the transform in reverse direction? (optional, defaultfalse
)
Returns string
An object that ObjC functions accept as an NSRange equivalent.
Type: object