Full Code of toddmotto/angular-component for AI

master 86a65539136e cached
11 files
19.9 KB
4.9k tokens
4 symbols
1 requests
Download .txt
Repository: toddmotto/angular-component
Branch: master
Commit: 86a65539136e
Files: 11
Total size: 19.9 KB

Directory structure:
gitextract_rmb3cuj_/

├── .editorconfig
├── .gitignore
├── .jshintrc
├── .travis.yml
├── LICENSE
├── README.md
├── bower.json
├── dist/
│   └── angular-component.js
├── gulpfile.js
├── package.json
└── src/
    └── angular-component.js

================================================
FILE CONTENTS
================================================

================================================
FILE: .editorconfig
================================================
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false


================================================
FILE: .gitignore
================================================
# Node
node_modules

## OS X
.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.Spotlight-V100
.Trashes

## Windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/


================================================
FILE: .jshintrc
================================================
{
  "node": true,
  "browser": true,
  "esnext": true,
  "bitwise": true,
  "camelcase": true,
  "curly": false,
  "eqeqeq": true,
  "indent": 2,
  "loopfunc": true,
  "immed": true,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "quotmark": "single",
  "regexp": true,
  "undef": true,
  "unused": false,
  "trailing": false,
  "sub": true,
  "globals": {
    "angular": true
  }
}


================================================
FILE: .travis.yml
================================================
language: node_js
node_js:
  - "0.10"
  - "0.11"
before_script:
  - npm install -g gulp
script: gulp


================================================
FILE: LICENSE
================================================
LICENSE

The MIT License

Copyright (c) 2015 Todd Motto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


================================================
FILE: README.md
================================================
# angular-component.js

Start using `.component()` now!

