react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / src / docblock.js
80542 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;17var ltrimRe = /^\s*/;18/**19* @param {String} contents20* @return {String}21*/22function extract(contents) {23var match = contents.match(docblockRe);24if (match) {25return match[0].replace(ltrimRe, '') || '';26}27return '';28}293031var commentStartRe = /^\/\*\*?/;32var commentEndRe = /\*+\/$/;33var wsRe = /[\t ]+/g;34var stringStartRe = /(\r?\n|^) *\*/g;35var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;36var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;3738/**39* @param {String} contents40* @return {Array}41*/42function parse(docblock) {43docblock = docblock44.replace(commentStartRe, '')45.replace(commentEndRe, '')46.replace(wsRe, ' ')47.replace(stringStartRe, '$1');4849// Normalize multi-line directives50var prev = '';51while (prev != docblock) {52prev = docblock;53docblock = docblock.replace(multilineRe, "\n$1 $2\n");54}55docblock = docblock.trim();5657var result = [];58var match;59while (match = propertyRe.exec(docblock)) {60result.push([match[1], match[2]]);61}6263return result;64}6566/**67* Same as parse but returns an object of prop: value instead of array of paris68* If a property appers more than once the last one will be returned69*70* @param {String} contents71* @return {Object}72*/73function parseAsObject(docblock) {74var pairs = parse(docblock);75var result = {};76for (var i = 0; i < pairs.length; i++) {77result[pairs[i][0]] = pairs[i][1];78}79return result;80}818283exports.extract = extract;84exports.parse = parse;85exports.parseAsObject = parseAsObject;868788