| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 /** | |
| 8 * Type of a root directory. | |
| 9 * @enum {string} | |
| 10 * @const | |
| 11 */ | |
| 12 var RootType = Object.freeze({ | |
| 13 // Root of local directory. | |
| 14 DOWNLOADS: 'downloads', | |
| 15 | |
| 16 // Root of mounted archive file. | |
| 17 ARCHIVE: 'archive', | |
| 18 | |
| 19 // Root of removal volume. | |
| 20 REMOVABLE: 'removable', | |
| 21 | |
| 22 // Root of drive directory. | |
| 23 DRIVE: 'drive', | |
| 24 | |
| 25 // Root for privet storage volume. | |
| 26 CLOUD_DEVICE: 'cloud_device', | |
| 27 | |
| 28 // Root for MTP device. | |
| 29 MTP: 'mtp', | |
| 30 | |
| 31 // Root for entries that is not located under RootType.DRIVE. e.g. shared | |
| 32 // files. | |
| 33 DRIVE_OTHER: 'drive_other', | |
| 34 | |
| 35 // Fake root for offline available files on the drive. | |
| 36 DRIVE_OFFLINE: 'drive_offline', | |
| 37 | |
| 38 // Fake root for shared files on the drive. | |
| 39 DRIVE_SHARED_WITH_ME: 'drive_shared_with_me', | |
| 40 | |
| 41 // Fake root for recent files on the drive. | |
| 42 DRIVE_RECENT: 'drive_recent' | |
| 43 }); | |
| 44 | |
| 45 var PathUtil = {}; | |
| 46 | |
| 47 /** | |
| 48 * Extracts the extension of the path. | |
| 49 * | |
| 50 * Examples: | |
| 51 * PathUtil.splitExtension('abc.ext') -> ['abc', '.ext'] | |
| 52 * PathUtil.splitExtension('a/b/abc.ext') -> ['a/b/abc', '.ext'] | |
| 53 * PathUtil.splitExtension('a/b') -> ['a/b', ''] | |
| 54 * PathUtil.splitExtension('.cshrc') -> ['', '.cshrc'] | |
| 55 * PathUtil.splitExtension('a/b.backup/hoge') -> ['a/b.backup/hoge', ''] | |
| 56 * | |
| 57 * @param {string} path Path to be extracted. | |
| 58 * @return {Array.<string>} Filename and extension of the given path. | |
| 59 */ | |
| 60 PathUtil.splitExtension = function(path) { | |
| 61 var dotPosition = path.lastIndexOf('.'); | |
| 62 if (dotPosition <= path.lastIndexOf('/')) | |
| 63 dotPosition = -1; | |
| 64 | |
| 65 var filename = dotPosition != -1 ? path.substr(0, dotPosition) : path; | |
| 66 var extension = dotPosition != -1 ? path.substr(dotPosition) : ''; | |
| 67 return [filename, extension]; | |
| 68 }; | |
| OLD | NEW |