code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function success() {
if (debug) {
$log.info(arguments);
}
}
|
@ngdoc overview
@name angulartics.google.tagmanager.cordova
Enables analytics support for Google Tag Manager (http://google.com/tagmanager)
for Cordova plugin Tag Manager (http://plugins.cordova.io/#/package/com.jareddickson.cordova.tag-manager)
|
success
|
javascript
|
angulartics/angulartics
|
src/angulartics-gtm-cordova.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-gtm-cordova.js
|
MIT
|
function failure(err) {
if (debug) {
$log.error(err);
}
}
|
@ngdoc overview
@name angulartics.google.tagmanager.cordova
Enables analytics support for Google Tag Manager (http://google.com/tagmanager)
for Cordova plugin Tag Manager (http://plugins.cordova.io/#/package/com.jareddickson.cordova.tag-manager)
|
failure
|
javascript
|
angulartics/angulartics
|
src/angulartics-gtm-cordova.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-gtm-cordova.js
|
MIT
|
errorFunction = function(){
throw "Define _LTracker ";
}
|
@ngdoc overview
@name angulartics.loggly
Enables analytics support for Loggly
|
errorFunction
|
javascript
|
angulartics/angulartics
|
src/angulartics-loggly.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-loggly.js
|
MIT
|
_getLTracker = function () {
return window._LTracker || { push: errorFunction};
}
|
@ngdoc overview
@name angulartics.loggly
Enables analytics support for Loggly
|
_getLTracker
|
javascript
|
angulartics/angulartics
|
src/angulartics-loggly.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-loggly.js
|
MIT
|
associateLead = function(properties){
if(properties.email !== undefined) {
email = properties.email;
email_sha = sha1(Munchkin.sKey + email);
properties.Email = properties.email;
Munchkin.munchkinFunction('associateLead', properties, email_sha);
}
}
|
@ngdoc overview
@name angulartics.marketo
Enables analytics support for Marketo (http://www.marketo.com)
Will not be considered loaded until the sKey attribute is set on the Munchkin object, like so:
Munchkin.skey = 'my-secret-key';
for event tracking email is a required attribute
|
associateLead
|
javascript
|
angulartics/angulartics
|
src/angulartics-marketo.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-marketo.js
|
MIT
|
errorFunction = function(){
throw "Define sp ";
}
|
@ngdoc overview
@name angulartics.splunk
Enables analytics support for with custom collection backend API
using (sp.js as described in http://blogs.splunk.com/2013/10/17/still-using-3rd-party-web-analytics-providers-build-your-own-using-splunk/)
|
errorFunction
|
javascript
|
angulartics/angulartics
|
src/angulartics-splunk.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-splunk.js
|
MIT
|
_getSp = function () {
return window.sp || { pageview: errorFunction, track: errorFunction };
}
|
@ngdoc overview
@name angulartics.splunk
Enables analytics support for with custom collection backend API
using (sp.js as described in http://blogs.splunk.com/2013/10/17/still-using-3rd-party-web-analytics-providers-build-your-own-using-splunk/)
|
_getSp
|
javascript
|
angulartics/angulartics
|
src/angulartics-splunk.js
|
https://github.com/angulartics/angulartics/blob/master/src/angulartics-splunk.js
|
MIT
|
getMergedEslintConfig = function(filepath) {
return {
configFile: filepath,
baseConfig: '../.eslintrc.json',
rules: {
// Examples don't run in strict mode; accept that for now.
strict: 'off',
// Generated examples may miss the final EOL; ignore that.
'eol-last': 'off',
// Generated files use the system's default linebreak style (e.g. CRLF on Windows)
'linebreak-style': 'off',
// While alerts would be bad to have in the library or test code,
// they're perfectly fine in examples.
'no-alert': 'off',
// The following rules have to be disabled or tweaked because dgeni template wrappers
// don't follow them and we have no way to validate only the parts taken
// from ngdoc.
// some dgeni-packages templates generate whitespace-only lines
'no-trailing-spaces': ['error', { 'skipBlankLines': true }],
// dgeni templates use double quotes as string delimiters
quotes: 'off'
},
ignore: false,
useEslintrc: false
};
}
|
/*.js';
var ignoredFiles = '!src/angular.bind.js';
var assets = 'app/assets/*
|
getMergedEslintConfig
|
javascript
|
angular/angular.js
|
docs/gulpfile.js
|
https://github.com/angular/angular.js/blob/master/docs/gulpfile.js
|
MIT
|
copyComponent = function(component, pattern, base, sourceFolder, packageFile) {
pattern = pattern || '/**/*';
base = base || '';
sourceFolder = sourceFolder || '../node_modules';
packageFile = packageFile || 'package.json';
var version = require(path.resolve(sourceFolder, component, packageFile)).version;
return gulp
.src(sourceFolder + '/' + component + pattern, {base: sourceFolder + '/' + component + '/' + base})
.pipe(gulp.dest(outputFolder + '/components/' + component + '-' + version));
}
|
/*.js';
var ignoredFiles = '!src/angular.bind.js';
var assets = 'app/assets/*
|
copyComponent
|
javascript
|
angular/angular.js
|
docs/gulpfile.js
|
https://github.com/angular/angular.js/blob/master/docs/gulpfile.js
|
MIT
|
function extractTitleWords(title) {
var match = /ng([A-Z]\w*)/.exec(title);
if (match) {
title = title + ' ' + match[1].toLowerCase();
}
return title;
}
|
@dgProcessor generateKeywordsProcessor
@description
This processor extracts all the keywords from each document and creates
a new document that will be rendered as a JavaScript file containing all
this data.
|
extractTitleWords
|
javascript
|
angular/angular.js
|
docs/config/processors/keywords.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/keywords.js
|
MIT
|
function extractWords(text, words, keywordMap) {
var tokens = text.toLowerCase().split(/[.\s,`'"#]+/mg);
_.forEach(tokens, function(token) {
var match = token.match(KEYWORD_REGEX);
if (match) {
var key = match[1];
if (!keywordMap[key]) {
keywordMap[key] = true;
words.push(key);
}
}
});
}
|
@dgProcessor generateKeywordsProcessor
@description
This processor extracts all the keywords from each document and creates
a new document that will be rendered as a JavaScript file containing all
this data.
|
extractWords
|
javascript
|
angular/angular.js
|
docs/config/processors/keywords.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/keywords.js
|
MIT
|
function processAllVersionsResponse(versions) {
var latestMap = {};
// When the docs are built on a tagged commit, yarn info won't include the latest release,
// so we add it manually based on the local version.json file.
var missesCurrentVersion = !currentVersion.isSnapshot && !versions.find(function(version) {
return version === currentVersion.version;
});
if (missesCurrentVersion) versions.push(currentVersion.version);
versions = versions
.filter(function(versionStr) {
return ignoredBuilds.indexOf(versionStr) === -1;
})
.map(function(versionStr) {
return semver.parse(versionStr);
})
.filter(function(version) {
return version && version.major > 0;
})
.map(function(version) {
var key = version.major + '.' + version.minor;
var latest = latestMap[key];
if (!latest || version.compare(latest) > 0) {
latestMap[key] = version;
}
return version;
})
.map(function(version) {
return makeOption(version);
})
.reverse();
// List the latest version for each branch
var latest = sortObject(latestMap, reverse(semver.compare))
.map(function(version) { return makeOption(version, 'Latest'); });
// Get the stable release with the highest version
var highestStableRelease = versions.find(semverIsStable);
// Generate master and stable snapshots
var snapshots = [
makeOption(
{version: 'snapshot'},
'Latest',
'master-snapshot'
),
makeOption(
{version: 'snapshot-stable'},
'Latest',
createSnapshotStableLabel(highestStableRelease)
)
];
return snapshots
.concat(latest)
.concat(versions);
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
processAllVersionsResponse
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function makeOption(version, group, label) {
return {
version: version,
label: label || 'v' + version.raw,
group: group || 'v' + version.major + '.' + version.minor,
docsUrl: createDocsUrl(version)
};
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
makeOption
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function createDocsUrl(version) {
var url = 'https://code.angularjs.org/' + version.version + '/docs';
// Versions before 1.0.2 had a different docs folder name
if (version.major === 1 && version.minor === 0 && version.patch < 2) {
url += '-' + version.version;
}
return url;
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
createDocsUrl
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function reverse(fn) {
return function(left, right) { return -fn(left, right); };
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
reverse
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function sortObject(obj, cmp) {
return Object.keys(obj).map(function(key) { return obj[key]; }).sort(cmp);
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
sortObject
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function semverIsStable(version) {
var semverObj = version.version;
return semverObj === null ? false : !semverObj.prerelease.length;
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
semverIsStable
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function createSnapshotStableLabel(version) {
var label = version.label.replace(/.$/, 'x') + '-snapshot';
return label;
}
|
@dgProcessor generateVersionDocProcessor
@description
This processor will create a new doc that will be rendered as a JavaScript file
containing meta information about the current versions of AngularJS
|
createSnapshotStableLabel
|
javascript
|
angular/angular.js
|
docs/config/processors/versions-data.js
|
https://github.com/angular/angular.js/blob/master/docs/config/processors/versions-data.js
|
MIT
|
function createFolder(folder) {
return qfs.isDirectory(folder).then(function(isDir) {
if (!isDir) return qfs.makeDirectory(folder).then(function() {
console.log('Created directory %j', folder);
});
});
}
|
Make a folder under current directory.
@param folder {string} name of the folder to be made
|
createFolder
|
javascript
|
angular/angular.js
|
i18n/src/closureSlurper.js
|
https://github.com/angular/angular.js/blob/master/i18n/src/closureSlurper.js
|
MIT
|
function convertDatetimeData(dataObj) {
var datetimeFormats = {};
datetimeFormats.MONTH = dataObj.MONTHS;
datetimeFormats.SHORTMONTH = dataObj.SHORTMONTHS;
datetimeFormats.STANDALONEMONTH = dataObj.STANDALONEMONTHS;
datetimeFormats.DAY = dataObj.WEEKDAYS;
datetimeFormats.SHORTDAY = dataObj.SHORTWEEKDAYS;
datetimeFormats.AMPMS = dataObj.AMPMS;
datetimeFormats.FIRSTDAYOFWEEK = dataObj.FIRSTDAYOFWEEK;
datetimeFormats.WEEKENDRANGE = dataObj.WEEKENDRANGE;
datetimeFormats.ERAS = dataObj.ERAS;
datetimeFormats.ERANAMES = dataObj.ERANAMES;
datetimeFormats.medium = dataObj.DATEFORMATS[2] + ' ' + dataObj.TIMEFORMATS[2];
datetimeFormats.short = dataObj.DATEFORMATS[3] + ' ' + dataObj.TIMEFORMATS[3];
datetimeFormats.fullDate = dataObj.DATEFORMATS[0];
datetimeFormats.longDate = dataObj.DATEFORMATS[1];
datetimeFormats.mediumDate = dataObj.DATEFORMATS[2];
datetimeFormats.shortDate = dataObj.DATEFORMATS[3];
datetimeFormats.mediumTime = dataObj.TIMEFORMATS[2];
datetimeFormats.shortTime = dataObj.TIMEFORMATS[3];
return datetimeFormats;
}
|
after obtaining data from closure files, use converter to massage the data into the formats
we want
|
convertDatetimeData
|
javascript
|
angular/angular.js
|
i18n/src/converter.js
|
https://github.com/angular/angular.js/blob/master/i18n/src/converter.js
|
MIT
|
function ensureDecimalSep(pattern) {
return (pattern.indexOf(DECIMAL_SEP) !== -1)
? pattern : pattern.replace(LAST_ZERO_RE, '$1' + DECIMAL_SEP + '$2');
}
|
Helper function for parser.
Ensures that `pattern` (e.g #,##0.###) contains a DECIMAL_SEP, which is necessary for further
parsing. If a pattern does not include one, it is added after the last ZERO (which is the last
thing before the `posSuf` - if any).
|
ensureDecimalSep
|
javascript
|
angular/angular.js
|
i18n/src/parser.js
|
https://github.com/angular/angular.js/blob/master/i18n/src/parser.js
|
MIT
|
function parsePattern(pattern) {
var p = {
minInt: 1,
minFrac: 0,
maxFrac: 0,
posPre: '',
posSuf: '',
negPre: '',
negSuf: '',
gSize: 0,
lgSize: 0
};
var patternParts = pattern.split(PATTERN_SEP),
positive = patternParts[0],
negative = patternParts[1];
// The parsing logic further below assumes that there will always be a DECIMAL_SEP in the pattern.
// However, some locales (e.g. agq_CM) do not have one, thus we add one after the last ZERO
// (which is the last thing before the `posSuf` - if any). Since there will be no ZEROs or DIGITs
// after DECIMAL_SEP, `min/maxFrac` will remain 0 (which is accurate - no fraction digits) and
// `posSuf` will be processed correctly.
// For example `#,##0$` would be converted to `#,##0.$`, which would (correctly) result in:
// `minFrac: 0`, `maxFrac: 0`, `posSuf: '$'`
// Note: We shouldn't modify `positive` directly, because it is used to parse the negative part.)
var positiveWithDecimalSep = ensureDecimalSep(positive),
positiveParts = positiveWithDecimalSep.split(DECIMAL_SEP),
integer = positiveParts[0],
fraction = positiveParts[1];
p.posPre = integer.substr(0, integer.indexOf(DIGIT));
for (var i = 0; i < fraction.length; i++) {
var ch = fraction.charAt(i);
if (ch === ZERO) p.minFrac = p.maxFrac = i + 1;
else if (ch === DIGIT) p.maxFrac = i + 1;
else p.posSuf += ch;
}
var groups = integer.split(GROUP_SEP);
p.gSize = groups[1] ? groups[1].length : 0;
p.lgSize = (groups[2] || groups[1]) ? (groups[2] || groups[1]).length : 0;
if (negative) {
var trunkLen = positive.length - p.posPre.length - p.posSuf.length,
pos = negative.indexOf(DIGIT);
p.negPre = negative.substr(0, pos).replace(/'/g, '');
p.negSuf = negative.substr(pos + trunkLen).replace(/'/g, '');
} else {
// hardcoded '-' sign is fine as all locale use '-' as MINUS_SIGN. (\u2212 is the same as '-')
p.negPre = '-' + p.posPre;
p.negSuf = p.posSuf;
}
return p;
}
|
main function for parser
@param str {string} pattern to be parsed (e.g. #,##0.###).
|
parsePattern
|
javascript
|
angular/angular.js
|
i18n/src/parser.js
|
https://github.com/angular/angular.js/blob/master/i18n/src/parser.js
|
MIT
|
getPackage = function() {
// Search up the folder hierarchy for the first package.json
var packageFolder = path.resolve('.');
while (!fs.existsSync(path.join(packageFolder, 'package.json'))) {
var parent = path.dirname(packageFolder);
if (parent === packageFolder) { break; }
packageFolder = parent;
}
return JSON.parse(fs.readFileSync(path.join(packageFolder,'package.json'), 'UTF-8'));
}
|
Load information about this project from the package.json
@return {Object} The package information
|
getPackage
|
javascript
|
angular/angular.js
|
lib/versions/version-info.js
|
https://github.com/angular/angular.js/blob/master/lib/versions/version-info.js
|
MIT
|
getGitRepoInfo = function() {
var GITURL_REGEX = /^https:\/\/github.com\/([^/]+)\/(.+).git$/;
var match = GITURL_REGEX.exec(currentPackage.repository.url);
var git = {
owner: match[1],
repo: match[2]
};
return git;
}
|
Parse the github URL for useful information
@return {Object} An object containing the github owner and repository name
|
getGitRepoInfo
|
javascript
|
angular/angular.js
|
lib/versions/version-info.js
|
https://github.com/angular/angular.js/blob/master/lib/versions/version-info.js
|
MIT
|
getPreviousVersions = function() {
// If we are allowing remote requests then use the remote tags as the local clone might
// not contain all commits when cloned with git clone --depth=...
// Otherwise just use the tags in the local repository
var repo_url = currentPackage.repository.url;
var query = NO_REMOTE_REQUESTS ? 'git tag' : 'git ls-remote --tags ' + repo_url;
var tagResults = shell.exec(query, {silent: true});
if (tagResults.code === 0) {
return _(tagResults.stdout.match(/v[0-9].*[0-9]$/mg))
.map(function(tag) {
var version = semver.parse(tag);
return version;
})
.filter()
.map(function(version) {
// angular.js didn't follow semantic version until 1.20rc1
if ((version.major === 1 && version.minor === 0 && version.prerelease.length > 0) || (version.major === 1 && version.minor === 2 && version.prerelease[0] === 'rc1')) {
version.version = [version.major, version.minor, version.patch].join('.') + version.prerelease.join('');
version.raw = 'v' + version.version;
}
version.docsUrl = 'http://code.angularjs.org/' + version.version + '/docs';
// Versions before 1.0.2 had a different docs folder name
if (version.major < 1 || (version.major === 1 && version.minor === 0 && version.patch < 2)) {
version.docsUrl += '-' + version.version;
version.isOldDocsUrl = true;
}
return version;
})
.sort(semver.compare)
.value();
} else {
return [];
}
}
|
Get a collection of all the previous versions sorted by semantic version
@return {Array.<SemVer>} The collection of previous versions
|
getPreviousVersions
|
javascript
|
angular/angular.js
|
lib/versions/version-info.js
|
https://github.com/angular/angular.js/blob/master/lib/versions/version-info.js
|
MIT
|
getCdnVersion = function() {
return _(previousVersions)
.filter(function(tag) {
return semver.satisfies(tag, currentPackage.branchVersion);
})
.reverse()
.reduce(function(cdnVersion, version) {
if (!cdnVersion) {
if (NO_REMOTE_REQUESTS) {
// We do not want to make any remote calls to the CDN so just use the most recent version
cdnVersion = version;
} else {
// Note: need to use shell.exec and curl here
// as version-infos returns its result synchronously...
var cdnResult = shell.exec('curl http://ajax.googleapis.com/ajax/libs/angularjs/' + version + '/angular.min.js ' +
'--head --write-out "%{http_code}" -silent',
{silent: true});
if (cdnResult.code === 0) {
// --write-out appends its content to the general request response, so extract it
var statusCode = cdnResult.stdout.split('\n').pop().trim();
if (statusCode === '200') {
cdnVersion = version;
}
}
}
}
return cdnVersion;
}, null);
}
|
Get a collection of all the previous versions sorted by semantic version
@return {Array.<SemVer>} The collection of previous versions
|
getCdnVersion
|
javascript
|
angular/angular.js
|
lib/versions/version-info.js
|
https://github.com/angular/angular.js/blob/master/lib/versions/version-info.js
|
MIT
|
getSnapshotVersion = function() {
var version = _(previousVersions)
.filter(function(tag) {
return semver.satisfies(tag, currentPackage.branchVersion);
})
.last();
if (!version) {
// a snapshot version before the first tag on the branch
version = semver(currentPackage.branchPattern.replace('*','0-beta.1'));
}
// We need to clone to ensure that we are not modifying another version
version = semver(version.raw);
var ciBuild = process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER;
if (!version.prerelease || !version.prerelease.length) {
// last release was a non beta release. Increment the patch level to
// indicate the next release that we will be doing.
// E.g. last release was 1.3.0, then the snapshot will be
// 1.3.1-build.1, which is lesser than 1.3.1 according to the semver!
// If the last release was a beta release we don't update the
// beta number by purpose, as otherwise the semver comparison
// does not work any more when the next beta is released.
// E.g. don't generate 1.3.0-beta.2.build.1
// as this is bigger than 1.3.0-beta.2 according to semver
version.patch++;
}
version.prerelease = ciBuild ? ['build', ciBuild] : ['local'];
version.build = getBuild();
version.codeName = 'snapshot';
version.isSnapshot = true;
version.format();
version.full = version.version + '+' + version.build;
version.branch = 'master';
version.distTag = currentPackage.distTag;
return version;
}
|
Get the unstable snapshot version
@return {SemVer} The snapshot version
|
getSnapshotVersion
|
javascript
|
angular/angular.js
|
lib/versions/version-info.js
|
https://github.com/angular/angular.js/blob/master/lib/versions/version-info.js
|
MIT
|
function deleteOldSnapshotZip(object) {
const bucketId = object.bucket;
const filePath = object.name;
const contentType = object.contentType;
const bucket = storage.bucket(bucketId);
const snapshotFolderMatch = filePath.match(snapshotRegex);
if (!snapshotFolderMatch || contentType !== 'application/zip') {
return;
}
bucket.getFiles({
prefix: snapshotFolderMatch[0],
delimiter: '/',
autoPaginate: false
}).then(function(data) {
const files = data[0];
const oldZipFiles = files.filter(file => {
return file.metadata.name !== filePath && file.metadata.contentType === 'application/zip';
});
console.info(`found ${oldZipFiles.length} old zip files to delete`);
oldZipFiles.forEach(function(file) {
file.delete();
});
});
}
|
The build folder contains a zip file that is unique per build.
When a new zip file is uploaded into snapshot or snapshot-stable,
delete the previous zip file.
|
deleteOldSnapshotZip
|
javascript
|
angular/angular.js
|
scripts/code.angularjs.org-firebase/functions/index.js
|
https://github.com/angular/angular.js/blob/master/scripts/code.angularjs.org-firebase/functions/index.js
|
MIT
|
function isArrayLike(obj) {
// `null`, `undefined` and `window` are not array-like
if (obj == null || isWindow(obj)) return false;
// arrays, strings and jQuery/jqLite objects are array like
// * jqLite is either the jQuery or jqLite constructor function
// * we have to check the existence of jqLite first as this method is called
// via the forEach method when constructing the jqLite object in the first place
if (isArray(obj) || isString(obj) || (jqLite && obj instanceof jqLite)) return true;
// Support: iOS 8.2 (not reproducible in simulator)
// "length" in obj used to prevent JIT error (gh-11508)
var length = 'length' in Object(obj) && obj.length;
// NodeList objects (with `item` method) and
// other objects with suitable length characteristics are array-like
return isNumber(length) && (length >= 0 && (length - 1) in obj || typeof obj.item === 'function');
}
|
@private
@param {*} obj
@return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments,
String ...)
|
isArrayLike
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function forEach(obj, iterator, context) {
var key, length;
if (obj) {
if (isFunction(obj)) {
for (key in obj) {
if (key !== 'prototype' && key !== 'length' && key !== 'name' && obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key, obj);
}
}
} else if (isArray(obj) || isArrayLike(obj)) {
var isPrimitive = typeof obj !== 'object';
for (key = 0, length = obj.length; key < length; key++) {
if (isPrimitive || key in obj) {
iterator.call(context, obj[key], key, obj);
}
}
} else if (obj.forEach && obj.forEach !== forEach) {
obj.forEach(iterator, context, obj);
} else if (isBlankObject(obj)) {
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
for (key in obj) {
iterator.call(context, obj[key], key, obj);
}
} else if (typeof obj.hasOwnProperty === 'function') {
// Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
for (key in obj) {
if (obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key, obj);
}
}
} else {
// Slow path for objects which do not have a method `hasOwnProperty`
for (key in obj) {
if (hasOwnProperty.call(obj, key)) {
iterator.call(context, obj[key], key, obj);
}
}
}
}
return obj;
}
|
@ngdoc function
@name angular.forEach
@module ng
@kind function
@description
Invokes the `iterator` function once for each item in `obj` collection, which can be either an
object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value`
is the value of an object property or an array element, `key` is the object property key or
array element index and obj is the `obj` itself. Specifying a `context` for the function is optional.
It is worth noting that `.forEach` does not iterate over inherited properties because it filters
using the `hasOwnProperty` method.
Unlike ES262's
[Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18),
providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just
return the value provided.
```js
var values = {name: 'misko', gender: 'male'};
var log = [];
angular.forEach(values, function(value, key) {
this.push(key + ': ' + value);
}, log);
expect(log).toEqual(['name: misko', 'gender: male']);
```
@param {Object|Array} obj Object to iterate over.
@param {Function} iterator Iterator function.
@param {Object=} context Object to become context (`this`) for the iterator function.
@returns {Object|Array} Reference to `obj`.
|
forEach
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function forEachSorted(obj, iterator, context) {
var keys = Object.keys(obj).sort();
for (var i = 0; i < keys.length; i++) {
iterator.call(context, obj[keys[i]], keys[i]);
}
return keys;
}
|
@ngdoc function
@name angular.forEach
@module ng
@kind function
@description
Invokes the `iterator` function once for each item in `obj` collection, which can be either an
object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value`
is the value of an object property or an array element, `key` is the object property key or
array element index and obj is the `obj` itself. Specifying a `context` for the function is optional.
It is worth noting that `.forEach` does not iterate over inherited properties because it filters
using the `hasOwnProperty` method.
Unlike ES262's
[Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18),
providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just
return the value provided.
```js
var values = {name: 'misko', gender: 'male'};
var log = [];
angular.forEach(values, function(value, key) {
this.push(key + ': ' + value);
}, log);
expect(log).toEqual(['name: misko', 'gender: male']);
```
@param {Object|Array} obj Object to iterate over.
@param {Function} iterator Iterator function.
@param {Object=} context Object to become context (`this`) for the iterator function.
@returns {Object|Array} Reference to `obj`.
|
forEachSorted
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function reverseParams(iteratorFn) {
return function(value, key) {iteratorFn(key, value);};
}
|
when using forEach the params are value, key, but it is often useful to have key, value.
@param {function(string, *)} iteratorFn
@returns {function(*, string)}
|
reverseParams
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function nextUid() {
return ++uid;
}
|
A consistent way of creating unique IDs in angular.
Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before
we hit number precision issues in JavaScript.
Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M
@returns {number} an unique alpha-numeric string
|
nextUid
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function setHashKey(obj, h) {
if (h) {
obj.$$hashKey = h;
} else {
delete obj.$$hashKey;
}
}
|
Set or clear the hashkey for an object.
@param obj object
@param h the hashkey (!truthy to delete the hashkey)
|
setHashKey
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function baseExtend(dst, objs, deep) {
var h = dst.$$hashKey;
for (var i = 0, ii = objs.length; i < ii; ++i) {
var obj = objs[i];
if (!isObject(obj) && !isFunction(obj)) continue;
var keys = Object.keys(obj);
for (var j = 0, jj = keys.length; j < jj; j++) {
var key = keys[j];
var src = obj[key];
if (deep && isObject(src)) {
if (isDate(src)) {
dst[key] = new Date(src.valueOf());
} else if (isRegExp(src)) {
dst[key] = new RegExp(src);
} else if (src.nodeName) {
dst[key] = src.cloneNode(true);
} else if (isElement(src)) {
dst[key] = src.clone();
} else {
if (key !== '__proto__') {
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
baseExtend(dst[key], [src], true);
}
}
} else {
dst[key] = src;
}
}
}
setHashKey(dst, h);
return dst;
}
|
Set or clear the hashkey for an object.
@param obj object
@param h the hashkey (!truthy to delete the hashkey)
|
baseExtend
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function extend(dst) {
return baseExtend(dst, slice.call(arguments, 1), false);
}
|
@ngdoc function
@name angular.extend
@module ng
@kind function
@description
Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
**Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
{@link angular.merge} for this.
@param {Object} dst Destination object.
@param {...Object} src Source object(s).
@returns {Object} Reference to `dst`.
|
extend
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function hasCustomToString(obj) {
return isFunction(obj.toString) && obj.toString !== toString;
}
|
@ngdoc function
@name angular.identity
@module ng
@kind function
@description
A function that returns its first argument. This function is useful when writing code in the
functional style.
```js
function transformer(transformationFn, value) {
return (transformationFn || angular.identity)(value);
};
// E.g.
function getResult(fn, input) {
return (fn || angular.identity)(input);
};
getResult(function(n) { return n * 2; }, 21); // returns 42
getResult(null, 21); // returns 21
getResult(undefined, 21); // returns 21
```
@param {*} value to be returned.
@returns {*} the value passed in.
|
hasCustomToString
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isObject(value) {
// http://jsperf.com/isobject4
return value !== null && typeof value === 'object';
}
|
@ngdoc function
@name angular.isObject
@module ng
@kind function
@description
Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
considered to be objects. Note that JavaScript arrays are objects.
@param {*} value Reference to check.
@returns {boolean} True if `value` is an `Object` but not `null`.
|
isObject
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isBlankObject(value) {
return value !== null && typeof value === 'object' && !getPrototypeOf(value);
}
|
Determine if a value is an object with a null prototype
@returns {boolean} True if `value` is an `Object` with a null prototype
|
isBlankObject
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isDate(value) {
return toString.call(value) === '[object Date]';
}
|
@ngdoc function
@name angular.isDate
@module ng
@kind function
@description
Determines if a value is a date.
@param {*} value Reference to check.
@returns {boolean} True if `value` is a `Date`.
|
isDate
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isArray(arr) {
return Array.isArray(arr) || arr instanceof Array;
}
|
@ngdoc function
@name angular.isArray
@module ng
@kind function
@description
Determines if a reference is an `Array`.
@param {*} value Reference to check.
@returns {boolean} True if `value` is an `Array`.
|
isArray
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isError(value) {
var tag = toString.call(value);
switch (tag) {
case '[object Error]': return true;
case '[object Exception]': return true;
case '[object DOMException]': return true;
default: return value instanceof Error;
}
}
|
@description
Determines if a reference is an `Error`.
Loosely based on https://www.npmjs.com/package/iserror
@param {*} value Reference to check.
@returns {boolean} True if `value` is an `Error`.
|
isError
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isRegExp(value) {
return toString.call(value) === '[object RegExp]';
}
|
Determines if a value is a regular expression object.
@private
@param {*} value Reference to check.
@returns {boolean} True if `value` is a `RegExp`.
|
isRegExp
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isWindow(obj) {
return obj && obj.window === obj;
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isWindow
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isScope(obj) {
return obj && obj.$evalAsync && obj.$watch;
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isScope
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isFile(obj) {
return toString.call(obj) === '[object File]';
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isFile
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isFormData(obj) {
return toString.call(obj) === '[object FormData]';
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isFormData
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isBlob(obj) {
return toString.call(obj) === '[object Blob]';
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isBlob
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isBoolean(value) {
return typeof value === 'boolean';
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isBoolean
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isPromiseLike(obj) {
return obj && isFunction(obj.then);
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isPromiseLike
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isTypedArray(value) {
return value && isNumber(value.length) && TYPED_ARRAY_REGEXP.test(toString.call(value));
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isTypedArray
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isArrayBuffer(obj) {
return toString.call(obj) === '[object ArrayBuffer]';
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
isArrayBuffer
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
trim = function(value) {
return isString(value) ? value.trim() : value;
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
trim
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
escapeForRegexp = function(s) {
return s
.replace(/([-()[\]{}+?*.$^|,:#<!\\])/g, '\\$1')
// eslint-disable-next-line no-control-regex
.replace(/\x08/g, '\\x08');
}
|
Checks if `obj` is a window object.
@private
@param {*} obj Object to check
@returns {boolean} True if `obj` is a window obj.
|
escapeForRegexp
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function isElement(node) {
return !!(node &&
(node.nodeName // We are a direct element.
|| (node.prop && node.attr && node.find))); // We have an on and find method part of jQuery API.
}
|
@ngdoc function
@name angular.isElement
@module ng
@kind function
@description
Determines if a reference is a DOM element (or wrapped jQuery element).
@param {*} value Reference to check.
@returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
|
isElement
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function makeMap(str) {
var obj = {}, items = str.split(','), i;
for (i = 0; i < items.length; i++) {
obj[items[i]] = true;
}
return obj;
}
|
@param str 'key1,key2,...'
@returns {object} in the form of {key1:true, key2:true, ...}
|
makeMap
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function nodeName_(element) {
return lowercase(element.nodeName || (element[0] && element[0].nodeName));
}
|
@param str 'key1,key2,...'
@returns {object} in the form of {key1:true, key2:true, ...}
|
nodeName_
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function includes(array, obj) {
return Array.prototype.indexOf.call(array, obj) !== -1;
}
|
@param str 'key1,key2,...'
@returns {object} in the form of {key1:true, key2:true, ...}
|
includes
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function arrayRemove(array, value) {
var index = array.indexOf(value);
if (index >= 0) {
array.splice(index, 1);
}
return index;
}
|
@param str 'key1,key2,...'
@returns {object} in the form of {key1:true, key2:true, ...}
|
arrayRemove
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function equals(o1, o2) {
if (o1 === o2) return true;
if (o1 === null || o2 === null) return false;
// eslint-disable-next-line no-self-compare
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
if (t1 === t2 && t1 === 'object') {
if (isArray(o1)) {
if (!isArray(o2)) return false;
if ((length = o1.length) === o2.length) {
for (key = 0; key < length; key++) {
if (!equals(o1[key], o2[key])) return false;
}
return true;
}
} else if (isDate(o1)) {
if (!isDate(o2)) return false;
return simpleCompare(o1.getTime(), o2.getTime());
} else if (isRegExp(o1)) {
if (!isRegExp(o2)) return false;
return o1.toString() === o2.toString();
} else {
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
keySet = createMap();
for (key in o1) {
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
if (!equals(o1[key], o2[key])) return false;
keySet[key] = true;
}
for (key in o2) {
if (!(key in keySet) &&
key.charAt(0) !== '$' &&
isDefined(o2[key]) &&
!isFunction(o2[key])) return false;
}
return true;
}
}
return false;
}
|
@ngdoc function
@name angular.equals
@module ng
@kind function
@description
Determines if two objects or two values are equivalent. Supports value types, regular
expressions, arrays and objects.
Two objects or values are considered equivalent if at least one of the following is true:
* Both objects or values pass `===` comparison.
* Both objects or values are of the same type and all of their properties are equal by
comparing them with `angular.equals`.
* Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
* Both values represent the same regular expression (In JavaScript,
/abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
representation matches).
During a property comparison, properties of `function` type and properties with names
that begin with `$` are ignored.
Scope and DOMWindow objects are being compared only by identify (`===`).
@param {*} o1 Object or value to compare.
@param {*} o2 Object or value to compare.
@returns {boolean} True if arguments are equal.
@example
<example module="equalsExample" name="equalsExample">
<file name="index.html">
<div ng-controller="ExampleController">
<form novalidate>
<h3>User 1</h3>
Name: <input type="text" ng-model="user1.name">
Age: <input type="number" ng-model="user1.age">
<h3>User 2</h3>
Name: <input type="text" ng-model="user2.name">
Age: <input type="number" ng-model="user2.age">
<div>
<br/>
<input type="button" value="Compare" ng-click="compare()">
</div>
User 1: <pre>{{user1 | json}}</pre>
User 2: <pre>{{user2 | json}}</pre>
Equal: <pre>{{result}}</pre>
</form>
</div>
</file>
<file name="script.js">
angular.module('equalsExample', []).controller('ExampleController', ['$scope', function($scope) {
$scope.user1 = {};
$scope.user2 = {};
$scope.compare = function() {
$scope.result = angular.equals($scope.user1, $scope.user2);
};
}]);
</file>
</example>
|
equals
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
csp = function() {
if (!isDefined(csp.rules)) {
var ngCspElement = (window.document.querySelector('[ng-csp]') ||
window.document.querySelector('[data-ng-csp]'));
if (ngCspElement) {
var ngCspAttribute = ngCspElement.getAttribute('ng-csp') ||
ngCspElement.getAttribute('data-ng-csp');
csp.rules = {
noUnsafeEval: !ngCspAttribute || (ngCspAttribute.indexOf('no-unsafe-eval') !== -1),
noInlineStyle: !ngCspAttribute || (ngCspAttribute.indexOf('no-inline-style') !== -1)
};
} else {
csp.rules = {
noUnsafeEval: noUnsafeEval(),
noInlineStyle: false
};
}
}
return csp.rules;
function noUnsafeEval() {
try {
// eslint-disable-next-line no-new, no-new-func
new Function('');
return false;
} catch (e) {
return true;
}
}
}
|
@ngdoc function
@name angular.equals
@module ng
@kind function
@description
Determines if two objects or two values are equivalent. Supports value types, regular
expressions, arrays and objects.
Two objects or values are considered equivalent if at least one of the following is true:
* Both objects or values pass `===` comparison.
* Both objects or values are of the same type and all of their properties are equal by
comparing them with `angular.equals`.
* Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
* Both values represent the same regular expression (In JavaScript,
/abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
representation matches).
During a property comparison, properties of `function` type and properties with names
that begin with `$` are ignored.
Scope and DOMWindow objects are being compared only by identify (`===`).
@param {*} o1 Object or value to compare.
@param {*} o2 Object or value to compare.
@returns {boolean} True if arguments are equal.
@example
<example module="equalsExample" name="equalsExample">
<file name="index.html">
<div ng-controller="ExampleController">
<form novalidate>
<h3>User 1</h3>
Name: <input type="text" ng-model="user1.name">
Age: <input type="number" ng-model="user1.age">
<h3>User 2</h3>
Name: <input type="text" ng-model="user2.name">
Age: <input type="number" ng-model="user2.age">
<div>
<br/>
<input type="button" value="Compare" ng-click="compare()">
</div>
User 1: <pre>{{user1 | json}}</pre>
User 2: <pre>{{user2 | json}}</pre>
Equal: <pre>{{result}}</pre>
</form>
</div>
</file>
<file name="script.js">
angular.module('equalsExample', []).controller('ExampleController', ['$scope', function($scope) {
$scope.user1 = {};
$scope.user2 = {};
$scope.compare = function() {
$scope.result = angular.equals($scope.user1, $scope.user2);
};
}]);
</file>
</example>
|
csp
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function noUnsafeEval() {
try {
// eslint-disable-next-line no-new, no-new-func
new Function('');
return false;
} catch (e) {
return true;
}
}
|
@ngdoc function
@name angular.equals
@module ng
@kind function
@description
Determines if two objects or two values are equivalent. Supports value types, regular
expressions, arrays and objects.
Two objects or values are considered equivalent if at least one of the following is true:
* Both objects or values pass `===` comparison.
* Both objects or values are of the same type and all of their properties are equal by
comparing them with `angular.equals`.
* Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
* Both values represent the same regular expression (In JavaScript,
/abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
representation matches).
During a property comparison, properties of `function` type and properties with names
that begin with `$` are ignored.
Scope and DOMWindow objects are being compared only by identify (`===`).
@param {*} o1 Object or value to compare.
@param {*} o2 Object or value to compare.
@returns {boolean} True if arguments are equal.
@example
<example module="equalsExample" name="equalsExample">
<file name="index.html">
<div ng-controller="ExampleController">
<form novalidate>
<h3>User 1</h3>
Name: <input type="text" ng-model="user1.name">
Age: <input type="number" ng-model="user1.age">
<h3>User 2</h3>
Name: <input type="text" ng-model="user2.name">
Age: <input type="number" ng-model="user2.age">
<div>
<br/>
<input type="button" value="Compare" ng-click="compare()">
</div>
User 1: <pre>{{user1 | json}}</pre>
User 2: <pre>{{user2 | json}}</pre>
Equal: <pre>{{result}}</pre>
</form>
</div>
</file>
<file name="script.js">
angular.module('equalsExample', []).controller('ExampleController', ['$scope', function($scope) {
$scope.user1 = {};
$scope.user2 = {};
$scope.compare = function() {
$scope.result = angular.equals($scope.user1, $scope.user2);
};
}]);
</file>
</example>
|
noUnsafeEval
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
jq = function() {
if (isDefined(jq.name_)) return jq.name_;
var el;
var i, ii = ngAttrPrefixes.length, prefix, name;
for (i = 0; i < ii; ++i) {
prefix = ngAttrPrefixes[i];
el = window.document.querySelector('[' + prefix.replace(':', '\\:') + 'jq]');
if (el) {
name = el.getAttribute(prefix + 'jq');
break;
}
}
return (jq.name_ = name);
}
|
@ngdoc directive
@module ng
@name ngJq
@element ANY
@param {string=} ngJq the name of the library available under `window`
to be used for angular.element
@description
Use this directive to force the angular.element library. This should be
used to force either jqLite by leaving ng-jq blank or setting the name of
the jquery variable under window (eg. jQuery).
Since AngularJS looks for this directive when it is loaded (doesn't wait for the
DOMContentLoaded event), it must be placed on an element that comes before the script
which loads angular. Also, only the first instance of `ng-jq` will be used and all
others ignored.
@example
This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
```html
<!doctype html>
<html ng-app ng-jq>
...
...
</html>
```
@example
This example shows how to use a jQuery based library of a different name.
The library name must be available at the top most 'window'.
```html
<!doctype html>
<html ng-app ng-jq="jQueryLib">
...
...
</html>
```
|
jq
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function concat(array1, array2, index) {
return array1.concat(slice.call(array2, index));
}
|
@ngdoc directive
@module ng
@name ngJq
@element ANY
@param {string=} ngJq the name of the library available under `window`
to be used for angular.element
@description
Use this directive to force the angular.element library. This should be
used to force either jqLite by leaving ng-jq blank or setting the name of
the jquery variable under window (eg. jQuery).
Since AngularJS looks for this directive when it is loaded (doesn't wait for the
DOMContentLoaded event), it must be placed on an element that comes before the script
which loads angular. Also, only the first instance of `ng-jq` will be used and all
others ignored.
@example
This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
```html
<!doctype html>
<html ng-app ng-jq>
...
...
</html>
```
@example
This example shows how to use a jQuery based library of a different name.
The library name must be available at the top most 'window'.
```html
<!doctype html>
<html ng-app ng-jq="jQueryLib">
...
...
</html>
```
|
concat
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function sliceArgs(args, startIndex) {
return slice.call(args, startIndex || 0);
}
|
@ngdoc directive
@module ng
@name ngJq
@element ANY
@param {string=} ngJq the name of the library available under `window`
to be used for angular.element
@description
Use this directive to force the angular.element library. This should be
used to force either jqLite by leaving ng-jq blank or setting the name of
the jquery variable under window (eg. jQuery).
Since AngularJS looks for this directive when it is loaded (doesn't wait for the
DOMContentLoaded event), it must be placed on an element that comes before the script
which loads angular. Also, only the first instance of `ng-jq` will be used and all
others ignored.
@example
This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
```html
<!doctype html>
<html ng-app ng-jq>
...
...
</html>
```
@example
This example shows how to use a jQuery based library of a different name.
The library name must be available at the top most 'window'.
```html
<!doctype html>
<html ng-app ng-jq="jQueryLib">
...
...
</html>
```
|
sliceArgs
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function bind(self, fn) {
var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
if (isFunction(fn) && !(fn instanceof RegExp)) {
return curryArgs.length
? function() {
return arguments.length
? fn.apply(self, concat(curryArgs, arguments, 0))
: fn.apply(self, curryArgs);
}
: function() {
return arguments.length
? fn.apply(self, arguments)
: fn.call(self);
};
} else {
// In IE, native methods are not functions so they cannot be bound (note: they don't need to be).
return fn;
}
}
|
@ngdoc function
@name angular.bind
@module ng
@kind function
@description
Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
`fn`). You can supply optional `args` that are prebound to the function. This feature is also
known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
@param {Object} self Context which `fn` should be evaluated in.
@param {function()} fn Function to be bound.
@param {...*} args Optional arguments to be prebound to the `fn` function call.
@returns {function()} Function that wraps the `fn` with all the specified bindings.
|
bind
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function toJsonReplacer(key, value) {
var val = value;
if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
val = undefined;
} else if (isWindow(value)) {
val = '$WINDOW';
} else if (value && window.document === value) {
val = '$DOCUMENT';
} else if (isScope(value)) {
val = '$SCOPE';
}
return val;
}
|
@ngdoc function
@name angular.bind
@module ng
@kind function
@description
Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
`fn`). You can supply optional `args` that are prebound to the function. This feature is also
known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
@param {Object} self Context which `fn` should be evaluated in.
@param {function()} fn Function to be bound.
@param {...*} args Optional arguments to be prebound to the `fn` function call.
@returns {function()} Function that wraps the `fn` with all the specified bindings.
|
toJsonReplacer
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function toJson(obj, pretty) {
if (isUndefined(obj)) return undefined;
if (!isNumber(pretty)) {
pretty = pretty ? 2 : null;
}
return JSON.stringify(obj, toJsonReplacer, pretty);
}
|
@ngdoc function
@name angular.toJson
@module ng
@kind function
@description
Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
stripped since AngularJS uses this notation internally.
@param {Object|Array|Date|string|number|boolean} obj Input to be serialized into JSON.
@param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
If set to an integer, the JSON output will contain that many spaces per indentation.
@returns {string|undefined} JSON-ified string representing `obj`.
@knownIssue
The Safari browser throws a `RangeError` instead of returning `null` when it tries to stringify a `Date`
object with an invalid date value. The only reliable way to prevent this is to monkeypatch the
`Date.prototype.toJSON` method as follows:
```
var _DatetoJSON = Date.prototype.toJSON;
Date.prototype.toJSON = function() {
try {
return _DatetoJSON.call(this);
} catch(e) {
if (e instanceof RangeError) {
return null;
}
throw e;
}
};
```
See https://github.com/angular/angular.js/pull/14221 for more information.
|
toJson
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function fromJson(json) {
return isString(json)
? JSON.parse(json)
: json;
}
|
@ngdoc function
@name angular.fromJson
@module ng
@kind function
@description
Deserializes a JSON string.
@param {string} json JSON string to deserialize.
@returns {Object|Array|string|number} Deserialized JSON string.
|
fromJson
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function timezoneToOffset(timezone, fallback) {
// Support: IE 9-11 only, Edge 13-15+
// IE/Edge do not "understand" colon (`:`) in timezone
timezone = timezone.replace(ALL_COLONS, '');
var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
return isNumberNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
}
|
@ngdoc function
@name angular.fromJson
@module ng
@kind function
@description
Deserializes a JSON string.
@param {string} json JSON string to deserialize.
@returns {Object|Array|string|number} Deserialized JSON string.
|
timezoneToOffset
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function addDateMinutes(date, minutes) {
date = new Date(date.getTime());
date.setMinutes(date.getMinutes() + minutes);
return date;
}
|
@ngdoc function
@name angular.fromJson
@module ng
@kind function
@description
Deserializes a JSON string.
@param {string} json JSON string to deserialize.
@returns {Object|Array|string|number} Deserialized JSON string.
|
addDateMinutes
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function convertTimezoneToLocal(date, timezone, reverse) {
reverse = reverse ? -1 : 1;
var dateTimezoneOffset = date.getTimezoneOffset();
var timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
return addDateMinutes(date, reverse * (timezoneOffset - dateTimezoneOffset));
}
|
@ngdoc function
@name angular.fromJson
@module ng
@kind function
@description
Deserializes a JSON string.
@param {string} json JSON string to deserialize.
@returns {Object|Array|string|number} Deserialized JSON string.
|
convertTimezoneToLocal
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function startingTag(element) {
element = jqLite(element).clone().empty();
var elemHtml = jqLite('<div></div>').append(element).html();
try {
return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) :
elemHtml.
match(/^(<[^>]+>)/)[1].
replace(/^<([\w-]+)/, function(match, nodeName) {return '<' + lowercase(nodeName);});
} catch (e) {
return lowercase(elemHtml);
}
}
|
@returns {string} Returns the string representation of the element.
|
startingTag
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function tryDecodeURIComponent(value) {
try {
return decodeURIComponent(value);
} catch (e) {
// Ignore any invalid uri component.
}
}
|
Tries to decode the URI component without throwing an exception.
@private
@param str value potential URI component to check.
@returns {boolean} True if `value` can be decoded
with the decodeURIComponent function.
|
tryDecodeURIComponent
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function parseKeyValue(/**string*/keyValue) {
var obj = {};
forEach((keyValue || '').split('&'), function(keyValue) {
var splitPoint, key, val;
if (keyValue) {
key = keyValue = keyValue.replace(/\+/g,'%20');
splitPoint = keyValue.indexOf('=');
if (splitPoint !== -1) {
key = keyValue.substring(0, splitPoint);
val = keyValue.substring(splitPoint + 1);
}
key = tryDecodeURIComponent(key);
if (isDefined(key)) {
val = isDefined(val) ? tryDecodeURIComponent(val) : true;
if (!hasOwnProperty.call(obj, key)) {
obj[key] = val;
} else if (isArray(obj[key])) {
obj[key].push(val);
} else {
obj[key] = [obj[key],val];
}
}
}
});
return obj;
}
|
Parses an escaped url query string into key-value pairs.
@returns {Object.<string,boolean|Array>}
|
parseKeyValue
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function encodeUriSegment(val) {
return encodeUriQuery(val, true).
replace(/%26/gi, '&').
replace(/%3D/gi, '=').
replace(/%2B/gi, '+');
}
|
We need our custom method because encodeURIComponent is too aggressive and doesn't follow
http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
segments:
segment = *pchar
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
pct-encoded = "%" HEXDIG HEXDIG
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
|
encodeUriSegment
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function encodeUriQuery(val, pctEncodeSpaces) {
return encodeURIComponent(val).
replace(/%40/gi, '@').
replace(/%3A/gi, ':').
replace(/%24/g, '$').
replace(/%2C/gi, ',').
replace(/%3B/gi, ';').
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
}
|
This method is intended for encoding *key* or *value* parts of query component. We need a custom
method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
encoded per http://tools.ietf.org/html/rfc3986:
query = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
|
encodeUriQuery
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function getNgAttribute(element, ngAttr) {
var attr, i, ii = ngAttrPrefixes.length;
for (i = 0; i < ii; ++i) {
attr = ngAttrPrefixes[i] + ngAttr;
if (isString(attr = element.getAttribute(attr))) {
return attr;
}
}
return null;
}
|
This method is intended for encoding *key* or *value* parts of query component. We need a custom
method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
encoded per http://tools.ietf.org/html/rfc3986:
query = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
|
getNgAttribute
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function allowAutoBootstrap(document) {
var script = document.currentScript;
if (!script) {
// Support: IE 9-11 only
// IE does not have `document.currentScript`
return true;
}
// If the `currentScript` property has been clobbered just return false, since this indicates a probable attack
if (!(script instanceof window.HTMLScriptElement || script instanceof window.SVGScriptElement)) {
return false;
}
var attributes = script.attributes;
var srcs = [attributes.getNamedItem('src'), attributes.getNamedItem('href'), attributes.getNamedItem('xlink:href')];
return srcs.every(function(src) {
if (!src) {
return true;
}
if (!src.value) {
return false;
}
var link = document.createElement('a');
link.href = src.value;
if (document.location.origin === link.origin) {
// Same-origin resources are always allowed, even for banned URL schemes.
return true;
}
// Disabled bootstrapping unless angular.js was loaded from a known scheme used on the web.
// This is to prevent angular.js bundled with browser extensions from being used to bypass the
// content security policy in web pages and other browser extensions.
switch (link.protocol) {
case 'http:':
case 'https:':
case 'ftp:':
case 'blob:':
case 'file:':
case 'data:':
return true;
default:
return false;
}
});
}
|
This method is intended for encoding *key* or *value* parts of query component. We need a custom
method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
encoded per http://tools.ietf.org/html/rfc3986:
query = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
|
allowAutoBootstrap
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function angularInit(element, bootstrap) {
var appElement,
module,
config = {};
// The element `element` has priority over any other element.
forEach(ngAttrPrefixes, function(prefix) {
var name = prefix + 'app';
if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
appElement = element;
module = element.getAttribute(name);
}
});
forEach(ngAttrPrefixes, function(prefix) {
var name = prefix + 'app';
var candidate;
if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) {
appElement = candidate;
module = candidate.getAttribute(name);
}
});
if (appElement) {
if (!isAutoBootstrapAllowed) {
window.console.error('AngularJS: disabling automatic bootstrap. <script> protocol indicates ' +
'an extension, document.location.href does not match.');
return;
}
config.strictDi = getNgAttribute(appElement, 'strict-di') !== null;
bootstrap(appElement, module ? [module] : [], config);
}
}
|
@ngdoc directive
@name ngApp
@module ng
@element ANY
@param {angular.Module} ngApp an optional application
{@link angular.module module} name to load.
@param {boolean=} ngStrictDi if this attribute is present on the app element, the injector will be
created in "strict-di" mode. This means that the application will fail to invoke functions which
do not use explicit function annotation (and are thus unsuitable for minification), as described
in {@link guide/di the Dependency Injection guide}, and useful debugging info will assist in
tracking down the root of these bugs.
@description
Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
designates the **root element** of the application and is typically placed near the root element
of the page - e.g. on the `<body>` or `<html>` tags.
There are a few things to keep in mind when using `ngApp`:
- only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
found in the document will be used to define the root element to auto-bootstrap as an
application. To run multiple applications in an HTML document you must manually bootstrap them using
{@link angular.bootstrap} instead.
- AngularJS applications cannot be nested within each other.
- Do not use a directive that uses {@link ng.$compile#transclusion transclusion} on the same element as `ngApp`.
This includes directives such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and
{@link ngRoute.ngView `ngView`}.
Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
causing animations to stop working and making the injector inaccessible from outside the app.
You can specify an **AngularJS module** to be used as the root module for the application. This
module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
should contain the application code needed or have dependencies on other modules that will
contain the code. See {@link angular.module} for more information.
In the example below if the `ngApp` directive were not placed on the `html` element then the
document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
would not be resolved to `3`.
@example
### Simple Usage
`ngApp` is the easiest, and most common way to bootstrap an application.
<example module="ngAppDemo" name="ng-app">
<file name="index.html">
<div ng-controller="ngAppDemoController">
I can add: {{a}} + {{b}} = {{ a+b }}
</div>
</file>
<file name="script.js">
angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
$scope.a = 1;
$scope.b = 2;
});
</file>
</example>
@example
### With `ngStrictDi`
Using `ngStrictDi`, you would see something like this:
<example ng-app-included="true" name="strict-di">
<file name="index.html">
<div ng-app="ngAppStrictDemo" ng-strict-di>
<div ng-controller="GoodController1">
I can add: {{a}} + {{b}} = {{ a+b }}
<p>This renders because the controller does not fail to
instantiate, by using explicit annotation style (see
script.js for details)
</p>
</div>
<div ng-controller="GoodController2">
Name: <input ng-model="name"><br />
Hello, {{name}}!
<p>This renders because the controller does not fail to
instantiate, by using explicit annotation style
(see script.js for details)
</p>
</div>
<div ng-controller="BadController">
I can add: {{a}} + {{b}} = {{ a+b }}
<p>The controller could not be instantiated, due to relying
on automatic function annotations (which are disabled in
strict mode). As such, the content of this section is not
interpolated, and there should be an error in your web console.
</p>
</div>
</div>
</file>
<file name="script.js">
angular.module('ngAppStrictDemo', [])
// BadController will fail to instantiate, due to relying on automatic function annotation,
// rather than an explicit annotation
.controller('BadController', function($scope) {
$scope.a = 1;
$scope.b = 2;
})
// Unlike BadController, GoodController1 and GoodController2 will not fail to be instantiated,
// due to using explicit annotations using the array style and $inject property, respectively.
.controller('GoodController1', ['$scope', function($scope) {
$scope.a = 1;
$scope.b = 2;
}])
.controller('GoodController2', GoodController2);
function GoodController2($scope) {
$scope.name = 'World';
}
GoodController2.$inject = ['$scope'];
</file>
<file name="style.css">
div[ng-controller] {
margin-bottom: 1em;
-webkit-border-radius: 4px;
border-radius: 4px;
border: 1px solid;
padding: .5em;
}
div[ng-controller^=Good] {
border-color: #d6e9c6;
background-color: #dff0d8;
color: #3c763d;
}
div[ng-controller^=Bad] {
border-color: #ebccd1;
background-color: #f2dede;
color: #a94442;
margin-bottom: 0;
}
</file>
</example>
|
angularInit
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function bootstrap(element, modules, config) {
if (!isObject(config)) config = {};
var defaultConfig = {
strictDi: false
};
config = extend(defaultConfig, config);
var doBootstrap = function() {
element = jqLite(element);
if (element.injector()) {
var tag = (element[0] === window.document) ? 'document' : startingTag(element);
// Encode angle brackets to prevent input from being sanitized to empty string #8683.
throw ngMinErr(
'btstrpd',
'App already bootstrapped with this element \'{0}\'',
tag.replace(/</,'<').replace(/>/,'>'));
}
modules = modules || [];
modules.unshift(['$provide', function($provide) {
$provide.value('$rootElement', element);
}]);
if (config.debugInfoEnabled) {
// Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`.
modules.push(['$compileProvider', function($compileProvider) {
$compileProvider.debugInfoEnabled(true);
}]);
}
modules.unshift('ng');
var injector = createInjector(modules, config.strictDi);
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
function bootstrapApply(scope, element, compile, injector) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
}]
);
return injector;
};
var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/;
var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/;
if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) {
config.debugInfoEnabled = true;
window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, '');
}
if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) {
return doBootstrap();
}
window.name = window.name.replace(NG_DEFER_BOOTSTRAP, '');
angular.resumeBootstrap = function(extraModules) {
forEach(extraModules, function(module) {
modules.push(module);
});
return doBootstrap();
};
if (isFunction(angular.resumeDeferredBootstrap)) {
angular.resumeDeferredBootstrap();
}
}
|
@ngdoc function
@name angular.bootstrap
@module ng
@description
Use this function to manually start up AngularJS application.
For more information, see the {@link guide/bootstrap Bootstrap guide}.
AngularJS will detect if it has been loaded into the browser more than once and only allow the
first loaded script to be bootstrapped and will report a warning to the browser console for
each of the subsequent scripts. This prevents strange results in applications, where otherwise
multiple instances of AngularJS try to work on the DOM.
<div class="alert alert-warning">
**Note:** Protractor based end-to-end tests cannot use this function to bootstrap manually.
They must use {@link ng.directive:ngApp ngApp}.
</div>
<div class="alert alert-warning">
**Note:** Do not bootstrap the app on an element with a directive that uses {@link ng.$compile#transclusion transclusion},
such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
causing animations to stop working and making the injector inaccessible from outside the app.
</div>
```html
<!doctype html>
<html>
<body>
<div ng-controller="WelcomeController">
{{greeting}}
</div>
<script src="angular.js"></script>
<script>
var app = angular.module('demo', [])
.controller('WelcomeController', function($scope) {
$scope.greeting = 'Welcome!';
});
angular.bootstrap(document, ['demo']);
</script>
</body>
</html>
```
@param {DOMElement} element DOM element which is the root of AngularJS application.
@param {Array<String|Function|Array>=} modules an array of modules to load into the application.
Each item in the array should be the name of a predefined module or a (DI annotated)
function that will be invoked by the injector as a `config` block.
See: {@link angular.module modules}
@param {Object=} config an object for defining configuration options for the application. The
following keys are supported:
* `strictDi` - disable automatic function annotation for the application. This is meant to
assist in finding bugs which break minified code. Defaults to `false`.
@returns {auto.$injector} Returns the newly created injector for this app.
|
bootstrap
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
doBootstrap = function() {
element = jqLite(element);
if (element.injector()) {
var tag = (element[0] === window.document) ? 'document' : startingTag(element);
// Encode angle brackets to prevent input from being sanitized to empty string #8683.
throw ngMinErr(
'btstrpd',
'App already bootstrapped with this element \'{0}\'',
tag.replace(/</,'<').replace(/>/,'>'));
}
modules = modules || [];
modules.unshift(['$provide', function($provide) {
$provide.value('$rootElement', element);
}]);
if (config.debugInfoEnabled) {
// Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`.
modules.push(['$compileProvider', function($compileProvider) {
$compileProvider.debugInfoEnabled(true);
}]);
}
modules.unshift('ng');
var injector = createInjector(modules, config.strictDi);
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
function bootstrapApply(scope, element, compile, injector) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
}]
);
return injector;
}
|
@ngdoc function
@name angular.bootstrap
@module ng
@description
Use this function to manually start up AngularJS application.
For more information, see the {@link guide/bootstrap Bootstrap guide}.
AngularJS will detect if it has been loaded into the browser more than once and only allow the
first loaded script to be bootstrapped and will report a warning to the browser console for
each of the subsequent scripts. This prevents strange results in applications, where otherwise
multiple instances of AngularJS try to work on the DOM.
<div class="alert alert-warning">
**Note:** Protractor based end-to-end tests cannot use this function to bootstrap manually.
They must use {@link ng.directive:ngApp ngApp}.
</div>
<div class="alert alert-warning">
**Note:** Do not bootstrap the app on an element with a directive that uses {@link ng.$compile#transclusion transclusion},
such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
causing animations to stop working and making the injector inaccessible from outside the app.
</div>
```html
<!doctype html>
<html>
<body>
<div ng-controller="WelcomeController">
{{greeting}}
</div>
<script src="angular.js"></script>
<script>
var app = angular.module('demo', [])
.controller('WelcomeController', function($scope) {
$scope.greeting = 'Welcome!';
});
angular.bootstrap(document, ['demo']);
</script>
</body>
</html>
```
@param {DOMElement} element DOM element which is the root of AngularJS application.
@param {Array<String|Function|Array>=} modules an array of modules to load into the application.
Each item in the array should be the name of a predefined module or a (DI annotated)
function that will be invoked by the injector as a `config` block.
See: {@link angular.module modules}
@param {Object=} config an object for defining configuration options for the application. The
following keys are supported:
* `strictDi` - disable automatic function annotation for the application. This is meant to
assist in finding bugs which break minified code. Defaults to `false`.
@returns {auto.$injector} Returns the newly created injector for this app.
|
doBootstrap
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function reloadWithDebugInfo() {
window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name;
window.location.reload();
}
|
@ngdoc function
@name angular.reloadWithDebugInfo
@module ng
@description
Use this function to reload the current application with debug information turned on.
This takes precedence over a call to `$compileProvider.debugInfoEnabled(false)`.
See {@link ng.$compileProvider#debugInfoEnabled} for more.
|
reloadWithDebugInfo
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function getTestability(rootElement) {
var injector = angular.element(rootElement).injector();
if (!injector) {
throw ngMinErr('test',
'no injector found for element argument to getTestability');
}
return injector.get('$$testability');
}
|
@name angular.getTestability
@module ng
@description
Get the testability service for the instance of AngularJS on the given
element.
@param {DOMElement} element DOM element which is the root of AngularJS application.
|
getTestability
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function snake_case(name, separator) {
separator = separator || '_';
return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) {
return (pos ? separator : '') + letter.toLowerCase();
});
}
|
@name angular.getTestability
@module ng
@description
Get the testability service for the instance of AngularJS on the given
element.
@param {DOMElement} element DOM element which is the root of AngularJS application.
|
snake_case
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function bindJQuery() {
var originalCleanData;
if (bindJQueryFired) {
return;
}
// bind to jQuery if present;
var jqName = jq();
jQuery = isUndefined(jqName) ? window.jQuery : // use jQuery (if present)
!jqName ? undefined : // use jqLite
window[jqName]; // use jQuery specified by `ngJq`
// Use jQuery if it exists with proper functionality, otherwise default to us.
// AngularJS 1.2+ requires jQuery 1.7+ for on()/off() support.
// AngularJS 1.3+ technically requires at least jQuery 2.1+ but it may work with older
// versions. It will not work for sure with jQuery <1.7, though.
if (jQuery && jQuery.fn.on) {
jqLite = jQuery;
extend(jQuery.fn, {
scope: JQLitePrototype.scope,
isolateScope: JQLitePrototype.isolateScope,
controller: /** @type {?} */ (JQLitePrototype).controller,
injector: JQLitePrototype.injector,
inheritedData: JQLitePrototype.inheritedData
});
} else {
jqLite = JQLite;
}
// All nodes removed from the DOM via various jqLite/jQuery APIs like .remove()
// are passed through jqLite/jQuery.cleanData. Monkey-patch this method to fire
// the $destroy event on all removed nodes.
originalCleanData = jqLite.cleanData;
jqLite.cleanData = function(elems) {
var events;
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
events = (jqLite._data(elem) || {}).events;
if (events && events.$destroy) {
jqLite(elem).triggerHandler('$destroy');
}
}
originalCleanData(elems);
};
angular.element = jqLite;
// Prevent double-proxying.
bindJQueryFired = true;
}
|
@name angular.getTestability
@module ng
@description
Get the testability service for the instance of AngularJS on the given
element.
@param {DOMElement} element DOM element which is the root of AngularJS application.
|
bindJQuery
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function UNSAFE_restoreLegacyJqLiteXHTMLReplacement() {
JQLite.legacyXHTMLReplacement = true;
}
|
@ngdoc function
@name angular.UNSAFE_restoreLegacyJqLiteXHTMLReplacement
@module ng
@kind function
@description
Restores the pre-1.8 behavior of jqLite that turns XHTML-like strings like
`<div /><span />` to `<div></div><span></span>` instead of `<div><span></span></div>`.
The new behavior is a security fix. Thus, if you need to call this function, please try to adjust
your code for this change and remove your use of this function as soon as possible.
Note that this only patches jqLite. If you use jQuery 3.5.0 or newer, please read the
[jQuery 3.5 upgrade guide](https://jquery.com/upgrade-guide/3.5/) for more details
about the workarounds.
|
UNSAFE_restoreLegacyJqLiteXHTMLReplacement
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function assertArg(arg, name, reason) {
if (!arg) {
throw ngMinErr('areq', 'Argument \'{0}\' is {1}', (name || '?'), (reason || 'required'));
}
return arg;
}
|
throw error if the argument is falsy.
|
assertArg
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function assertArgFn(arg, name, acceptArrayAnnotation) {
if (acceptArrayAnnotation && isArray(arg)) {
arg = arg[arg.length - 1];
}
assertArg(isFunction(arg), name, 'not a function, got ' +
(arg && typeof arg === 'object' ? arg.constructor.name || 'Object' : typeof arg));
return arg;
}
|
throw error if the argument is falsy.
|
assertArgFn
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function assertNotHasOwnProperty(name, context) {
if (name === 'hasOwnProperty') {
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
}
}
|
throw error if the name given is hasOwnProperty
@param {String} name the name to test
@param {String} context the context in which the name is used, such as module or directive
|
assertNotHasOwnProperty
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function getter(obj, path, bindFnToScope) {
if (!path) return obj;
var keys = path.split('.');
var key;
var lastInstance = obj;
var len = keys.length;
for (var i = 0; i < len; i++) {
key = keys[i];
if (obj) {
obj = (lastInstance = obj)[key];
}
}
if (!bindFnToScope && isFunction(obj)) {
return bind(lastInstance, obj);
}
return obj;
}
|
Return the value accessible from the object by path. Any undefined traversals are ignored
@param {Object} obj starting object
@param {String} path path to traverse
@param {boolean} [bindFnToScope=true]
@returns {Object} value as accessible by path
|
getter
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function getBlockNodes(nodes) {
// TODO(perf): update `nodes` instead of creating a new object?
var node = nodes[0];
var endNode = nodes[nodes.length - 1];
var blockNodes;
for (var i = 1; node !== endNode && (node = node.nextSibling); i++) {
if (blockNodes || nodes[i] !== node) {
if (!blockNodes) {
blockNodes = jqLite(slice.call(nodes, 0, i));
}
blockNodes.push(node);
}
}
return blockNodes || nodes;
}
|
Return the DOM siblings between the first and last node in the given array.
@param {Array} array like object
@returns {Array} the inputted object or a jqLite collection containing the nodes
|
getBlockNodes
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function createMap() {
return Object.create(null);
}
|
Creates a new object without a prototype. This object is useful for lookup without having to
guard against prototypically inherited properties via hasOwnProperty.
Related micro-benchmarks:
- http://jsperf.com/object-create2
- http://jsperf.com/proto-map-lookup/2
- http://jsperf.com/for-in-vs-object-keys2
@returns {Object}
|
createMap
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function stringify(value) {
if (value == null) { // null || undefined
return '';
}
switch (typeof value) {
case 'string':
break;
case 'number':
value = '' + value;
break;
default:
if (hasCustomToString(value) && !isArray(value) && !isDate(value)) {
value = value.toString();
} else {
value = toJson(value);
}
}
return value;
}
|
Creates a new object without a prototype. This object is useful for lookup without having to
guard against prototypically inherited properties via hasOwnProperty.
Related micro-benchmarks:
- http://jsperf.com/object-create2
- http://jsperf.com/proto-map-lookup/2
- http://jsperf.com/for-in-vs-object-keys2
@returns {Object}
|
stringify
|
javascript
|
angular/angular.js
|
src/Angular.js
|
https://github.com/angular/angular.js/blob/master/src/Angular.js
|
MIT
|
function hashKey(obj, nextUidFn) {
var key = obj && obj.$$hashKey;
if (key) {
if (typeof key === 'function') {
key = obj.$$hashKey();
}
return key;
}
var objType = typeof obj;
if (objType === 'function' || (objType === 'object' && obj !== null)) {
key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
} else {
key = objType + ':' + obj;
}
return key;
}
|
Computes a hash of an 'obj'.
Hash of a:
string is string
number is number as string
object is either result of calling $$hashKey function on the object or uniquely generated id,
that is also assigned to the $$hashKey property of the object.
@param obj
@returns {string} hash string such that the same input will have the same hash string.
The resulting string key is in 'type:hashKey' format.
|
hashKey
|
javascript
|
angular/angular.js
|
src/apis.js
|
https://github.com/angular/angular.js/blob/master/src/apis.js
|
MIT
|
function NgMapShim() {
this._keys = [];
this._values = [];
this._lastKey = NaN;
this._lastIndex = -1;
}
|
Computes a hash of an 'obj'.
Hash of a:
string is string
number is number as string
object is either result of calling $$hashKey function on the object or uniquely generated id,
that is also assigned to the $$hashKey property of the object.
@param obj
@returns {string} hash string such that the same input will have the same hash string.
The resulting string key is in 'type:hashKey' format.
|
NgMapShim
|
javascript
|
angular/angular.js
|
src/apis.js
|
https://github.com/angular/angular.js/blob/master/src/apis.js
|
MIT
|
function cssKebabToCamel(name) {
return kebabToCamel(name.replace(MS_HACK_REGEXP, 'ms-'));
}
|
Converts kebab-case to camelCase.
There is also a special case for the ms prefix starting with a lowercase letter.
@param name Name to normalize
|
cssKebabToCamel
|
javascript
|
angular/angular.js
|
src/jqLite.js
|
https://github.com/angular/angular.js/blob/master/src/jqLite.js
|
MIT
|
function fnCamelCaseReplace(all, letter) {
return letter.toUpperCase();
}
|
Converts kebab-case to camelCase.
There is also a special case for the ms prefix starting with a lowercase letter.
@param name Name to normalize
|
fnCamelCaseReplace
|
javascript
|
angular/angular.js
|
src/jqLite.js
|
https://github.com/angular/angular.js/blob/master/src/jqLite.js
|
MIT
|
function kebabToCamel(name) {
return name
.replace(DASH_LOWERCASE_REGEXP, fnCamelCaseReplace);
}
|
Converts kebab-case to camelCase.
@param name Name to normalize
|
kebabToCamel
|
javascript
|
angular/angular.js
|
src/jqLite.js
|
https://github.com/angular/angular.js/blob/master/src/jqLite.js
|
MIT
|
function jqLiteIsTextNode(html) {
return !HTML_REGEXP.test(html);
}
|
Converts kebab-case to camelCase.
@param name Name to normalize
|
jqLiteIsTextNode
|
javascript
|
angular/angular.js
|
src/jqLite.js
|
https://github.com/angular/angular.js/blob/master/src/jqLite.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.