> [View live demo in v1.3.0](https://jsfiddle.net/vz53audf)

angular-component.js is a `~1kb` script that adds `component()` support in Angular 1.5 to all Angular versions above `1.3`, so you can begin using the new method now.

_Note_: you must include this script straight after `angular.js` and before your application code to ensure the `component()` method has been added to the `angular.module` global.

> Read about the Angular 1.5 `component()` method [here](http://toddmotto.com/exploring-the-angular-1-5-component-method)

### Polyfill support

This polyfill supports the following feature set of the `.component()` method:

| Feature                                                        | Supports  |
|----------------------------------------------------------------|-----------|
| `angular.module.component()` method                            | Yes       |
| `bindings` property                                            | Yes       |
| `'E'` restrict default                                         | Yes       |
| `$ctrl` controllerAs default                                   | Yes       |
| `transclude` property                                          | Yes       |
| `template` support                                             | Yes       |
| `templateUrl` injectable for `$element` and `$attrs`           | Yes       |
| One-way data-binding emulated                                  | Yes       |
| Lifecycles: `$onInit`, `$onChanges`m `$postLink`, `$onDestroy` | Yes       |
| `require` Object for parent Component inheritance              | Yes       |
| `$` prefixed properties such as `$canActivate`                 | Yes       |

### Component method usage

```html
<div ng-app="app">
  <div ng-controller="MainCtrl as vm">
    <counter count="vm.count"></counter>
  </div>
</div>

<script>
angular
	.module('app', [])
  .component('parentComponent', {
    template: `
      <div>
        {{ $ctrl.user }}
        <child-component user="$ctrl.user" on-update="$ctrl.updateUser($event);"></child-component>
      </div>
    `,
    controller: function () {
      this.user = {
        name: 'Todd',
        location: 'England, UK'
      };
      this.updateUser = function (event) {
        this.user = event.user;
      };
    }
  })
	.component('childComponent', {
    bindings: {
      user: '<',
      onUpdate: '&'
    },
    controller: function () {
    	this.$onInit = function () {
        // component initialisation
      };
      this.$onChanges = function (changes) {
        if (changes.user) {
          this.user = angular.copy(this.user);
        }
      };
      this.$postLink = function () {
        // component post-link
      };
      this.$onDestroy = function () {
        // component $destroy function
      };
    },
    template: `
      <div>
        <input type="text" ng-model="$ctrl.user.name">
        <a href="" ng-click="$ctrl.onUpdate({$event: {user: $ctrl.user}});">Update</a>
      </div>
    `
  });
</script>
```

## Installing with NPM

```
npm install angular-component --save
```

## Installing with Bower

```
bower install angular-component.js --save
```

## Manual installation
Ensure you're using the files from the `dist` directory (contains compiled production-ready code). Ensure you place the script before the closing `</body>` tag.

```html
<body>
  <!-- html above -->
  <script src="angular-1.x.js"></script>
  <script src="dist/angular-component.js"></script>
  <script src="app.js"></script>
</body>
```

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.

## Release history

- 0.1.2
  - Version fixes
- 0.1.1
  - Version fixes
- 0.1.0
  - Add one-way data-binding and $onChanges lifecycle, stable release
- 0.0.8
  - Add new lifecycle hooks ($onInit, $onDestroy, $postLink)
- 0.0.7
  - Add `require` property from 1.5 stable, `restrict: 'E'` as default
- 0.0.6
  - Add automated `$` prefixed properties to factory Object
- 0.0.5
  - Add automatic function annotations
- 0.0.4
  - Fix Array dependency annotations [#11](https://github.com/toddmotto/angular-component/issues/11)
- 0.0.3
  - Fix bug caused by bugfix (aligns with new 1.5 changes)
- 0.0.2
  - Bugfix isolate scope when `bindings` is omitted, short-circuit if .component() is already supported
- 0.0.1
  - Initial release


================================================
FILE: bower.json
================================================
{
  "name": "angular-component.js",
  "version": "0.0.7",
  "main": "./dist/angular-component.min.js",
  "dependencies": {
    "angular": ">=1.3.0 <=1.5"
  },
  "homepage": "https://github.com/toddmotto/angular-component",
  "authors": [
    "Todd Motto <todd@toddmotto.com>"
  ],
  "description": "Angular component() polyfill for v1.3+",
  "moduleType": [],
  "keywords": [
    "Angular",
    "Component",
    "Directives"
  ],
  "license": "MIT",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ]
}


================================================
FILE: dist/angular-component.js
================================================
/*! angular-component v0.1.3 | (c) 2017 @toddmotto | https://github.com/toddmotto/angular-component */
(function () {

  var ng = angular.module;

  function identifierForController(controller, ident) {
    if (ident && typeof ident === 'string') return ident;
    if (typeof controller === 'string') {
      var match = /^(\S+)(\s+as\s+(\w+))?$/.exec(controller);
      if (match) return match[3];
    }
  }

  function module() {

    var hijacked = ng.apply(this, arguments);

    if (hijacked.component) {
      return hijacked;
    }

    function component(name, options) {

      function factory($injector) {

        function makeInjectable(fn) {
          var closure;
          var isArray = angular.isArray(fn);
          if (angular.isFunction(fn) || isArray) {
            return function (tElement, tAttrs) {
              return $injector.invoke((isArray ? fn : [
                '$element',
                '$attrs',
                fn
              ]), this, {
                $element: tElement,
                $attrs: tAttrs
              });
            };
          } else {
            return fn;
          }
        }

        var oneWayQueue = [];

        function parseBindings(bindings) {
          var newBindings = {};
          for (var prop in bindings) {
            var binding = bindings[prop];
            if (binding.charAt(0) === '<') {
              var attr = binding.substring(1);
              oneWayQueue.unshift({
              	local: prop,
                attr: attr === '' ? prop : attr
              });
            } else {
              newBindings[prop] = binding;
            }
          }
          return newBindings;
        }

        var modifiedBindings = parseBindings(options.bindings);

        var requires = [name];
        var ctrlNames = [];
        if (angular.isObject(options.require)) {
          for (var prop in options.require) {
            requires.push(options.require[prop]);
            ctrlNames.push(prop);
          }
        }

        return {
          controller: options.controller || angular.noop,
          controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
          template: makeInjectable(
            !options.template && !options.templateUrl ? '' : options.template
          ),
          templateUrl: makeInjectable(options.templateUrl),
          transclude: options.transclude,
          scope: modifiedBindings || {},
          bindToController: !!modifiedBindings,
          restrict: 'E',
          require: requires,
          link: {
            pre: function ($scope, $element, $attrs, $ctrls) {
              var self = $ctrls[0];
              for (var i = 0; i < ctrlNames.length; i++) {
                self[ctrlNames[i]] = $ctrls[i + 1];
              }
              if (typeof self.$onDestroy === 'function') {
                $scope.$on('$destroy', function () {
                  self.$onDestroy.call(self);
                });
              }
              var changes;
              function triggerOnChanges() {
                self.$onChanges(changes);
                changes = undefined;
              }
              function updateChangeListener(key, newValue, oldValue, flush) {
                if (typeof self.$onChanges === 'function') {
                  if (!changes) {
                    changes = {};
                  }
                  if (changes[key]) {
                    oldValue = changes[key].currentValue;
                  }
                  changes[key] = {
                    currentValue: newValue,
                    previousValue: oldValue
                  };
                  if (flush) {
                    triggerOnChanges();
                  }
                }
              }
              if (oneWayQueue.length) {
                var destroyQueue = [];
                for (var q = oneWayQueue.length; q--;) {
                  (function(current){
                    self[current.local] = $scope.$parent.$eval($attrs[current.attr]);
                    var unbindParent = $scope.$parent.$watch($attrs[current.attr], function (newValue, oldValue) {
                      self[current.local] = newValue;
                      updateChangeListener(current.local, newValue, oldValue, true);
                    });
                    destroyQueue.unshift(unbindParent);
                    var unbindLocal = $scope.$watch(function () {
                      return self[current.local];
                    }, function (newValue, oldValue) {
                      updateChangeListener(current.local, newValue, oldValue, false);
                    });
                    destroyQueue.unshift(unbindLocal);
                  })(oneWayQueue[q]);
                }
                $scope.$on('$destroy', function () {
                  for (var i = destroyQueue.length; i--;) {
                    destroyQueue[i]();
                  }
                });
              }
              if (typeof self.$onInit === 'function') {
                self.$onInit();
              }
            },
            post: function ($scope, $element, $attrs, $ctrls) {
              var self = $ctrls[0];
              if (typeof self.$postLink === 'function') {
                self.$postLink();
              }
            }
          }
        };
      }

      for (var key in options) {
        if (key.charAt(0) === '$') {
          factory[key] = options[key];
        }
      }

      factory.$inject = ['$injector'];

      return hijacked.directive(name, factory);

    }

    hijacked.component = component;

    return hijacked;

  }

  angular.module = module;

})();


================================================
FILE: gulpfile.js
================================================
var gulp    = require('gulp'),
    jshint  = require('gulp-jshint'),
    stylish = require('jshint-stylish'),
    header  = require('gulp-header'),
    uglify  = require('gulp-uglify'),
    plumber = require('gulp-plumber'),
    clean   = require('gulp-clean'),
    rename  = require('gulp-rename'),
    package = require('./package.json');

var paths = {
  output : 'dist/',
  scripts : [
    'src/angular-component.js'
  ],
  test: [
    'test/spec/**/*.js'
  ]
};

var banner = [
  '/*! ',
    '<%= package.name %> ',
    'v<%= package.version %> | ',
    '(c) ' + new Date().getFullYear() + ' <%= package.author %> |',
    ' <%= package.homepage %>',
  ' */',
  '\n'
].join('');

gulp.task('scripts', ['clean'], function() {
  return gulp.src(paths.scripts)
    .pipe(plumber())
    .pipe(header(banner, { package : package }))
    .pipe(gulp.dest('dist/'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(uglify())
    .pipe(header(banner, { package : package }))
    .pipe(gulp.dest('dist/'));
});

gulp.task('lint', function () {
  return gulp.src(paths.scripts)
    .pipe(plumber())
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('clean', function () {
  return gulp.src(paths.output, { read: false })
    .pipe(plumber())
    .pipe(clean());
});

gulp.task('default', [
  'lint',
  'clean',
  'scripts'
]);


================================================
FILE: package.json
================================================
{
  "name": "angular-component",
  "version": "0.1.3",
  "main": "./dist/angular-component.min.js",
  "description": "Angular component() polyfill",
  "author": "@toddmotto",
  "license": "MIT",
  "homepage": "https://github.com/toddmotto/angular-component",
  "repository": {
    "type": "git",
    "url": "https://github.com/toddmotto/angular-component.git"
  },
  "devDependencies": {
    "gulp": "~3.9.0",
    "gulp-uglify": "~0.3.0",
    "gulp-rename": "~1.1.0",
    "gulp-clean": "^0.2.4",
    "gulp-plumber": "~0.6.2",
    "gulp-header": "^1.0.2",
    "gulp-jshint": "^1.6.1",
    "jshint-stylish": "^0.2.0"
  }
}


================================================
FILE: src/angular-component.js
================================================
(function () {

  var ng = angular.module;

  function identifierForController(controller, ident) {
    if (ident && typeof ident === 'string') return ident;
    if (typeof controller === 'string') {
      var match = /^(\S+)(\s+as\s+(\w+))?$/.exec(controller);
      if (match) return match[3];
    }
  }

  function module() {

    var hijacked = ng.apply(this, arguments);

    if (hijacked.component) {
      return hijacked;
    }

    function component(name, options) {

      function factory($injector) {

        function makeInjectable(fn) {
          var closure;
          var isArray = angular.isArray(fn);
          if (angular.isFunction(fn) || isArray) {
            return function (tElement, tAttrs) {
              return $injector.invoke((isArray ? fn : [
                '$element',
                '$attrs',
                fn
              ]), this, {
                $element: tElement,
                $attrs: tAttrs
              });
            };
          } else {
            return fn;
          }
        }

        var oneWayQueue = [];

        function parseBindings(bindings) {
          var newBindings = {};
          for (var prop in bindings) {
            var binding = bindings[prop];
            if (binding.charAt(0) === '<') {
              var attr = binding.substring(1);
              oneWayQueue.unshift({
              	local: prop,
                attr: attr === '' ? prop : attr
              });
            } else {
              newBindings[prop] = binding;
            }
          }
          return newBindings;
        }

        var modifiedBindings = parseBindings(options.bindings);

        var requires = [name];
        var ctrlNames = [];
        if (angular.isObject(options.require)) {
          for (var prop in options.require) {
            requires.push(options.require[prop]);
            ctrlNames.push(prop);
          }
        }

        return {
          controller: options.controller || angular.noop,
          controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
          template: makeInjectable(
            !options.template && !options.templateUrl ? '' : options.template
          ),
          templateUrl: makeInjectable(options.templateUrl),
          transclude: options.transclude,
          scope: modifiedBindings || {},
          bindToController: !!modifiedBindings,
          restrict: 'E',
          require: requires,
          link: {
            pre: function ($scope, $element, $attrs, $ctrls) {
              var self = $ctrls[0];
              for (var i = 0; i < ctrlNames.length; i++) {
                self[ctrlNames[i]] = $ctrls[i + 1];
              }
              if (typeof self.$onDestroy === 'function') {
                $scope.$on('$destroy', function () {
                  self.$onDestroy.call(self);
                });
              }
              var changes;
              function triggerOnChanges() {
                self.$onChanges(changes);
                changes = undefined;
              }
              function updateChangeListener(key, newValue, oldValue, flush) {
                if (typeof self.$onChanges === 'function') {
                  if (!changes) {
                    changes = {};
                  }
                  if (changes[key]) {
                    oldValue = changes[key].currentValue;
                  }
                  changes[key] = {
                    currentValue: newValue,
                    previousValue: oldValue
                  };
                  if (flush) {
                    triggerOnChanges();
                  }
                }
              }
              if (oneWayQueue.length) {
                var destroyQueue = [];
                for (var q = oneWayQueue.length; q--;) {
                  (function(current){
                    self[current.local] = $scope.$parent.$eval($attrs[current.attr]);
                    var unbindParent = $scope.$parent.$watch($attrs[current.attr], function (newValue, oldValue) {
                      self[current.local] = newValue;
                      updateChangeListener(current.local, newValue, oldValue, true);
                    });
                    destroyQueue.unshift(unbindParent);
                    var unbindLocal = $scope.$watch(function () {
                      return self[current.local];
                    }, function (newValue, oldValue) {
                      updateChangeListener(current.local, newValue, oldValue, false);
                    });
                    destroyQueue.unshift(unbindLocal);
                  })(oneWayQueue[q]);
                }
                $scope.$on('$destroy', function () {
                  for (var i = destroyQueue.length; i--;) {
                    destroyQueue[i]();
                  }
                });
              }
              if (typeof self.$onInit === 'function') {
                self.$onInit();
              }
            },
            post: function ($scope, $element, $attrs, $ctrls) {
              var self = $ctrls[0];
              if (typeof self.$postLink === 'function') {
                self.$postLink();
              }
            }
          }
        };
      }

      for (var key in options) {
        if (key.charAt(0) === '$') {
          factory[key] = options[key];
        }
      }

      factory.$inject = ['$injector'];

      return hijacked.directive(name, factory);

    }

    hijacked.component = component;

    return hijacked;

  }

  angular.module = module;

})();
Download .txt
gitextract_rmb3cuj_/

├── .editorconfig
├── .gitignore
├── .jshintrc
├── .travis.yml
├── LICENSE
├── README.md
├── bower.json
├── dist/
│   └── angular-component.js
├── gulpfile.js
├── package.json
└── src/
    └── angular-component.js
Download .txt
SYMBOL INDEX (4 symbols across 2 files)

FILE: dist/angular-component.js
  function identifierForController (line 6) | function identifierForController(controller, ident) {
  function module (line 14) | function module() {

FILE: src/angular-component.js
  function identifierForController (line 5) | function identifierForController(controller, ident) {
  function module (line 13) | function module() {
Condensed preview — 11 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (22K chars).
[
  {
    "path": ".editorconfig",
    "chars": 414,
    "preview": "# EditorConfig helps developers define and maintain consistent\n# coding styles between different editors and IDEs\n# edit"
  },
  {
    "path": ".gitignore",
    "chars": 158,
    "preview": "# Node\nnode_modules\n\n## OS X\n.DS_Store\n.AppleDouble\n.LSOverride\nIcon\n._*\n.Spotlight-V100\n.Trashes\n\n## Windows\nThumbs.db\n"
  },
  {
    "path": ".jshintrc",
    "chars": 392,
    "preview": "{\n  \"node\": true,\n  \"browser\": true,\n  \"esnext\": true,\n  \"bitwise\": true,\n  \"camelcase\": true,\n  \"curly\": false,\n  \"eqeq"
  },
  {
    "path": ".travis.yml",
    "chars": 101,
    "preview": "language: node_js\nnode_js:\n  - \"0.10\"\n  - \"0.11\"\nbefore_script:\n  - npm install -g gulp\nscript: gulp\n"
  },
  {
    "path": "LICENSE",
    "chars": 1080,
    "preview": "LICENSE\n\nThe MIT License\n\nCopyright (c) 2015 Todd Motto\n\nPermission is hereby granted, free of charge, to any person obt"
  },
  {
    "path": "README.md",
    "chars": 4468,
    "preview": "# angular-component.js\n\nStart using `.component()` now!\n\n> [View live demo in v1.3.0](https://jsfiddle.net/vz53audf)\n\nan"
  },
  {
    "path": "bower.json",
    "chars": 551,
    "preview": "{\n  \"name\": \"angular-component.js\",\n  \"version\": \"0.0.7\",\n  \"main\": \"./dist/angular-component.min.js\",\n  \"dependencies\":"
  },
  {
    "path": "dist/angular-component.js",
    "chars": 5666,
    "preview": "/*! angular-component v0.1.3 | (c) 2017 @toddmotto | https://github.com/toddmotto/angular-component */\n(function () {\n\n "
  },
  {
    "path": "gulpfile.js",
    "chars": 1350,
    "preview": "var gulp    = require('gulp'),\n    jshint  = require('gulp-jshint'),\n    stylish = require('jshint-stylish'),\n    header"
  },
  {
    "path": "package.json",
    "chars": 621,
    "preview": "{\n  \"name\": \"angular-component\",\n  \"version\": \"0.1.3\",\n  \"main\": \"./dist/angular-component.min.js\",\n  \"description\": \"An"
  },
  {
    "path": "src/angular-component.js",
    "chars": 5563,
    "preview": "(function () {\n\n  var ng = angular.module;\n\n  function identifierForController(controller, ident) {\n    if (ident && typ"
  }
]

About this extraction

This page contains the full source code of the toddmotto/angular-component GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 11 files (19.9 KB), approximately 4.9k tokens, and a symbol index with 4 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!