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

globalize

Package Overview
Dependencies
Maintainers
4
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globalize - npm Package Compare versions

Comparing version 1.0.0-alpha.18 to 1.0.0-alpha.19

dist/globalize/relative-time.js

2

bower.json
{
"name": "globalize",
"version": "1.0.0-alpha.18",
"version": "1.0.0-alpha.19",
"license": "MIT",

@@ -5,0 +5,0 @@ "ignore": [

/**
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/
/*!
* Globalize v1.0.0-alpha.18 2015-03-17T20:37Z Released under the MIT license
* Globalize v1.0.0-alpha.19 2015-03-26T15:19Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/*!
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,3 +10,3 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/

@@ -13,0 +13,0 @@ (function( root, factory ) {

/**
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/
/*!
* Globalize v1.0.0-alpha.18 2015-03-17T20:37Z Released under the MIT license
* Globalize v1.0.0-alpha.19 2015-03-26T15:19Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/
/*!
* Globalize v1.0.0-alpha.18 2015-03-17T20:37Z Released under the MIT license
* Globalize v1.0.0-alpha.19 2015-03-26T15:19Z Released under the MIT license
* http://git.io/TrdQbw

@@ -16,0 +16,0 @@ */

/**
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/
/*!
* Globalize v1.0.0-alpha.18 2015-03-17T20:37Z Released under the MIT license
* Globalize v1.0.0-alpha.19 2015-03-26T15:19Z Released under the MIT license
* http://git.io/TrdQbw

@@ -123,12 +123,2 @@ */

var numberTruncate = function( value ) {
if ( isNaN( value ) ) {
return NaN;
}
return Math[ value < 0 ? "ceil" : "floor" ]( value );
};
/**

@@ -174,3 +164,3 @@ * integerFractionDigits( number, minimumIntegerDigits, minimumFractionDigits,

} else {
number = numberTruncate( number );
number = round( number );
}

@@ -687,2 +677,12 @@

var numberTruncate = function( value ) {
if ( isNaN( value ) ) {
return NaN;
}
return Math[ value < 0 ? "ceil" : "floor" ]( value );
};
/**

@@ -689,0 +689,0 @@ * round( method )

/**
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,6 +10,6 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/
/*!
* Globalize v1.0.0-alpha.18 2015-03-17T20:37Z Released under the MIT license
* Globalize v1.0.0-alpha.19 2015-03-26T15:19Z Released under the MIT license
* http://git.io/TrdQbw

@@ -43,3 +43,4 @@ */

validateParameterPresence = Globalize._validateParameterPresence,
validateParameterType = Globalize._validateParameterType;
validateParameterType = Globalize._validateParameterType,
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;
/**

@@ -218,2 +219,14 @@ * make-plural.js -- https://github.com/eemeli/make-plural.js/

var validateParameterTypePluralType = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || value === "cardinal" || value === "ordinal",
"String \"cardinal\" or \"ordinal\""
);
};
/**

@@ -228,10 +241,10 @@ * .plural( value )

Globalize.plural =
Globalize.prototype.plural = function( value ) {
Globalize.prototype.plural = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.pluralGenerator()( value );
return this.pluralGenerator( options )( value );
};
/**
* .pluralGenerator()
* .pluralGenerator( [options] )
*

@@ -248,19 +261,29 @@ * Return a plural function (of the form below).

Globalize.pluralGenerator =
Globalize.prototype.pluralGenerator = function() {
var cldr, plural;
Globalize.prototype.pluralGenerator = function( options ) {
var cldr, isOrdinal, plural, type;
validateParameterTypePlainObject( options, "options" );
options = options || {};
type = options.type || "cardinal";
cldr = this.cldr;
validateParameterTypePluralType( options.type, "options.type" );
validateDefaultLocale( cldr );
isOrdinal = type === "ordinal";
cldr.on( "get", validateCldr );
cldr.supplemental( "plurals-type-cardinal/{language}" );
cldr.supplemental([ "plurals-type-" + type, "{language}" ]);
cldr.off( "get", validateCldr );
// Set CLDR data
MakePlural.rules = {
cardinal: cldr.supplemental( "plurals-type-cardinal" )
};
MakePlural.rules = {};
MakePlural.rules[ type ] = cldr.supplemental( "plurals-type-" + type );
plural = MakePlural( cldr.attributes.language, { "no_tests": true } );
plural = MakePlural( cldr.attributes.language, {
"no_tests": true,
"ordinals": isOrdinal,
"no_cardinals": isOrdinal
} );

@@ -267,0 +290,0 @@ return function( value ) {

/*!
* Globalize v1.0.0-alpha.18
* Globalize v1.0.0-alpha.19
*

@@ -10,3 +10,3 @@ * http://github.com/jquery/globalize

*
* Date: 2015-03-17T20:37Z
* Date: 2015-03-26T15:19Z
*/

@@ -25,1 +25,4 @@

require( "./globalize/date" );
// Load after globalize/number and globalize/plural
require( "./globalize/relative-time" );

@@ -37,2 +37,3 @@ ## .dateFormatter( pattern ) ➜ function( value )

> **date**
>
> One of the following String values: `full`, `long`, `medium`, or `short`, eg.

@@ -116,3 +117,3 @@ > `{ date: "full" }`.

Use convenient presets for `date`, `time`, or `datetime`. Their possible values
are: `full`, `long`, `medium`, or `short`.
are: `full`, `long`, `medium`, and `short`.

@@ -189,8 +190,10 @@ | `presetValue` | `Globalize( "en" ).dateFormatter( presetValue )( new Date( 2010, 10, 1, 17, 55 ) )` |

```javascript
var dates = [ new Date( a ), new Date( b ), ... ];
// In an application, this array could have a few hundred entries
var dates = [ new Date( 2010, 10, 30, 17, 55 ), new Date( 2015, 3, 18, 4, 25 ) ];
var formatter = Globalize( "en" ).dateFormatter({ time: "short" });
formattedDates = dates.map(function( date ) {
var formattedDates = dates.map(function( date ) {
return formatter( date );
});
// > Array [ "5:55 PM", "4:25 AM" ]
```

@@ -1,2 +0,2 @@

## .pluralGenerator() ➜ function( value )
## .pluralGenerator( [options] ) ➜ function( value )

@@ -12,2 +12,10 @@ It supports the creation of internationalized messages with plural inflection by

**options** Optional
A JSON object including none or any of the following options.
> **type** Optional
>
> String `cardinal` (default), or `ordinal`.
**value**

@@ -19,3 +27,6 @@

Prior to using any plural method, you must load `supplemental/plurals.json`.
Prior to using any plural method, you must load either
`supplemental/plurals.json` for cardinals or `supplemental/ordinals.json` for
ordinals.
Read [CLDR content][] if you need more information.

@@ -32,2 +43,4 @@

Globalize.locale( "en" );
// Cardinals
plural = Globalize.pluralGenerator();

@@ -43,2 +56,14 @@

// > "other"
// Ordinals
plural = Globalize.pluralGenerator({ type: "ordinal" });
plural( 0 );
// > "other"
plural( 1 );
// > "one"
plural( 2 );
// > "two"
```

@@ -56,3 +81,3 @@

For comparison:
For comparison (cardinals):

@@ -66,1 +91,11 @@ | | en (English) | ru (Russian) | ar (Arabic) |

| `plural( 5 )` | `other` | `many` | `few` |
For comparison (ordinals):
| | en (English) | ru (Russian) | ar (Arabic) |
| --- | --- | --- | --- |
| `plural( 0, { type: "ordinal" } )` | `other` | `other` | `other` |
| `plural( 1, { type: "ordinal" } )` | `one` | `other` | `other` |
| `plural( 2, { type: "ordinal" } )` | `two` | `other` | `other` |
| `plural( 3, { type: "ordinal" } )` | `few` | `other` | `other` |
| `plural( 5, { type: "ordinal" } )` | `other` | `other` | `other` |

@@ -31,4 +31,5 @@ /**

// CLDR content.
"json!cldr-data/main/en/ca-gregorian.json",
"json!cldr-data/main/en/currencies.json",
"json!cldr-data/main/en/ca-gregorian.json",
"json!cldr-data/main/en/dateFields.json",
"json!cldr-data/main/en/numbers.json",

@@ -47,4 +48,5 @@ "json!cldr-data/supplemental/currencyData.json",

"globalize/number",
"globalize/plural"
], function( Globalize, enCurrencies, enGregorian, enNumbers, currencyData, likelySubtags,
"globalize/plural",
"globalize/relative-time"
], function( Globalize, enGregorian, enCurrencies, enDateFields, enNumbers, currencyData, likelySubtags,
pluralsData, timeData, weekData, messages ) {

@@ -58,2 +60,3 @@

enCurrencies,
enDateFields,
enGregorian,

@@ -74,3 +77,3 @@ enNumbers,

datetime: "medium"
})
});

@@ -85,3 +88,3 @@ // Use Globalize to format numbers.

// Use Globalize to get the plural form of a numeric value.
document.getElementById( "plural-number" ).innerHTML = number( 12345.6789 )
document.getElementById( "plural-number" ).innerHTML = number( 12345.6789 );
document.getElementById( "plural-form" ).innerHTML = en.plural( 12345.6789 );

@@ -96,2 +99,5 @@

// Use Globalize to format a relative time.
document.getElementById( "relative-time" ).innerText = en.formatRelativeTime( -35, "second" );
document.getElementById( "requirements" ).style.display = "none";

@@ -98,0 +104,0 @@ document.getElementById( "demo" ).style.display = "block";

@@ -8,4 +8,5 @@ #! /usr/bin/node

Globalize.load(
require( "cldr-data/main/en/ca-gregorian" ),
require( "cldr-data/main/en/currencies" ),
require( "cldr-data/main/en/ca-gregorian" ),
require( "cldr-data/main/en/dateFields" ),
require( "cldr-data/main/en/numbers" ),

@@ -41,1 +42,4 @@ require( "cldr-data/supplemental/currencyData" ),

console.log( like( 3 ) );
// Use Globalize to format relative time.
console.log( Globalize.formatRelativeTime( -35, "second" ) );

@@ -296,2 +296,21 @@ module.exports = function( grunt ) {

}
},
{
name: "globalize.relative-time",
include: [ "relative-time" ],
exclude: [
"cldr",
"cldr/event",
"cldr/supplemental",
"./core",
"./number",
"./plural"
],
create: true,
override: {
wrap: {
startFile: "src/build/intro-relative-time.js",
endFile: "src/build/outro.js"
}
}
}

@@ -348,3 +367,4 @@ ]

"tmp/globalize/plural.min.js": [ "dist/globalize/plural.js" ],
"tmp/globalize/message.min.js": [ "dist/globalize/message.js" ]
"tmp/globalize/message.min.js": [ "dist/globalize/message.js" ],
"tmp/globalize/relative-time.min.js": [ "dist/globalize/relative-time.js" ]
}

@@ -351,0 +371,0 @@ }

{
"name": "globalize",
"version": "1.0.0-alpha.18",
"version": "1.0.0-alpha.19",
"description": "A JavaScript library for internationalization and localization that leverage the official Unicode CLDR JSON data.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -29,2 +29,3 @@ # Globalize

- [Plural module](#plural-module)
- [Relative time module](#relative-time-module)
- more to come...

@@ -146,2 +147,3 @@ - [Error reference](#error-reference)

| globalize/plural.js | +1.7KB | [Plural module](#plural-module) provides pluralization support |
| globalize/relative-time.js | +0.7KB | [Relative time module](#relative-time-module) provides relative time formatting support |

@@ -210,3 +212,4 @@ ### Browser Support

| Number module | cldr/main/`locale`/numbers.json<br>cldr/supplemental/numberingSystems.json |
| Plural module | cldr/supplemental/plurals.json |
| Plural module | cldr/supplemental/plurals.json (for cardinals)<br>cldr/supplemental/ordinals.json (for ordinals) |
| Relative time module | cldr/main/`locale`/dateFields.json<br>+CLDR JSON files from number and plural modules |

@@ -439,3 +442,3 @@ *(b) How am I supposed to get and load CLDR content?*

- **`.pluralGenerator()`**
- **`.pluralGenerator( [options] )`**

@@ -445,2 +448,4 @@ Return a function that returns the value's corresponding plural group: `zero`,

The function may be used for cardinals or ordinals.
```javascript

@@ -452,2 +457,8 @@ .pluralGenerator()( 0 )

// > "one"
.pluralGenerator({ type: "ordinal" })( 1 )
// > "one"
.pluralGenerator({ type: "ordinal" })( 2 )
// > "two"
```

@@ -457,7 +468,31 @@

- **`.plural( value )`**
- **`.plural( value[, options ] )`**
Alias for `.pluralGenerator()( value )`.
Alias for `.pluralGenerator( [options] )( value )`.
### Relative time module
- **`.relativeTimeFormatter( unit [, options] )`**
Returns a function that formats a relative time according to the given unit, options, and the
default/instance locale.
```javascript
.relativeTimeFormatter( "day" )( 1 )
// > "tomorrow"
.relativeTimeFormatter( "month" )( -1 )
// > "last month"
.relativeTimeFormatter( "month" )( 3 )
// > "in 3 months"
```
[Read more...](doc/api/relative-time/relative-time-formatter.md)
- **`.formatRelativeTime( value, unit [, options] )`**
Alias for `.relativeTimeFormatter( unit, options )( value )`.
## Error reference

@@ -552,2 +587,4 @@

│ ├── plural/ (plural source code)
│ ├── relative-time.js (relative time module)
│ ├── relative-time/ (relative time source code)
│ └── util/ (basic JavaScript helpers polyfills, eg array.map)

@@ -554,0 +591,0 @@ └── test/ (unit and functional test files)

@@ -42,2 +42,3 @@ /**

validateParameterPresence = Globalize._validateParameterPresence,
validateParameterType = Globalize._validateParameterType;
validateParameterType = Globalize._validateParameterType,
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;

@@ -24,1 +24,4 @@ /*!

require( "./globalize/date" );
// Load after globalize/number and globalize/plural
require( "./globalize/relative-time" );
define([
"../../util/number/truncate",
"../../util/string/pad"
], function( numberTruncate, stringPad ) {
], function( stringPad ) {

@@ -46,3 +45,3 @@ /**

} else {
number = numberTruncate( number );
number = round( number );
}

@@ -49,0 +48,0 @@

@@ -10,2 +10,4 @@ define([

"./common/validate/parameter-type/number",
"./common/validate/parameter-type/plain-object",
"./common/validate/parameter-type/plural-type",

@@ -15,3 +17,4 @@ "cldr/event",

], function( Cldr, MakePlural, Globalize, validateCldr, validateDefaultLocale,
validateParameterPresence, validateParameterType, validateParameterTypeNumber ) {
validateParameterPresence, validateParameterType, validateParameterTypeNumber,
validateParameterTypePlainObject, validateParameterTypePluralType ) {

@@ -27,10 +30,10 @@ /**

Globalize.plural =
Globalize.prototype.plural = function( value ) {
Globalize.prototype.plural = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.pluralGenerator()( value );
return this.pluralGenerator( options )( value );
};
/**
* .pluralGenerator()
* .pluralGenerator( [options] )
*

@@ -47,19 +50,29 @@ * Return a plural function (of the form below).

Globalize.pluralGenerator =
Globalize.prototype.pluralGenerator = function() {
var cldr, plural;
Globalize.prototype.pluralGenerator = function( options ) {
var cldr, isOrdinal, plural, type;
validateParameterTypePlainObject( options, "options" );
options = options || {};
type = options.type || "cardinal";
cldr = this.cldr;
validateParameterTypePluralType( options.type, "options.type" );
validateDefaultLocale( cldr );
isOrdinal = type === "ordinal";
cldr.on( "get", validateCldr );
cldr.supplemental( "plurals-type-cardinal/{language}" );
cldr.supplemental([ "plurals-type-" + type, "{language}" ]);
cldr.off( "get", validateCldr );
// Set CLDR data
MakePlural.rules = {
cardinal: cldr.supplemental( "plurals-type-cardinal" )
};
MakePlural.rules = {};
MakePlural.rules[ type ] = cldr.supplemental( "plurals-type-" + type );
plural = MakePlural( cldr.attributes.language, { "no_tests": true } );
plural = MakePlural( cldr.attributes.language, {
"no_tests": true,
"ordinals": isOrdinal,
"no_cardinals": isOrdinal
} );

@@ -66,0 +79,0 @@ return function( value ) {

@@ -43,4 +43,7 @@ require.config({

// plural
"./functional/plural/plural"
"./functional/plural/plural",
// relative-time
"./functional/relative-time/format-relative-time",
"./functional/relative-time/relative-time-formatter"
], function() {

@@ -47,0 +50,0 @@ QUnit.start();

@@ -107,4 +107,4 @@ define([

assert.equal( Globalize.currencyFormatter( "ZWD" )( 12345 ), "ZWD 12,345" );
assert.equal( Globalize.currencyFormatter( "ZWD" )( 12345.67 ), "ZWD 12,345" );
assert.equal( Globalize.currencyFormatter( "JPY" )( 12345.67 ), "¥12,345" );
assert.equal( Globalize.currencyFormatter( "ZWD" )( 12345.67 ), "ZWD 12,346" );
assert.equal( Globalize.currencyFormatter( "JPY" )( 12345.67 ), "¥12,346" );

@@ -111,0 +111,0 @@ assert.equal( Globalize.currencyFormatter( "CLF", code )( 12345.67 ),

@@ -5,9 +5,11 @@ define([

"json!cldr-data/supplemental/plurals.json",
"json!cldr-data/supplemental/ordinals.json",
"../../util",
"globalize/plural"
], function( Globalize, likelySubtags, plurals, util ) {
], function( Globalize, likelySubtags, plurals, ordinals, util ) {
function extraSetup() {
Globalize.load( plurals );
Globalize.load( ordinals );

@@ -51,2 +53,8 @@ // Temporary fix due to CLDR v26 regression about pt_BR plural

});
util.assertPlainObjectParameter( assert, "options", function( invalidOptions ) {
return function() {
Globalize.plural( 0, invalidOptions );
};
});
});

@@ -72,2 +80,10 @@

assert.equal( Globalize( "en" ).plural( 0, { type: "ordinal" } ), "other" );
assert.equal( Globalize( "en" ).plural( 1, { type: "ordinal" } ), "one" );
assert.equal( Globalize( "en" ).plural( 2, { type: "ordinal" } ), "two" );
assert.equal( Globalize( "en" ).plural( 3, { type: "ordinal" } ), "few" );
assert.equal( Globalize( "en" ).plural( 1412, { type: "ordinal" } ), "other" );
assert.equal( Globalize( "en" ).plural( 0.14, { type: "ordinal" } ), "other" );
assert.equal( Globalize( "en" ).plural( 3.14, { type: "ordinal" } ), "other" );
assert.equal( Globalize( "ar" ).plural( 0 ), "zero" );

@@ -93,2 +109,6 @@ assert.equal( Globalize( "ar" ).plural( 1 ), "one" );

[ 0, 1, 2, 3, 9, 10, 11, 99, 100, 101, 3.14 ].forEach(function( value ) {
assert.equal( Globalize( "ar" ).plural( value, { type: "ordinal" } ), "other" );
});
assert.equal( Globalize( "ja" ).plural( 0 ), "other" );

@@ -95,0 +115,0 @@ assert.equal( Globalize( "ja" ).plural( 1 ), "other" );

@@ -48,4 +48,8 @@ require.config({

"./unit/number/parse-properties",
"./unit/number/parse"
"./unit/number/parse",
// relative time
"./unit/relative-time/properties",
"./unit/relative-time/format"
], function() {

@@ -52,0 +56,0 @@ QUnit.start();

@@ -47,2 +47,3 @@ define([

assert.equal( formatIntegerFractionDigits( pi, 1, 2, 2, round, 0.10 ), "3.10" );
assert.equal( formatIntegerFractionDigits( 100.7, 1, 0, 0, round, null ), "101" );
});

@@ -49,0 +50,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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