MCPcopy
hub / github.com/processing/p5.js / files

Function files

src/io/files.js:75–2128  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

73}
74
75function files(p5, fn){
76 /**
77 * Loads a JSON file to create an `Object`.
78 *
79 * JavaScript Object Notation
80 * (<a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON" target="_blank">JSON</a>)
81 * is a standard format for sending data between applications. The format is
82 * based on JavaScript objects which have keys and values. JSON files store
83 * data in an object with strings as keys. Values can be strings, numbers,
84 * Booleans, arrays, `null`, or other objects.
85 *
86 * The first parameter, `path`, is a string with the path to the file.
87 * Paths to local files should be relative, as in
88 * `loadJSON('assets/data.json')`. URLs such as
89 * `'https://example.com/data.json'` may be blocked due to browser security.
90 * The `path` parameter can also be defined as a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
91 * object for more advanced usage.
92 *
93 * The second parameter, `successCallback`, is optional. If a function is
94 * passed, as in `loadJSON('assets/data.json', handleData)`, then the
95 * `handleData()` function will be called once the data loads. The object
96 * created from the JSON data will be passed to `handleData()` as its only argument.
97 * The return value of the `handleData()` function will be used as the final return
98 * value of `loadJSON('assets/data.json', handleData)`.
99 *
100 * The third parameter, `failureCallback`, is also optional. If a function is
101 * passed, as in `loadJSON('assets/data.json', handleData, handleFailure)`,
102 * then the `handleFailure()` function will be called if an error occurs while
103 * loading. The `Error` object will be passed to `handleFailure()` as its only
104 * argument. The return value of the `handleFailure()` function will be used as the
105 * final return value of `loadJSON('assets/data.json', handleData, handleFailure)`.
106 *
107 * This function returns a `Promise` and should be used in an `async` setup with
108 * `await`. See the examples for the usage syntax.
109 *
110 * @method loadJSON
111 * @param {String|Request} path path of the JSON file to be loaded.
112 * @param {Function} [successCallback] function to call once the data is loaded. Will be passed the object.
113 * @param {Function} [errorCallback] function to call if the data fails to load. Will be passed an `Error` event object.
114 * @return {Promise<Object>} object containing the loaded data.
115 *
116 * @example
117 * let myData;
118 *
119 * async function setup() {
120 * myData = await loadJSON('assets/data.json');
121 * createCanvas(100, 100);
122 *
123 * background(200);
124 *
125 * // Style the circle.
126 * fill(myData.color);
127 * noStroke();
128 *
129 * // Draw the circle.
130 * circle(myData.x, myData.y, myData.d);
131 *
132 * describe('A pink circle on a gray background.');

Callers 9

downloading.jsFile · 0.85
loadBytes.jsFile · 0.85
loadJSON.jsFile · 0.85
saveTable.jsFile · 0.85
loadXML.jsFile · 0.85
loadStrings.jsFile · 0.85
loadTable.jsFile · 0.85
files.jsFile · 0.85
files.jsFile · 0.85

Calls 13

_checkFileExtensionFunction · 0.90
requestFunction · 0.85
escapeHelperFunction · 0.85
serializeMethod · 0.80
toBlobMethod · 0.80
splitMethod · 0.80
cbFunction · 0.70
popMethod · 0.45
pushMethod · 0.45
clearMethod · 0.45
closeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected