mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
isFileOrResourcePath and RESOURCE_PREFIX moved in utils
This commit is contained in:
@ -1,11 +1,9 @@
|
|||||||
import http = require("http");
|
import http = require("http");
|
||||||
import types = require("utils/types");
|
import utils = require("utils/utils");
|
||||||
|
|
||||||
// This is used for definition purposes only, it does not generate JavaScript for it.
|
// This is used for definition purposes only, it does not generate JavaScript for it.
|
||||||
import definition = require("image-source");
|
import definition = require("image-source");
|
||||||
|
|
||||||
var RESOURCE_PREFIX = "res://";
|
|
||||||
|
|
||||||
export function fromResource(name: string): definition.ImageSource {
|
export function fromResource(name: string): definition.ImageSource {
|
||||||
var image = new definition.ImageSource();
|
var image = new definition.ImageSource();
|
||||||
return image.loadFromResource(name) ? image : null;
|
return image.loadFromResource(name) ? image : null;
|
||||||
@ -40,18 +38,12 @@ export function fromFileOrResource(path: string): definition.ImageSource {
|
|||||||
throw new Error("Path \"" + "\" is not a valid file or resource.");
|
throw new Error("Path \"" + "\" is not a valid file or resource.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.indexOf(RESOURCE_PREFIX) === 0) {
|
if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
|
||||||
return fromResource(path.substr(RESOURCE_PREFIX.length));
|
return fromResource(path.substr(utils.RESOURCE_PREFIX.length));
|
||||||
}
|
}
|
||||||
return fromFile(path);
|
return fromFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isFileOrResourcePath(path: string): boolean {
|
export function isFileOrResourcePath(path: string): boolean {
|
||||||
if (!types.isString(path)) {
|
return utils.isFileOrResourcePath(path);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.indexOf("~/") === 0 || // relative to AppRoot
|
|
||||||
path.indexOf("/") === 0 || // absolute path
|
|
||||||
path.indexOf(RESOURCE_PREFIX) === 0; // resource
|
|
||||||
}
|
}
|
2
image-source/image-source.d.ts
vendored
2
image-source/image-source.d.ts
vendored
@ -118,7 +118,7 @@ declare module "image-source" {
|
|||||||
export function fromFileOrResource(path: string): ImageSource;
|
export function fromFileOrResource(path: string): ImageSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the specified path points to a resource or local file.
|
* [Obsolete. Please use utils.isFileOrResourcePath instead!] Returns true if the specified path points to a resource or local file.
|
||||||
* @param path The path.
|
* @param path The path.
|
||||||
*/
|
*/
|
||||||
export function isFileOrResourcePath(path: string): boolean
|
export function isFileOrResourcePath(path: string): boolean
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import types = require("utils/types");
|
import types = require("utils/types");
|
||||||
|
|
||||||
|
export var RESOURCE_PREFIX = "res://";
|
||||||
|
|
||||||
export function copyFrom(source: any, target: any) {
|
export function copyFrom(source: any, target: any) {
|
||||||
if (types.isDefined(source) && types.isDefined(target)) {
|
if (types.isDefined(source) && types.isDefined(target)) {
|
||||||
var i: number;
|
var i: number;
|
||||||
@ -50,4 +52,14 @@ export module layout {
|
|||||||
export function getMeasureSpecSize(spec: number): number {
|
export function getMeasureSpecSize(spec: number): number {
|
||||||
return (spec & ~MODE_MASK);
|
return (spec & ~MODE_MASK);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isFileOrResourcePath(path: string): boolean {
|
||||||
|
if (!types.isString(path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.indexOf("~/") === 0 || // relative to AppRoot
|
||||||
|
path.indexOf("/") === 0 || // absolute path
|
||||||
|
path.indexOf(RESOURCE_PREFIX) === 0; // resource
|
||||||
}
|
}
|
8
utils/utils.d.ts
vendored
8
utils/utils.d.ts
vendored
@ -2,6 +2,8 @@
|
|||||||
import colorModule = require("color");
|
import colorModule = require("color");
|
||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
|
|
||||||
|
export var RESOURCE_PREFIX: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility module related to layout.
|
* Utility module related to layout.
|
||||||
*/
|
*/
|
||||||
@ -132,4 +134,10 @@
|
|||||||
* An utility function that invokes garbage collection on the JavaScript side.
|
* An utility function that invokes garbage collection on the JavaScript side.
|
||||||
*/
|
*/
|
||||||
export function GC();
|
export function GC();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the specified path points to a resource or local file.
|
||||||
|
* @param path The path.
|
||||||
|
*/
|
||||||
|
export function isFileOrResourcePath(path: string): boolean
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user