Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ngify
Advanced tools
Readme
Ngify is a Browserify transform that performs the following tasks for building Angular 1.x apps:
Ngify provides these benefits:
Use in conjunction with require-globify to easily bulk load files.
Configure browserify to use this transform in package.json:
"browserify": {
"transform": [
"ngify"
]
}
Configure browserify to use this transform in package.json with settings:
"browserify": {
"transform": [
[
"ngify",
{
moduleName: "test"
}
]
]
}
Configure browserify to use this transform programmatically:
var b = browserify(options)
.transform(require('ngify'))
Configure browserify to use this transform programmatically with settings:
var b = browserify()
.transform(require('ngify'), {moduleName: 'test'})
Require an HTML file (the name registered with Angular's $templateCache is returned):
require('./templates/angularTemplate.html');
Here is an example of the contents of angularTemplate.html:
<div>
{{value}}
<div>
Ngify replaces the file contents with the following:
angular.module('ngify')
.run([
'$templateCache',
function($templateCache){
$templateCache.put(
'angularTemplate.html',
'<div> {{value}} </div>'
)
}
])
Require a JavaScript file:
require('./lib/myLib.js');
Here is an example of the contents of myLib.js:
function MyCtrl (serviceName){
this.message = 'Hello World!';
}
MyCtrl.prototype.sayHello = function(){
console.log(this.message);
}
exports = module.exports = MyCtrl
exports['@ng'] = {
name: 'myCtrl',
type: 'controller',
inject: [ 'serviceName' ],
}
The annotation statement is deleted and Ngify appends the following code to the file contents:
angular.module('ngify')
.controller('myCtrl', [ 'serviceName', module.exports ])
name (Required when used)
type (Required)
inject (Optional when used)
The names of the injectables used in Angular's minification syntax.
Not used for value and constant types.
Here is an example of the contents of myLib.js without the optional inject property:
function MyCtrl (serviceName){ this.message = 'Hello World!'; }
MyCtrl.prototype.sayHello = function(){ console.log(this.message); }
exports = module.exports = MyCtrl
exports['@ng'] = { name: 'myCtrl', type: 'controller', }
The injectables are read from the function signature, the annotation statement is deleted and the following is appended to the file contents:
angular.module('ngify')
.controller('myCtrl', [ 'serviceName', module.exports ])
Both the name and type can be taken from the file name, allowing annotations to be optional.
Annotation values always override the filename when they are present. Filename formats are as follows:
<name>.<type>.js (annotation is optional)
<name>.js (annotation is required)
For example, the following filename:
myCtrl.controller.js
and no annotation, will result in this output:
angular.module('ngify')
.controller('myCtrl', [ 'serviceName', module.exports ])
The type can be omitted from the filename, but the annotation is required in this case:
myCtrl.js
plus this annotation:
exports['@ng'] = {
type: 'controller'
}
will provide the same output as above:
angular.module('ngify')
.controller('myCtrl', [ 'serviceName', module.exports ])
To change the default settings, you can configure ngify as follows (the defaults are shown):
"browserify": {
"transform": [
[
"ngify",
{
"moduleName": 'ngify',
"moduleTemplate": "angular.module('{moduleName}')",
"htmlExtension": ".html",
"htmlTemplate": ".run(['$templateCache', function($templateCache){$templateCache.put('{templateName}','{html}')}])",
"htmlPath": false,
"htmlMinifyArgs": {
"collapseWhitespace": true,
"conservativeCollapse": true
},
"jsExtension": ".js",
"jsAnnotation": "@ng",
"jsTemplates": {
"provider": ".{type}('{name}', [ {inject}module.exports ] );",
"factory": ".{type}('{name}', [ {inject}module.exports ] );",
"service": ".{type}('{name}', [ {inject}module.exports ] );",
"animation": ".{type}('{name}', [ {inject}module.exports ] );",
"filter": ".{type}('{name}', [ {inject}module.exports ] );",
"controller": ".{type}('{name}', [ {inject}module.exports ] );",
"directive": ".{type}('{name}', [ {inject}module.exports ] );",
"value": ".{type}('{name}', module.exports );",
"constant": ".{type}('{name}', module.exports );",
"config": ".{type}([ {inject}module.exports ]);",
"run": ".{type}([ {inject}module.exports ]);"
}
}
]
]
Here is a description of each setting:
moduleName
angular.module('ngify', [])
moduleTemplate
htmlExtension
.ng.html
might identify
your angular templateshtmlTemplate
htmlPath
htmlMinifyArgs
jsExtension
.ng.js
might identify your angular filesjsAnnotation
jsTemplates
type
propertyv1.6.0 - htmlPath option allows for prefixed html template
v1.5.0 - html-minifier v1.4.0
v1.4.0 - The name registered with Angular's $templateCache is now returned from the require of html files
v1.3.0 - Annotations are now optional, with the name and type coming from the filename.
v1.2.0 - The annotation statements are now removed from the output
v1.1.0 - The inject annotation is now optional
v1.0.0 - Breaking changes to add support for annotations
The following configuration properties were renamed:
Support for @ng annotations was added
v0.1.0 - Breaking changes to eliminate file system calls
Execute tests for a single run:
npm test
Execute tests for continuous testing with changes:
npm run autotest
The MIT License (MIT)
Copyright (c) 2014 majgis
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.
FAQs
Browserify transform for Angular 1.x
The npm package ngify receives a total of 30 weekly downloads. As such, ngify popularity was classified as not popular.
We found that ngify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.