Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iconfont

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iconfont - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

test/font-awesome.tss

58

bin.js

@@ -7,3 +7,4 @@ #!/usr/bin/env node

fs = require('fs'),
path = require('path');
path = require('path'),
util = require('util');

@@ -38,2 +39,3 @@ var

.version(pkg.version, '-v, --version')
.option('-t, --tss', 'export to Titanium Alloy Style Sheet(tss)')
.description(pkg.description)

@@ -59,4 +61,9 @@ .usage('<stylesheet> [js]')

js = path.normalize(program.args[1]);
if (js.match(/\.tss$/)) {
program.tss = true;
}
} else {
js = stylesheet.replace(/\.css$/, '.js');
js = stylesheet.replace(/\.css$/, program.tss ? '.tss' : '.js');
}

@@ -82,2 +89,3 @@

var prefixes = [];
var fontFamily = '';

@@ -87,2 +95,7 @@ _.each(obj.stylesheet.rules, function(rule) {

if (!rule.selectors || !rule.declarations) {
if (rule.type == 'font-face') {
fontFamily = _.findWhere(rule.declarations, {
property: 'font-family'
}).value.replace(/["']/g, '');
}
return;

@@ -142,22 +155,33 @@ }

data = 'module.exports = {\n';
if (program.tss) {
data = '/* ' + fontFamily + ' Styles (Generated by IconFont) */\n';
_.each(_.keys(icons), function(name, i) {
var unicode = icons[name];
_.each(_.keys(icons), function(name, i) {
var unicode = icons[name];
data += util.format('".%s": { font: { fontFamily: "%s"}, text: "%s", title: "%s"}\n',
name, fontFamily, unicode, unicode);
});
} else {
data = 'module.exports = {\n';
if (prefix) {
name = name.substr(prefix.length);
}
_.each(_.keys(icons), function(name, i) {
var unicode = icons[name];
if (name.indexOf('-') !== -1 || name.indexOf('_') !== -1) {
name = name.replace(/[_-]([a-z0-9])([^_-]*)/gi, function(match, p1, p2) {
return p1.toUpperCase() + p2.toLowerCase();
});
}
if (prefix) {
name = name.substr(prefix.length);
}
data += ' ' + name + ': "' + unicode + '"' + ((i === ln - 1) ? '' : ',') + '\n';
});
if (name.indexOf('-') !== -1 || name.indexOf('_') !== -1) {
name = name.replace(/[_-]([a-z0-9])([^_-]*)/gi, function(match, p1, p2) {
return p1.toUpperCase() + p2.toLowerCase();
});
}
data += '};';
data += ' ' + name + ': "' + unicode + '"' + ((i === ln - 1) ? '' : ',') + '\n';
});
data += '};';
}
fs.writeFile(js, data, null, function(err) {

@@ -173,2 +197,2 @@

});
});

@@ -6,5 +6,10 @@ {

"fonts",
"icons"
"icons",
"css",
"iconfonts",
"tss",
"alloy",
"titanium"
],
"version": "0.2.1",
"version": "0.3.0",
"author": {

@@ -14,8 +19,6 @@ "name": "Fokke Zandbergen",

},
"maintainers": [
{
"name": "Fokke Zandbergen",
"email": "mail@fokkezb.nl"
}
],
"maintainers": [{
"name": "Fokke Zandbergen",
"email": "mail@fokkezb.nl"
}],
"repository": {

@@ -22,0 +25,0 @@ "type": "git",

# IconFont
CLI to convert CSS StyleSheets for Icon Fonts like [FontAwesome](https://github.com/FortAwesome/Font-Awesome/blob/master/css/font-awesome.css) to a [CommonJS module](test/font-awesome.js) that exports all unicodes by name. I use them in native iOS & Android apps build with [Titanium](http://appcelerator.com/titanium).
CLI to convert CSS StyleSheets for Icon Fonts like [FontAwesome](https://github.com/FortAwesome/Font-Awesome/blob/master/css/font-awesome.css) to a [CommonJS module](test/font-awesome.js) or [Alloy TSS](http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Styles_and_Themes) file that exports all unicodes by name.
I use them in native iOS & Android apps build with [Titanium](http://appcelerator.com/titanium).
## Example
- Input: [font-awesome.css](test/font-awesome.css)
- Output: [font-awesome.js](test/font-awesome.js)
- Output as JS (default): [font-awesome.js](test/font-awesome.js)
- Output as TSS: [font-awesome.tss](test/font-awesome.tss)

@@ -16,4 +19,6 @@ ## Install the CLI [![npm](http://img.shields.io/npm/v/iconfont.png)](https://www.npmjs.org/package/iconfont)

## Generate a module
## CommonJS
### Generate it
Just point the CLI to the CSS file:

@@ -27,3 +32,3 @@

## Use the module
### Use it

@@ -53,6 +58,41 @@ In [Titanium](http://appcelerator.com/titanium), I'd use the module like this:

## Alloy TSS
Credits: [Jong Eun Lee](https://github.com/yomybaby).
### Generate it
Add the `-t` or `--tss` flag:
$ iconfont font-awesome.css -t
Or when using the second output-argument, make sure its extension is `.tss`:
$ iconfont font-awesome.css ~/fa.tss
### Use it
Since you cannot import TSS files at the moment, you'd probably copy-paste the contents of the generated file to your `app/styles/app.tss` file.
*index.xml*
Use the classes just like in HTML:
<Label class="fa-thumbs-up otherClassName"></Label>
*index.tss*
And overwrite any property using additional class names:
".otherClassName": {
font: {
fontSize: 40
}
}
## Notes
- Icon names are camel-cased (`arrow-up` becomes `arrowUp`).
- If **all** icon names share the same prefix this will be stripped out (`icon-flag` becomes `flag`).
- For JS:
- Icon names are camel-cased (`arrow-up` becomes `arrowUp`).
- If **all** icon names share the same prefix this will be stripped out (`icon-flag` becomes `flag`).
- The CLI expects selectors ending with `:before`.

@@ -63,2 +103,3 @@ - The CLI expects declerations with a `content` property and a valid (unicode) string as value.

* 0.3.0: Adds support for generating TSS files
* 0.2.0:

@@ -65,0 +106,0 @@ - Adds support for non-unicode content

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc