Specify dataFormat when loading asset for import

When importing a project we know the file extension for each asset to be
loaded. This change provides that information to the storage system so
that we can load assets which don't use the default. For example, this
allows loading JPG-format backdrops.

In support of this change, there's a new function on `StringUtil` called
`splitFirst`, which splits a string on the first instance of a separator
character. This change includes unit tests for this new function.
This commit is contained in:
Christopher Willis-Ford committed 2017-05-24 15:35:10 -07:00
1 parent b39de6722f
commit eb931fd99b
7 files changed
+44 -9

No files matched your search

+24
View File
@@ -12,6 +12,30 @@ class StringUtil {
while (existingNames.indexOf(name + i) >= 0) i++;
return name + i;
}
/**
* Split a string on the first occurrence of a split character.
* @param {string} text - the string to split.
* @param {string} separator - split the text on this character.
* @returns {[string, string]} - the two parts of the split string, or [text, null] if no split character found.
* @example
* // returns ['foo', 'tar.gz']
* splitFirst('foo.tar.gz', '.');
* @example
* // returns ['foo', null]
* splitFirst('foo', '.');
* @example
* // returns ['foo', '']
* splitFirst('foo.', '.');
*/
static splitFirst (text, separator) {
const index = text.indexOf(separator);
if (index >= 0) {
return [text.substring(0, index), text.substring(index + 1)];
} else {
return [text, null];
}
}
}
module.exports = StringUtil;